Registry / productivity / amount

amount

JSON →
library1.0.6jsnpmunverified

Lightweight library for formatting amounts and currencies in JavaScript. Version 1.0.6 provides two main functions: `amount()` for number formatting with customizable decimal and thousands separators, and `amount.currency()` for locale-based or fully custom currency formatting. It supports all major currencies (EUR, USD, etc.) with automatic symbol placement and spacing. The package is dependency-free, uses CJS (CommonJS) modules, and is available via npm. Updated infrequently; last release in 2022.

npm install amount
INSTALL
IMPORT
SIG · AMOUNT
A
amount
productivityjavascriptv1.0.6
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.

amount
const amount = require('amount');
import amount from 'amount';
The package uses CommonJS module format; ES module imports are not supported.
amount (with named export)
const { amount } = require('amount');
const { amount } = await import('amount');
Named import works only with require(), not dynamic import().
currency function
amount.currency(12345.67, 'USD');
currency(12345.67, 'USD');
currency is a method on the amount function; it is not a standalone export.

Demonstrates basic number formatting and currency formatting with both automatic and custom options.

const amount = require('amount'); // Format number with default (no separators) console.log(amount(87686.987)); // '87686.987' // Custom decimal separator console.log(amount(87686.987, ',')); // '87686,987' // Custom thousand separator console.log(amount(87686.987, ',', '.')); // '87.686,987' // Limit decimal digits console.log(amount(87686.987, ',', '.', 2)); // '87.686,98' console.log(amount(87686, ',', '.', 2)); // '87.686,00' // Currency formatting (auto) console.log(amount.currency(87686.987, 'EUR')); // '87 686,98 €' console.log(amount.currency(87686.987, 'USD')); // '$87,686.98' // Custom currency options console.log(amount.currency(87686.987, { thousands_separator: ',', decimals_separator: '.', decimal_digits: 2, symbol: '€', symbol_on_left: false, symbol_space: ' ', })); // '87.686,98 €'
Debug
Known issues
gotchaThe `amount` function mutates the input argument?
fix
No, it does not mutate. But note that decimal_digits parameter truncates (not rounds).
affects: >=1.0.0
gotchaThousands separator is inserted based on the decimals_separator position; incorrect order may produce unexpected output.
fix
Ensure arguments are in correct order: amount(value, decimals_separator, thousands_separator, decimal_digits).
affects: >=1.0.0
gotchaNo built-in support for locale-specific formatting; only provides basic separators and currency symbols.
fix
Use Intl.NumberFormat for full locale support.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: amount is not a function
Using ES module import (import amount from 'amount') on a CommonJS module.
fix
Use require('amount') instead of import.
amount.currency is not a function
Trying to call amount.currency without requiring the package correctly, or using a bundler that tree-shakes the currency function.
fix
Ensure you call require('amount') and use amount.currency(). Avoid tree-shaking by using require().
ReferenceError: currency is not defined
Calling currency(...) without the amount prefix.
fix
Call amount.currency(...) instead.
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
49 hits · last 30 days
node
42
OpenAI (training)
1
Resources
packageamount
amount — npm install amount · libregistry