Giter Site home page Giter Site logo

abranhe / short-numbers Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 10 KB

Make short numbers from long numbers

Home Page: https://p.abranhe.com/short-numbers

License: MIT License

JavaScript 85.05% TypeScript 14.95%
javascript nodejs short-numbers strings truncate truncate-text

short-numbers's Introduction

short-numbers Build Status

Make short numbers from long numbers

Why?

  • Supports space before sufix.
  • Include type definitions.

Install

$ npm install short-numbers

Usage

const shortNumbers = require('short-numbers');

shortNumbers('1000')
// => '1K'

shortNumbers(1000)
// => '1K'

shortNumbers('10300')
// => '10.3K'

shortNumbers('1000000')
// => '1M'

shortNumbers('1000000000')
// => '1B'

shortNumbers('1000000000000')
// => '1T'

shortNumbers('10300', { space: true })
// => '10.3 K'

shortNumbers('1000000', { m: 'million', space: true })
// => '1 million'

API

shortNumbers(input, [options])

input

Type: string | number

The input number you'd like to convert to a short number. It must be a parsable to number string or a number.

options

Type: object

k

Type: string
Default: 'K'

Set the value of the k which is the prefix 'kilo'.

m

Type: string
Default: 'M'

Set the value of the m which is the prefix 'million'.

b

Type: string
Default: 'B'

Set the value of the b which is the prefix 'billion'.

t

Type: string
Default: 'T'

Set the value of the t which is the prefix 'trillion'.

space

Type: string
Default: true

Specify if the contains space before sufix.

Todo

  • Supports for plural sufixes.

Current behavior

shortNumbers('2000000', { m: 'million like', space: true })
// => 2 million like

Desired behavior

// => 2 million likes
  • Suport for prefix. An optional string to prepend to the value, e.g. '$'.

License

MIT © Abraham Hernandez

short-numbers's People

Contributors

abranhe avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

tom-beijner

short-numbers's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.