1.0.9 • Published 3 years ago

frostnumberformat v1.0.9

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

FrostNumberFormat

FrostNumberFormat is a free, open-source number formatting library for JavaScript.

It is a tiny (~1kb gzipped) and modern library, extending the native Intl.NumberFormat class, with additional capabilities for parsing formatted number strings into numbers.

Table Of Contents

Installation

In Browser

<script type="text/javascript" src="/path/to/frost-numberformat.min.js"></script>

Using NPM

npm i frostnumberformat

In Node.js:

const NumberFormat = require('frostnumberformat');

Basic Usage

As the class internally utilizes the native Intl.NumberFormat class, usage is very straightforward.

  • locale is a string with a BCP 47 language tag, or an array of such strings, and will default to the system locale.
  • options is an object containing options for formatting.

For a full list of supported options, see the Intl.NumberFormat documentation.

const formatter = new NumberFormat(locale, options);

Formatting

Return a formatted number string, using the locale and formatting options.

  • number is the number you wish to format.
const numberString = formatter.format(number);

Format To Parts

Return an array of objects, containing the formatted number string in parts.

  • number is the number you wish to format.
const numberParts = formatter.formatToParts(number);

Parsing

Return a parsed number from a formatted number string.

  • numberString is the string you wish to parse.
const number = formatter.parse(numberString);
1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago