Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
argon-formatter
Advanced tools
Argon Formatter is universal currency formatter. This is a fork of Smirzaei's currency-formatter except that it provides UMD and ESM builds.
npm install argon-formatter --save
Using currency code
import * as argonFormatter from 'argon-formatter';
argonFormatter.format(1000000, { code: 'USD' });
// => '$1,000,000.00'
argonFormatter.format(1000000, { code: 'GBP' });
// => '£1,000,000.00'
argonFormatter.format(1000000, { code: 'EUR' });
// => '1 000 000,00 €'
Using locale
import * as argonFormatter from 'argon-formatter';
argonFormatter.format(1000000, { locale: 'en-US' });
// => '$1,000,000.00'
argonFormatter.format(1000000, { locale: 'en-GB' });
// => '£1,000,000.00'
argonFormatter.format(1000000, { locale: 'GB' });
// => '£1,000,000.00'
argonFormatter.format(1000000, { locale: 'de-DE' });
// => '1.000.000,00 €'
argonFormatter.format(1000000, { locale: 'nl-NL' });
// => '€1.000.000,00'
import * as argonFormatter from 'argon-formatter';
argonFormatter.findCurrency('USD');
// returns:
// {
// code: 'USD',
// symbol: '$',
// thousandsSeparator: ',',
// decimalSeparator: '.',
// symbolOnLeft: true,
// spaceBetweenAmountAndSymbol: false,
// decimalDigits: 2
// }
argonFormatter.unformat('$10.5', { code: 'USD' })
// => 10.5
argonFormatter.unformat('$1,000,000', { code: 'USD' })
// => 1000000
argonFormatter.unformat('10,5 €', { code: 'EUR' })
// => 10.5
argonFormatter.unformat('1 000 000,00 €', { code: 'EUR' })
// => 1000000
argonFormatter.unformat('1.000,99', { locale: 'de-DE' })
// => 1000.99
argonFormatter.unformat('10\'000 CHF', { code: 'CHF' })
// => 10000
argonFormatter.unformat('10.00 CHF', { code: 'CHF' })
// => 10
argonFormatter.unformat('10,00 CHF', { code: 'CHF' })
// => 1000
Argon Formatter uses accounting under the hood, and you can use its options to override default behavior.
import * as argonFormatter from 'argon-formatter';
argonFormatter.format(1000000, {
symbol: '@',
decimal: '*',
thousand: '^',
precision: 1,
format: '%v %s' // %s is the symbol and %v is the value
});
// => '1^000^000*0 @'
// Different formatting for positive and negative values
argonFormatter.format(-10, {
format: {
pos: '%s%v' // %s is the symbol and %v is the value
neg: '(%s%v)',
zero: '%s%v'
}
});
// => ($10)
const currencies = argonFormatter.currencies();
FAQs
A universal Javascript utility for formatting currency
We found that argon-formatter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.