# js-currency-format

> This is a tool for intl currency and percent formatting.the special feature is that it can be uesd in event listenner function onChange of inputNumber

Latest version **1.0.3** (published 2021-04-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install js-currency-format
pnpm add js-currency-format
yarn add js-currency-format
bun add js-currency-format
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-04-18 |
| First published | 2021-04-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 33.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | zgo |
| Maintainers | zgo |
| Keywords | currency format, intl currency, format number to currency, unformat currency to number, percent fommatting, percent unfommatting, intl number, toLocaleString |

## Links

- npm: https://www.npmjs.com/package/js-currency-format
- Homepage: https://github.com/zgoby/js-currency-format
- npm.io page: https://npm.io/package/js-currency-format

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2021-04-18
- 1.0.2 — 2021-04-15
- 1.0.1 — 2021-04-15
- 1.0.0 — 2021-04-14
- 0.4.1 — 2021-04-07
- 0.4.0 — 2021-04-07
- 0.3.6 — 2021-04-06
- 0.3.5 — 2021-04-06
- 0.3.4 — 2021-04-02
- 0.3.3 — 2021-04-02
- 0.3.2 — 2021-04-02
- 0.3.1 — 2021-04-02
- 0.3.0 — 2021-04-02
- 0.2.1 — 2021-04-01
- 0.2.0 — 2021-04-01
- … 4 more at https://npm.io/package/js-currency-format/versions

## README

# intl currency format
> this is a tool that can format and unformat currency and percent.the special feature is that it can be uesd in event listenner function onChange of inputNumber;

## install
```
npm i js-currency-format
```

## usage
```
import CurrencyFormatter from 'js-currency-format';

const currencyFormatter = new CurrencyFormatter({
  locales: 'zh-CN',
  precision: 5,
  currency: 'USD',
  style: 'currency',
  // currencyDisplay: 'code'
});

const b = a.format(10000);
console.log(b);
console.log(a.unformat(b));
```
> if you want to know more details of values from format and unformat, you can see file 'test/index.test.ts';
### api
1. `CurrencyFormatter.prototype.parseThousandthsSymbol: (locales?: string | string[])  => string`: it can get thousandths symbol form the locales
2. `CurrencyFormatter.prototype.parseDecimalSymbol: (locales?: string | string[])  => string`: it can get decimal symbol form the locales
3. `CurrencyFormatter.prototype.parseStyleSymbol(options?: CurrencyFormatterProps) => [styleSymbolPosition, string]`: it can get style symbol form the CurrencyFormatterProps
4. `CurrencyFormatter.prototype.format: (formatVal: number | string, localesOrOption?: string | string[], options?: CurrencyFormatterProps) => string`
5. `CurrencyFormatter.prototype.unformat: (string: number | string, locales?: string | string[], options?: CurrencyFormatterProps & {isNumber: boolean}) => number | string `

### arguments
> [Number.prototype.toLocaleString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString).Maybe you can get some informations from this page of MDN;
```
// constructor
interface CurrencyFormatterProps {
  locales: string | string[],
  minimumIntegerDigits?: number,
  precision?: number,
  useGrouping?: boolean,
  localeMatcher?: 'lookup' | 'best fit',
  formatter?: typeof CurrencyFormatter.formatter,

  style?: 'decimal' | 'currency' | 'percent',
  currency?: string,
  currencyDisplay?: 'symbol' | 'code' | 'name',
}

//options of format
interface optionsofformat {
  minimumIntegerDigits?: number,
  precision?: number,
  useGrouping?: boolean,
  localeMatcher?: 'lookup' | 'best fit',

  style?: 'decimal' | 'currency' | 'percent',
  currency?: string,
  currencyDisplay?: 'symbol' | 'code' | 'name',
}
```

---
_Source: https://npm.io/package/js-currency-format · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
