JSPM

number-abbreviation

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 169
  • Score
    100M100P100Q85720F
  • License MIT

A simple number abbreviation tool.

Package Exports

  • number-abbreviation
  • number-abbreviation/dist/index.js
  • number-abbreviation/dist/number-abbreviation.esm.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (number-abbreviation) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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