npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typographizer-js

v0.5.1

Published

A script to fix typographic errors

Downloads

6

Readme

TypographizerJS

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.


Acknowledgement

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

Usage

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.

Installation

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)

console.log(formatted)
// I introduced myself, “Hi, I’m Oscar“.

/**
 * Using .then()
 */
Typographizer.typographize(str)
  .then((str) => {
    console.log(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.

Options

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.

API

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

Methods

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