Registry / finance / usd-formatter

usd-formatter

JSON →
library1.0.1jsnpmunverified

A lightweight, zero-dependency JavaScript library for formatting numbers and strings into USD currency strings. Current stable version is 1.0.1, last released in 2018. It accepts any string or number input and outputs a formatted string with a dollar sign, commas, and two decimal places. Options include prepending a symbol (default $). This is a simple, no-frills formatter for basic USD formatting without locale support or advanced configuration.

npm install usd-formatter
INSTALL
IMPORT
SIG · USD-FORMATTER
U
usd-formatter
financejavascriptv1.0.1
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.

formatter
import formatter from 'usd-formatter'
const formatter = require('usd-formatter')
The package ships a default export as a function. In CJS, require works; in ESM, use default import.
formatter
const formatter = require('usd-formatter')
const { formatter } = require('usd-formatter')
CommonJS require returns the function directly, not an object.
formatter
const formatter = require('usd-formatter').default
const formatter = require('usd-formatter')
In TypeScript with esModuleInterop false, default export is under .default.

Basic usage: formatting a number to USD string, handling invalid input, and using custom prepend option.

const formatter = require('usd-formatter'); console.log(formatter(12345678.9)); // $12,345,678.90 console.log(formatter('abc')); // $0.00 (invalid input returns $0.00) console.log(formatter(12345678.9, { prepend: 'USD ' })); // USD 12,345,678.90
Debug
Known issues
gotchaInput that cannot be parsed as a number (e.g., 'abc') returns '$0.00' instead of throwing an error.
fix
Validate input before formatting if you need to handle errors.
affects: >=1.0.0
gotchaThe formatter does not support locale-specific formatting (e.g., spaces instead of commas, different decimal separators).
fix
Use Intl.NumberFormat for full locale support.
affects: >=1.0.0
gotchaThe prepend option only affects the string prepended to the number, not the symbol used for negative amounts or other contexts.
fix
Manually handle negative signs if needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , usd_formatter_1.default) is not a function
Using default import in TypeScript without esModuleInterop or using wrong import style.
fix
Use import formatter from 'usd-formatter' or const formatter = require('usd-formatter').default
Cannot find module 'usd-formatter'
Package not installed or module path incorrect.
fix
Run 'npm install usd-formatter' and ensure node_modules contains the package.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
44 hits · last 30 days
node
40
Resources
usd-formatter — npm install usd-formatter · libregistry