Server-side Text Width Calculation

JSON →
library 1.0.2 ·javascript
verified May 27, 2026

server-text-width is a utility library designed for server-side environments, specifically Node.js, to accurately calculate the pixel width of text. Unlike browser-based solutions that leverage Canvas or DOM elements, this package operates without a browser environment by relying on pre-generated lookup tables. This capability is crucial for server-side rendering (SSR) scenarios where text needs to be trimmed, aligned, or used in layout calculations without client-side dependencies. The current stable version is 1.0.2, indicating a nascent but stable 1.x release series. Its key differentiators include zero runtime dependencies, full Unicode support, compatibility with custom fonts, and a highly compact base64 encoding for character width data. Developers must use an included `mappingTool.html` to generate these character width lookup tables for their specific fonts, sizes, and weights, which are then passed to the library's `init` function. This approach ensures consistent text measurement results across environments and allows for precise control over font metrics.

total hits 16
actors 7 distinct systems
last hit 6d ago MetaBot
GPTBot
5
MetaBot
4
Script
1
ClaudeBot
1
Search engines
1

top countries 🇺🇸 United States · 🇨🇦 Canada · 🇩🇪 Germany · 🇫🇷 France · 🇳🇱 Netherlands