Skip to content


Repository files navigation

Logo of Typographizer JS


Published version Code Coverage Build Status Dependency Status Dev Dependency Status Greenkeeper badge

Typographizer automates everything some things you don’t want (or need) to know about typography.


The JS version is inspired by the Typographizer by Frank Rausch, written in Swift. 🙇‍


Here be dragons 🐉

This package uses RegExp lookbehinds. These are not universally supported. You can use it in Node >=6.4 with enabled --harmony flag, without a flag in Node >=9.11.

You should not use this in the browser (probably). Formatting and reinserting long strings is a mayor performance hit.

In general, this is more of a fun project. So, use with caution.


npm install typographizer-js

If you are using Yarn:

yarn add typographizer-js

Import the bundle into your project:

const TypographizerJS = require('typographizer-js')

And crate a new instance:

const Typographizer = new TypographizerJS()

Note: Typographizer will preserve inline HTML Tags (a, strong, em), but should not be used to format large bunches of source code.

Once you have your Typographizer instance available you can format strings using the typographize() method.

typographize returns a Promise. So you need to either await the return value or use .then().

const str = `I introduced myself, "Hi, I'm Oscar".`

 * Using await
const formatted = await Typographizer.typographize(str)

// I introduced myself, “Hi, I’m Oscar“.

 * Using .then()
  .then((str) => {
    // I introduced myself, “Hi, I’m Oscar“.

Typographizer uses a bunch of different methods under the hood. All of them can be called on their own. For details, take a look at the API section below.


By default quotes will be formatted to match en_US style. If you need different formatting, pass a language code while initializing.

const Typographizer = new TypographizerJS('fr')

You can find a list of supported languages further down this file.

⚠️ To avoid side effects and confusion, It is not possible to change these options after you created your instance. If you want to format text in multiple languages, you need to create multiple instances.


All these methods return Promises. Usage instructions for typographize usage apply.


Method Description
fixApostroph(str) Replace ', ´ and ` used as an apostroph
fixEllipsis(str) Formats all occurences of ... to use the correct … character
fixAiryPunctuation(str) Finds punctuation that is surrounded by whitespace
formatQuotes(str) Format quotes, but not whitespace or apostrophes
formatOpeningQuotes(str) Format all opening quotes
formatClosingQuotes(str) Format all closing quotes
trimWhitespace(str) Remove whitespace from the beginning and end of a string, replaces multiple spaces with a single one
typographize(str) Takes a string and applies all optimizations

Supported languages

Language support has been ported from the original Typographizer.

Supported languages are:

Language Shortcode
Bosnian bs
Czech cz
Danish da
Dutch, Flemish nl
British English en_GB
American English (default) en_US
Estonian es
Finnish fi
French fr
German de
German (Suisse) de_CH
German (Liechtenstein) de_LI
Hungarian hu
Icelandic is
Lithuanian lt
Latvian lv
Polish pl
Romanian ro
Slovak sk
Slovenian sl
Swedish sw

This list is missing Japanese and Hebrew, which are supported by Typographizer. Hebrew is missing due to complicated support. Japanese requires extended Unicode checks.


A script to fix typographic errors