Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→string-unfancynext

string-unfancy6.3.0

Replace all n/m dashes, curly quotes with their simpler equivalents

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • IDEA
  • API — UNFANCY()
  • API — VERSION
  • EXAMPLE — NO…
  • CAN YOU USE…
  • Changelog

No 3rd party dependencies. All dependencies and devDependencies, checked recursively, are Codsen packages.

Permalink to InstallationInstallation

Permalink to Quick TakeQuick Take

Permalink to ExamplesExamples

  • Preserve combining marks while simplifying punctuation when requested
  • Normalise common typographic characters
  • Normalise an HTML-encoded typographic character
  • Convert non-breaking spaces
  • Decode repeatedly encoded HTML

Idea

Convert typographically-correctopens in a new tab characters (like curly quotesopens in a new tab or m-dashesopens in a new tab) to their basic counterparts (like apostrophes or hyphens).

It’s the opposite of detergent and string-apostrophes.

Use it to simplify supported punctuation in text, including image alt values before they are encoded for HTML. Other characters, such as accented letters and backticks, remain unchanged.

API — unfancy()

The main function unfancy() is imported like this:

Pass a string and an optional options object:

The function returns a string. Omitting the options preserves the existing conversions.

OptionTypeDefaultDescription
preserveCombiningMarks
Type: Boolean
Default: false
preserveCombiningMarksBooleanfalsePreserve U+0312–U+0315 combining marks instead of replacing them with apostrophes. Other typography conversions and recursive character-reference decoding still apply.
unfancy("…q\u0313r—");
// → "...q'r-"

unfancy("…q\u0313r—", { preserveCombiningMarks: true });
// → "...q\u0313r-"

The option preserves these marks as written; unfancy() does not apply Unicode normalization. extract-search-index enables it alongside NFC normalization to keep canonically equivalent words together.

API — version

You can import version:

Example — normalize text

Character references are decoded repeatedly before typography is simplified. Every mapped character is converted, including quotes and apostrophes after an ellipsis expands to three periods:

import { unfancy } from "string-unfancy";

unfancy("…“alpha” …beta’s");
// → `..."alpha" ...beta's`

unfancy("…“alpha”");
// → `..."alpha"`

After decoding reaches a fixed point, one replacement pass handles the selected punctuation. Repeated typography does not require rebuilding the entire string for each replacement. Pass the complete text, including repeated or encoded punctuation; the same conversions apply throughout it.

Pass the text to normalize. When inserting the result into HTML, encode it for its destination attribute or text context. Extract an image’s alt value before normalizing it; unfancy() does not parse or repair the surrounding HTML attribute syntax.

Can you use lodash.deburr instead?

No. It won’t even convertopens in a new tab a single m-dash! It’s a different tool for a different purpose.

Permalink to changelogChangelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab