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

prevOpen Source→string-unfancynext

string-unfancy6.2.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 — GU…
  • CAN YOU USE…
  • Changelog

Installation

Quick Take

Examples

  • 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.

It’s used in ASCII-restricted places where encoding is too unwieldy, for example, image alt attribute values in email templates. Or stripping down the formatted markdown value, removing backticks and so on.

API — unfancy()

The main function unfancy() is imported like this:

It’s a function which takes one string input argument:

Function will return a string.

API — version

You can import version:

Example — Gulp streams

If you are using Gulp to build email templates, you can tap the stream, apply a function to it, then within that function, replaceopens in a new tab all instances of alt="..." with their unfancied versions.

First, you need to require gulp-tapopens in a new tab and string-unfancy:

import tap from "gulp-tap";
import { unfancy } from "string-unfancy";

Then, tap your main build task’s stream, probably towards the end of the pipeline:

.pipe(tap((file) => {
  file.contents = Buffer.from(unfancy(file.contents.toString()))
}))
.pipe(gulp.dest('dist')) // that's the final write happening, yours might be different

Then, declare a function somewhere within your gulpfile.js:

function unfancy(input) {
  input = input.replace(/alt="[^"]*"/g, (el) => {
    return unfancy(el);
  });
  return input;
}

As you see above, an inline functionopens in a new tab is run upon all regex-matched characters.

And that’s it! All image alt attributes will lose their HTML encoding and will have their fancy special characters converted to simple ASCII letter equivalents.

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.

Changelog

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