A simple number abbreviation tool.
npm install number-abbreviation

A simple number abbreviation tool.
- Zero dependencies.
- Works with any NodeJs projects.
- Simple usage.
#### Install with NPM or YARN:
``shell script`
$ npm i number-abbreviation
or
`shell script`
$ yarn add number-abbreviation
#### Methods
- [numberAbbr(value, [options])](#abbreviate-a-number)
`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'
`Abbreviate a number [options] - suffixes and suffixSpace
`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'
`
#### numberAbbr(value: number)
The "number" to abbreviation.
#### numberAbbr(value: number, { decimals: number })
The "number" of truncated decimals.
Default is: { decimals: 1 }.
#### numberAbbr(value: number, { suffixes: string[] })
An "array" of strings.
It is mandatory to define the value of the 4 indices.
Default is: { suffixes: [ 'K', 'M', 'B', 'T' ] }.
#### numberAbbr(value: number, { suffixSpace: boolean })`
If true, sets a space between the suffix and abbreviated number.
Default is: { suffixSpace: false }.
|
@anselmodev |
| :--------------------------------------------------------------------------------------------------------------------------------: |