Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
wNumb
✓ import wNumb from 'wnumb';
✗ import { wNumb } from 'wnumb';
wNumb is typically consumed as a default export when using modern bundlers or CommonJS environments. It is not a named export.
wNumb (CommonJS)
✓ const wNumb = require('wnumb');
For Node.js or older environments using CommonJS, wNumb is imported as a module.
wNumb (Global)
✓ const formatter = wNumb({...}); // Assumes wNumb script tag is present
When included via a <script> tag in a browser, wNumb is exposed globally as the 'wNumb' function.
Demonstrates how to create and use wNumb formatters for currency, percentages, and custom numeric transformations, including encoding and decoding values.
import wNumb from 'wnumb'; // For module environments like Node.js or bundlers
// If using directly in browser via script tag, 'wNumb' is global.
// Create a currency formatter for USD
const usdFormatter = wNumb({
decimals: 2, // Number of decimals (e.g., 2 for $XX.XX)
mark: '.', // Decimal separator
thousand: ',', // Thousands separator
prefix: '$ ',
suffix: ' USD'
});
console.log(usdFormatter.to(12345.678));
// Expected output: "$ 12,345.68 USD"
console.log(usdFormatter.from('$ 5,432.10 USD'));
// Expected output: 5432.1
// Create a percentage formatter
const percentFormatter = wNumb({
decimals: 0,
suffix: '%'
});
console.log(percentFormatter.to(0.75));
// Expected output: "75%"
console.log(percentFormatter.from('99%'));
// Expected output: 0.99
// A simple number formatter with specific rounding
const numberFormatter = wNumb({
decimals: 3,
encoder: value => value * 2, // Example: custom encode function
decoder: value => value / 2 // Example: custom decode function
});
console.log(numberFormatter.to(10.1234));
// Expected output: "20.247" (10.1234 * 2 = 20.2468, rounded to 3 decimals)
Errors
Common errors & fixes
Formatter outputs '-0' for negative numbers with `decimals: 0`
You are using an older version of wNumb (prior to 1.0.2) which had a bug in rounding very small negative numbers.
fixUpgrade your wNumb package to version 1.0.2 or higher.
Unexpected behavior or incorrect parsing when handling decimal values.
Your wNumb version is older than 1.0.1, which contained a bug related to decimal processing.
fixUpgrade your wNumb package to version 1.0.1 or higher.
The `postfix` option is ignored or does not apply the desired text.
In version 1.1.0, the `postfix` option was renamed to `suffix`. While an internal remapping exists, direct use of `suffix` is recommended.
fixChange your formatter configuration from `postfix: 'TEXT'` to `suffix: 'TEXT'`.
Audit
Dependencies
No dependency data recorded yet.