number-abbreviation
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

A simple number abbreviation tool

number-abbreviation

A simple number abbreviation tool.

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

Package Sidebar

Install

npm i number-abbreviation

Weekly Downloads

151

Version

1.0.2

License

MIT

Unpacked Size

27.5 kB

Total Files

16

Last publish

Collaborators

  • anselmodev