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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dinvader/autonbsp

v1.0.3

Published

Automatically replace whitespace in string with non-breaking spaces (`\u00A0` or ` `) to prevent hanging articles, prepositions and digits.

Readme

Auto NBSP

Automatically replace whitespace in string with non-breaking spaces (\u00A0 or  ) to prevent hanging articles, prepositions and digits.

Important: this package does not parse or traverse AST. Using it with raw HTML or Markdown strings will likely break your content or markup.

For rich Markdown content use remark-plugin-autonbsp.

Installation

Install with npm or any other package manager:

npm install @dinvader/autonbsp
yarn add @dinvader/autonbsp

Usage

Basic example:

import { autoNBSP } from '@dinvader/autonbsp';

const inputText = 'An example string with 6 tokens.';

const result = autoNBSP(inputText, {
    mode: 'html',
    afterDigits: true,
    prepositions: ['an', 'with'],
});

console.log(result);
// -> "An example string with 6 tokens.";

Presets

Two config presets are available for Russian and English languages. You can extend them for your needs.

import { autoNBSP } from '@dinvader/autonbsp';
import nbspEn from '@dinvader/autonbsp/presets/en';
import nbspRu from '@dinvader/autonbsp/presets/ru';

console.log(autoNBSP('5 items in stock', nbspEn));
// -> "5\u00A0items in\u00A0stock"

console.log(autoNBSP('5 items in stock', { ...nbspEn, prepositions: '', mode: 'html' }));
// -> "5 items in stock"

console.log(autoNBSP('5 шт. на складе', nbspEn));
// -> "5\u00A0шт. на\u00A0складе"

Configuration options

mode?: 'utf' | 'html'

Defines the replacement used for matched whitespace.

  • 'utf' replaces whitespace with the Unicode non-breaking space character '\u00A0' or  .
  • 'html' replaces whitespace with the HTML entity string ' '.

Default value is 'utf'.

betweenDigits?: boolean

Replace runs of whitespace that occur between two adjacent digits.

Examples:

  • "123 456""123\u00A0456"
  • "1\t 2""1\u00A02"

false by default.

afterDigits?: boolean | 'before-letter'

Replace runs of whitespace that occur immediately after a digit.

  • true replaces whitespace when followed by any non-digit character.
  • 'before-letter' replaces whitespace only when followed by a Unicode letter.

Examples:

  • "2 pieces""2\u00A0pieces"
  • "5 %""5\u00A0%"
  • "5 %""5 %" with 'before-letter' option

false by default.

prepositions?: string | string[];

Replace runs of whitespace that occur after specified whole-word prepositions.

Prepositions may be provided as:

  • an array of strings (e.g. ['a', 'in', 'for'])
  • a pipe-separated regular expression pattern (e.g. 'a|in|for')

Matching is case-insensitive and respects word boundaries.

License

MIT © Mikhail Panichev