Server-side Text Width Calculation
JSON →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.
Traffic · last 30 days ↓50% vs prev 7d
top countries 🇺🇸 United States · 🇨🇦 Canada · 🇩🇪 Germany · 🇫🇷 France · 🇳🇱 Netherlands