number-abbreviation
v1.0.2
Published
A simple number abbreviation tool.
Downloads
314
Maintainers
Readme
Features
- Zero dependencies.
- Works with any NodeJs projects.
- Simple usage.
Install
Install with NPM or YARN:
$ npm i number-abbreviation
or
$ yarn add number-abbreviation
Methods
Abbreviate a number (simple usage)
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'
Abbreviate a number [options] - decimals
import { numberAbbr } from 'number-abbreviation';
const millionNumber = numberAbbr(7654321, { decimals: 2 });
// return '7.65M'
Abbreviate a number [options] - suffixes and suffixSpace
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'
Parameters
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 }.
Autor
| @anselmodev | | :--------------------------------------------------------------------------------------------------------------------------------: |