Registry / productivity / number-formatter-js

number-formatter-js

JSON →
library1.1.0jsnpmunverified

A standalone JavaScript library for formatting numbers with customizable patterns, currency symbols, separators, and signs. Version 1.1.0 is the current stable release, available via npm and yarn. It provides two main formatting functions (formatFromPattern and formatFromConfig) and a pattern parser. Key differentiator: pattern-based formatting similar to Java's DecimalFormat, with no external dependencies, ESM and CJS support.

npm install number-formatter-js
INSTALL
IMPORT
SIG · NUMBER-FORMATTER-J
N
number-formatter-js
productivityjavascriptv1.1.0
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.

formatFromPattern
import { formatFromPattern } from 'number-formatter-js'
const { formatFromPattern } = require('number-formatter-js')
ESM import is recommended; CommonJS require works but may cause issues in bundlers.
formatFromConfig
import { formatFromConfig } from 'number-formatter-js'
const formatFromConfig = require('number-formatter-js').formatFromConfig
Named export, not default.
parsePattern
import { parsePattern } from 'number-formatter-js'
const parsePattern = require('number-formatter-js').parsePattern
Parses a pattern string into a config object for reuse.

Demonstrates basic usage: formatting with pattern, signing, config reuse, and custom separator.

import { formatFromPattern, formatFromConfig, parsePattern } from 'number-formatter-js'; // Simple pattern console.log(formatFromPattern(1000000, '$0,000.00')); // '$1,000,000.00' // With sign console.log(formatFromPattern(-1000000, '$+0,000.00')); // '$-1,000,000.00' // Using config for efficiency let config = parsePattern('+++-> +0,000.00USD'); console.log(formatFromConfig(1000000, config)); // '+++-> +1,000,000.00USD' console.log(formatFromConfig(-1000000, config)); // '+++-> -1,000,000.00USD' // Custom separator console.log(formatFromPattern(1000000, "+++-> +0,000.00USD", { separator: "'" })); // "+++-> +1'000'000.00USD"
Debug
Known issues
gotchaSigns (+/-) must be placed immediately before the number mask without whitespace, otherwise they are treated as prefix/suffix.
fix
Use '+0,000.00' not '+ 0,000.00'.
affects: >=1.0.0
gotchaThe library does not handle localization (e.g., different decimal separators) out of the box; only custom separator option is available.
fix
Use options.separator for thousands separator; decimal point always '.'.
affects: >=1.0.0
gotchaZero digits in the pattern are not allowed in prefix/suffix; they are part of the mask.
fix
To include zeros in prefix, modify config.prefix after parsePattern.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: formatFromPattern is not a function
Wrong import style (default vs named) or using require without destructuring.
fix
Use: import { formatFromPattern } from 'number-formatter-js' or const { formatFromPattern } = require('number-formatter-js')
Error: Invalid pattern format
Pattern contains invalid characters or misplaced signs.
fix
Ensure pattern follows guidelines: signs directly before mask, only 0, ,, ., +, - allowed in mask.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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