New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

argon-formatter

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argon-formatter

A universal Javascript utility for formatting currency

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Argon Formatter

Argon Formatter is universal currency formatter. This is a fork of Smirzaei's currency-formatter except that it provides UMD and ESM builds.

Install

npm install argon-formatter --save

Basic Usage

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'

Get currency information

import * as argonFormatter from 'argon-formatter';

argonFormatter.findCurrency('USD');
// returns:
// {
//   code: 'USD',
//   symbol: '$',
//   thousandsSeparator: ',',
//   decimalSeparator: '.',
//   symbolOnLeft: true,
//   spaceBetweenAmountAndSymbol: false,
//   decimalDigits: 2
// }

Unformat


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

Advanced Usage

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)

Getting a list of all currencies

const currencies = argonFormatter.currencies();

Keywords

FAQs

Package last updated on 19 Dec 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc