Registry / productivity / fast-number-formatter

fast-number-formatter

JSON →
library2.0.4jsnpmunverified

A React-focused number formatting library (v2.0.4) that enforces reuse of formatter instances to improve performance, avoiding creation of new Intl.NumberFormat objects per call. It wraps native Intl API with a caching layer and provides TypeScript types. Currently in early development with potential breaking changes. Differentiator: fixed API that forces best practices compared to ad-hoc formatting. Released via semantic-release, maintained by Agoda.

npm install fast-number-formatter
INSTALL
IMPORT
SIG · FAST-NUMBER-FORMAT
F
fast-number-formatter
productivityjavascriptv2.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatNumber
import { formatNumber } from 'fast-number-formatter'
import formatNumber from 'fast-number-formatter'
Default export is not available; use named import.
getNumberFormatter
import { getNumberFormatter } from 'fast-number-formatter'
const getNumberFormatter = require('fast-number-formatter').getNumberFormatter
CommonJS require works but named import is preferred for tree-shaking.
setCurrentCulture
import { setCurrentCulture } from 'fast-number-formatter'
Sets global locale; affects all subsequent format calls.
getCustomNumberFormatter
import { getCustomNumberFormatter } from 'fast-number-formatter'
Accepts NumberFormatOptions object for advanced Intl configuration.
NumberFormatOptions
import type { NumberFormatOptions } from 'fast-number-formatter'
import { NumberFormatOptions } from 'fast-number-formatter'
TypeScript type, not a runtime value; use 'import type' for isolated type imports.

Shows basic formatting, locale switching, and cached formatter reuse for performance.

import { formatNumber, getNumberFormatter, setCurrentCulture } from 'fast-number-formatter' // Basic formatting with default locale (en-US) const result1 = formatNumber(12345.6789) // '12,345.68' console.log(result1) // Specify decimal places const result2 = formatNumber(12345.6789, 1) // '12,345.7' console.log(result2) // Change locale globally setCurrentCulture('de-DE') const result3 = formatNumber(12345.6789, 2) // '12.345,68' console.log(result3) // Use a cached formatter for performance const formatter = getNumberFormatter(3, 'fr-FR') console.log(formatter.format(12345.6789)) // '12 345,679' console.log(formatter.format(9876.54321)) // '9 876,543' // Reset to default setCurrentCulture('en-US')
Debug
Known issues
breakingBreaking changes may occur in early versions; API not stable.
fix
Pin exact version and test thoroughly when upgrading.
affects: <3.0.0
gotchasetCurrentCulture affects all subsequent calls globally; may cause unexpected behavior in concurrent environments.
fix
Use locale-specific formatter with getNumberFormatter or getCustomNumberFormatter instead of global state.
affects: all
gotchaImporting TypeScript type NumberFormatOptions at runtime will cause error.
fix
Use 'import type { NumberFormatOptions }' or use inline type if not needed.
affects: all
deprecatedNo deprecation warnings known yet.
affects: none
Errors
Common errors & fixes
TypeError: fast_number_formatter_1.formatNumber is not a function
Default import used instead of named import.
fix
Change to: import { formatNumber } from 'fast-number-formatter'
Module '"fast-number-formatter"' has no exported member 'NumberFormatOptions'.
Attempting to import a type as a value.
fix
Use 'import type { NumberFormatOptions } from 'fast-number-formatter''
Error: Invalid locale. Please set a valid locale string.
setCurrentCulture called with an invalid or unsupported locale.
fix
Verify locale string (e.g., 'en-US', 'de-DE') and ensure Intl support.
TypeError: Cannot read property 'format' of undefined
getNumberFormatter or getCustomNumberFormatter returned undefined due to invalid args.
fix
Ensure decimalPlaces is a number and options object is correct.
Upgrade
Version history
2.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources
fast-number-formatter — npm install fast-number-formatter · libregistry