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

@lokalise/text-measure

v1.3.0

Published

Readme

Text measure

Utilities to measure text for Lokalise — character count and translatable word count — with pluggable counting rules. Runs in both the browser and Node.

countCharacters

Counts the characters in a text. Non-translatable (NTC) marker tags are excluded (the content they wrap is kept); everything else in the text, including whitespace, is counted.

import { countCharacters } from '@lokalise/text-measure'

countCharacters('Hello world') // 11

The counting algorithm is pluggable via options.algorithm (defaults to utf16):

  • utf16 — UTF-16 code units (JS String.length). A surrogate pair (e.g. an emoji) counts as two.
  • codePoints — Unicode code points. A surrogate pair counts as one.
countCharacters('👍') // 2 (default: utf16)
countCharacters('👍', { algorithm: 'utf16' }) // 2
countCharacters('👍', { algorithm: 'codePoints' }) // 1

More algorithms (e.g. glyphs — à la XLIFF size-units) can be added over time. To measure the encoded size of a text rather than its characters, use countBytes.

By default the content wrapped between NTC tags is counted (only the marker tags are excluded). Set options.excludeNtc to true to drop non-translatable content — the whole region, tags and wrapped content — from the count:

// NTC markers are two private-use code points: U+E101 (start) and U+E102 (end).
const text = 'a\uE101bc\uE102d' // "bc" is wrapped in NTC markers

countCharacters(text) // 4 — NTC content "bc" is counted
countCharacters(text, { excludeNtc: true }) // 2 — only "a" and "d" counted

countBytes

Counts the size of a text in bytes — the size it takes in a database or a search index, which is what storage limits are expressed in. The text is measured as given: NTC markers and the content they wrap are counted like any other character.

import { countBytes } from '@lokalise/text-measure'

countBytes('Hello') // 5
countBytes('你好') // 6
countBytes('👍') // 4
countBytes('a<b>') // 10 — each NTC marker is 3 bytes

The encoding is pluggable via options.encoding (defaults to utf8):

  • utf8 — UTF-8. A lone surrogate counts as three bytes, the size of the replacement character (U+FFFD) that UTF-8 encoders write in its place.
countBytes('👍', { encoding: 'utf8' }) // 4

More encodings can be added over time.

countTranslatableWords

Counts the translatable words in a text, excluding non-translatable content (NTC) and tags. Backed by gmx-word-counter.

import { countTranslatableWords } from '@lokalise/text-measure'

countTranslatableWords('Hello world') // 2

options.locale is a BCP47 language subtag used for word segmentation (defaults to -), so logographic scripts are counted correctly:

countTranslatableWords('你好世界', { locale: 'zh' })