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

@funboxteam/babel-plugin-typograf

v3.0.0

Published

Babel plugin for enhancing text punctuation and readability

Downloads

403

Readme

@funboxteam/babel-plugin-typograf

npm

Babel plugin for enhancing text punctuation and readability.

По-русски

Rationale

Text is the main tool to describe an action in UI. Also there're texts on landing pages, “FAQs”, “About” sections and other common places on modern websites. Frontend developers should remember to always write those texts properly using correct quotes, dashes, spaces, symbols, etc.

This plugin makes it possible to automate enhancing text readability but replacing entities in string during the build stage.

Installation

npm install --save-dev @funboxteam/babel-plugin-typograf

Configuration

Note: The plugin should be placed “above” other plugins that work with template literals (such as plugin-transform-template-literals) in plugins array, to make it possible to convert tagged templates earlier than process template literals overall.

Add plugin settings into your Babel config:

{
  plugins: [
    ['@funboxteam/babel-plugin-typograf', {
      // Set locales to get correct symbol replacements (such as quotes, dashes, etc.)
      locale: ['ru', 'en-US'],

      // Symbols to HTML entities convertaion (disabled by default)
      htmlEntity: {
        type: 'name',        // 'name' or 'digit'
        onlyInvisible: true, // Set `true` to convert invisible symbols only
      },

      // Here you can enable additional typograf rules
      enableRules: [
        'common/nbsp/afterNumber',
      ],

      // Here you can disable Typograf rules that are enabled by default
      disableRules: [
        'common/punctuation/quote',
      ],

      // Rules settings
      ruleSettings: [
        ['common/nbsp/beforeShortLastWord', 'lengthLastWord', 8],
      ],
    }],
  ]
}

Usage

Use this template literal tag to transform strings:

// Source string
T`Formatted "string".  `;

// Typografed string
// Tagged template with tag `T` is converted to a regular template literal
`Formatted “string”.`;

Typograf

To process text the plugin uses Typograf. It looks for the templates tagged with T:

T`"string"`

Then transforms the text inside and converts the expressions into the regular template literals without the tag:

`“string”`

Main features of Typograf

  • Trailing and double spaces removing.
  • Inserting non-breaking spaces.
  • Quotes conversion.
  • HTML-entities ( , «, », etc.) to Unicode-symbols conversion.

Typograf rules

Some rules are enabled by default in Typograf's config.

Not recommended to turn on

  • ru/money/ruble
    Transforms руб. to . It's better to use when necessary to avoid transformation in the places where it isn't expected. E.g. in the texts where it's important to use руб.. Or in the markup where isn't displayed correctly due to fonts incompatibility.

  • common/space/delBeforePunctuation
    Removes spaces before the punctuation signs. But there's a bug. E.g. the phrase “We need a .Net developer” will be transformed into “We need a.Net developer”. Right now there's no fix for this issue, but maybe later it will be possible to create a list of exceptions.

  • common/space/afterPunctuation
    Adds space after the punctuation signs. But sometimes they are added when you don't expect them to see. E.g. comma sign “,” will be transformed into comma sign “, ”, which will break common/punctuation/quote and the result will be comma sign “, “.

Sponsored by FunBox