everything some things you don’t want (or need) to know about typography.
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 =
And crate a new instance:
const Typographizer =
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 returns a Promise. So you need to either await the return value or use
const str = `I introduced myself, "Hi, I'm Oscar".`/*** Using await*/const formatted = await Typographizerconsole// I introduced myself, “Hi, I’m Oscar“./*** Using .then()*/Typographizer
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 = '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.
|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|
Language support has been ported from the original Typographizer.
Supported languages are:
|American English (default)||en_US|
This list is missing Japanese and Hebrew, which are supported by Typographizer. Hebrew is missing due to complicated support. Japanese requires extended Unicode checks.