$ show adamwdraper/Numeral-js
Numeral.js is a mature, standalone JavaScript library for formatting and manipulating numbers. It provides a plugin-based architecture where number formats (e.g., currency, percentage, bytes, time) and locale definitions are registered separately, allowing extensibility and customization. The core library parses numeric strings, applies locale-specific delimiters and abbreviations, and outputs formatted strings. It also supports arithmetic operations with floating-point correction. The library is distributed as a single-file UMD module and has no external runtime dependencies. It is widely used in web applications for displaying numbers in a human-readable, locale-aware manner.
The LLM identified 2 files worth highlighting for reuse:
Implements a bytes format plugin that supports both decimal (base 1000) and binary (base 1024) units. It registers itself via numeral.register('format', 'bytes', {...}) and provides format/unformat functions. The format function selects the appropriate unit suffix based on value magnitude, and the unformat function parses strings like '5MB' or '3GiB' back to numbers. This component is self-contained, demonstrates a clean plugin pattern, and can be reused in any project needing byte formatting.
Implements a percentage format plugin that scales values by 100 (configurable via numeral.options.scalePercentBy100). It registers itself via numeral.register('format', 'percentage', {...}) and handles formatting with optional space before '%' and correct placement when parentheses are used for negatives. The unformat function reverses the scaling. This component is isolated, demonstrates a common formatting pattern, and can be extracted for use in other projects requiring percentage display.