number-abbreviation
Version:
A simple number abbreviation tool.
116 lines (71 loc) • 2.46 kB
Markdown
<p align="center">
<img src="https://raw.githubusercontent.com/anselmodev/number-abbreviation/master/abbr-logo.jpg" alt="A simple number abbreviation tool" title="A simple number abbreviation tool" width="200" />
</p>
<h1 align="center">number-abbreviation
</h1>
<p align="center">A simple number abbreviation tool.</p>
- Zero dependencies.
- Works with any NodeJs projects.
- Simple usage.
<br>
```shell script
$ npm i number-abbreviation
```
or
```shell script
$ yarn add number-abbreviation
```
- [`numberAbbr(value, [options])`](
<br />
```js
import { numberAbbr } from 'number-abbreviation';
const thousandNumber = numberAbbr(1234);
// return '1.2K'
const millionNumber = numberAbbr(7654321);
// return '7.7M'
const billionNumber = numberAbbr(9356412313);
// return '9.4B'
const trillionNumber = numberAbbr(5767473333233);
// return '5.8T'
```
```js
import { numberAbbr } from 'number-abbreviation';
const millionNumber = numberAbbr(7654321, { decimals: 2 });
// return '7.65M'
```
```js
import { numberAbbr } from 'number-abbreviation';
const mySuffixes = ["Mil", "Milhões", "Bilhões", "Trilhões"];
const millionNumber = numberAbbr(
7654321,
{
suffixes: mySufixes,
suffixSpace: true
}
);
// return '7.6 Milhões'
```
<br />
The <b>"number"</b> to abbreviation. <br><br>
The <b>"number"</b> of truncated decimals. <br>
Default is: <b>{ decimals: 1 }</b>. <br><br>
An <b>"array"</b> of strings. <br>
It is mandatory to define the value of the 4 indices. <br>
Default is: <b>{ suffixes: [ 'K', 'M', 'B', 'T' ] }</b>. <br><br>
If true, sets a space between the suffix and abbreviated number.<br>
Default is: <b>{ suffixSpace: false }</b>. <br><br>
| [<img src="https://avatars2.githubusercontent.com/u/14978874?v=3&s=115"><br><sub>@anselmodev</sub>](https://github.com/anselmodev) |
| :--------------------------------------------------------------------------------------------------------------------------------: |