numberstring is a JavaScript library that converts numbers to their English word representation. It supports numbers from 0 to Number.MAX_SAFE_INTEGER (~9 quadrillion).
- Converts a number to English words
- Returns
stringon success,falseon invalid input - Options:
{ cap: 'title'|'upper'|'lower', punc: '!'|'?'|'.' }
comma(n)- Format number with comma separatorsgroup(n)- Get magnitude group (0=ones, 1=thousands, 2=millions, etc.)
import numberstring, { comma, group } from 'numberstring';
numberstring(42); // 'forty-two'
numberstring(1000000); // 'one million'
numberstring(100, { cap: 'title' }); // 'One Hundred'
numberstring(50, { punc: '!' }); // 'fifty!'
comma(1234567); // '1,234,567'
group(1000000); // 2 (millions)- Only accepts non-negative integers within safe integer range
- Returns
falsefor: NaN, Infinity, negative numbers, strings, objects - Hyphenates compound numbers (e.g., "forty-two", "ninety-nine")
- This is an ESM-only package (use
import, notrequire)
npm test # Run tests
npm run lint # Run ESLint
npm run test:coverage # Run with coverageindex.js- Single file containing all logic- Pure functions, no side effects
- Frozen arrays for immutable word lists
- Full JSDoc type documentation