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 🙏

© 2025 – Pkg Stats / Ryan Hefner

uwrap

v0.1.1

Published

A very fast and accurate text and line wrapping util

Downloads

51,242

Readme

⏎ μWrap

A 10x faster and more accurate text wrapping util in < 2KB (min) (MIT Licensed)


Introduction

uWrap exists to efficiently predict varying row heights for list and grid virtualization, a technique for UI performance optimization when rendering large, scrollable datasets. Doing this both quickly and accurately turns out to be a non-trivial task since Canvas2D provides no API for text wrapping, and measureText() is quite expensive; measuring via DOM is also a non-starter due to poor performance. Additionally, font size, variable-width kerning, letter-spacing, explicit line breaks, and different white-space choices affect the wrapping locations.

Notes:

  • Currently works most accurately with Latin charsets
  • Does not yet handle Windows-style \r\n explicit line breaks
  • Only pre-line wrapping strategy is implemented so far

Performance

uWrap outperforms canvas-hypertxt by a wide margin in both CPU and memory usage while being significantly more accurate.

The benchmark below wraps 100,000 random sentences into boxes of random widths between 50px and 250px. You can see this live in DevTools console of the demo page.


Installation

npm i uwrap

or

<script src="./dist/uWrap.iife.min.js"></script>

API

See uWrap.d.ts TypeScript def.


Usage

// import fn for wrapping variable-width fonts using pre-line strategy
import { varPreLine } from 'uwrap';

// create a Canvas2D context with desired font settings
let ctx = document.createElement('canvas').getContext('2d');
ctx.font = "14px Inter, sans-serif";
ctx.letterSpacing = '0.15px';

// init util fns
const { count, test, split } = varPreLine(ctx);

// example text
let text = 'The quick brown fox jumps over the lazy dog.';

// count lines
let numLines = count(text, width);

// test if text will wrap
let willWrap = test(text, width);

// split lines (with optional limit)
let lines = split(text, width, 3);