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

uc-width

v0.1.0

Published

Unicode-aware terminal cell width engine: grapheme cluster boundaries + terminal-style cluster width.

Readme

uc-width

Unicode-aware terminal cell width engine that measures grapheme clusters under terminal conventions, plus a stateful stepper for streaming text.

Install

npm i uc-width

ESM: import { ucWidth } from "uc-width"
CJS: const { ucWidth } = require("uc-width") (no default export)

API

ucWidthStep(cp, opts, state?) => { shouldJoin, clusterWidth, state }

Stateful stepper for streaming text. Reports:

  • shouldJoin: whether cp continues the previous grapheme cluster
  • clusterWidth: current cluster width (0–2) after consuming cp
  • state: opaque state to feed into the next call
// Cluster a mixed string into: [ [codePoints[], width], ... ]
import { ucWidthStep, ucWidthOptions } from "uc-width";

const str = "A中ä⌚︎⌚️👨‍🌾";
const opt = ucWidthOptions();

let state;
const out = [];

for (const ch of str) {
  const cp = ch.codePointAt(0);
  const res = ucWidthStep(cp, opt, state);

  if (!res.shouldJoin) out.push([[], 0]);
  out.at(-1)[0].push(cp);
  out.at(-1)[1] = res.clusterWidth;

  state = res.state;
}

console.log(JSON.stringify(out));
// => [[[65],1],[[20013],2],[[97,776],1],[[8986,65038],1],[[8986,65039],2],[[128104,8205,127806],2]]

ucWidth(str, opts?) => number

Simple calculator for the width of an entire string.

import { ucWidth } from "uc-width";

const str = "A中ä⌚︎⌚️👨‍🌾";

console.log(ucWidth(str));
// => 9

ucWidthOptions(overrides?) => UcWidthOptions

Defaults: ucWidthOptions({ nul: 0, control: 0, ambiguous: 1, vs15: 1 }).

  • nul / control: whether control chars should consume a cell (0 or 1).
  • ambiguous: Western terminals typically use 1; some CJK environments prefer 2.
  • vs15: depends on whether your terminal supports (or wants) VS15 narrowing.

Compatibility

  • Unicode tables are derived from Unicode 17.0.0.
  • Width policy is aligned with the wcwidth ecosystem and tested against Python wcwidth.
  • Repo includes an xterm.js Unicode provider demo plus a ucs-detect harness (npm run xterm-detect).

Notes on terminal width

Terminal cell width is a terminal convention rooted in wcwidth-style column heuristics (see Kuhn’s wcwidth.c). Many modern terminals are grapheme-aware, but width policy remains elusive (kitty RFC #8533, Ghostty writeup). There is no Unicode-sanctioned width standard; however, discussion continues (e.g. L2/23-107, TTWG report).