Socket
Book a DemoInstallSign in
Socket

amount-format

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amount-format

Localization of currency amounts

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Amount format

A wrapper around Number.prototype.toLocaleString.

The purpose is to provide a unified API for formatting currency amounts regardless of browser support and whether the currency is known or not.

// modern browser
format('da-DK', { currency: 'DKK', major: 1500.5 });
	// 1.500,50 kr.

// legacy browser
format('da-DK', { currency: 'DKK', major: 1500.5 });
	// DKK 1500.50

format({
	locales: [ 'da-DK', 'en-GB' ],
	display: 'code',
	currency: 'GBP',
}, 100.2);
	// 100,20 GBP

format([ opts|locale,] amount|{ currency, major });

Options are:

  • currency (three letter ISO)
  • locale (e.g. da-DK or simply da)
  • locales (an array of prioritized locales, left to right)
  • display (one of symbol (default), code or name)
  • matcher (best fit (default) or lookup)
  • grouping (whether to use thousand separators, detaults to true)
  • minimumFractionDigits (used only if localization is not supported, defaults to 2)
$ format-amount --currency USD 124422 --locale en-US
USD 1,244.22

FAQs

Package last updated on 11 Jun 2017

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.