Socket
Book a DemoInstallSign in
Socket

format-currency-to-parts

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-currency-to-parts

Format number into currency parts for UI

0.1.2
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Format currency to parts

Why use this?

Having worked on a few projects for financial institutions, currency formatting is often required. Even though using Intl.NumberFormat or currency.js is adequate for many, I have found out that what usually happens is that the UI designs require the currency symbol/code and decimals to be visually different. Moreover, there are currencies that have 0, 2, or 3 decimal digits, instead of just 2. Until Intl​.Number​Format​.prototype​.format​ToParts() becomes widely supported, this library should be able to cover most of the formatting needs (note: this is not a polyfill for it, nor does it support all the functionalities of it).

Why not use this?

If you're developing an interface for non-Latin-based languages, this may not work for you. Where appropriate, some symbols for currencies use its commonly-used Latin form.

Installation

$ npm install format-currency-to-parts

Usage

import { formatCurrencyToParts } from 'format-currency-to-parts';
const formatted = formatCurrencyToParts(options: IFormatCurrencyOptions)(locale: string, amount: number);

Options

  • currency (required): 3-letter ISO 4217 currency code (https://en.wikipedia.org/wiki/ISO_4217)
  • parts (required): An array of parts you want to return, import CurrencyParts for possible values:
    • number: the whole number
    • integer: the integer portion of the number
    • decimals: the fraction portion of the number (including the decimal point), will return empty string if number of decimals for the currency is 0 (e.g. JPY).
    • code: the currency code
    • symbol: the currency symbol (Latin form when approriate)

References

Keywords

currency

FAQs

Package last updated on 14 May 2020

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.