JSPM

@based/pretty-number

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 488
  • Score
    100M100P100Q94402F
  • License MIT

Small package to nicely format a to a specific format, using a human-readable style.

Package Exports

    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 (@based/pretty-number) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Pretty number

    Small package to nicely format a to a specific format, using a human-readable style.

    This package transform a numerical value to a specific format, including converting bytes to to kilobytes, and so on.

    Install

    $ npm i @based/pretty-number

    Usage

    import { prettyNumber } from '@based/pretty-number'
    
    let number = 500000 
    
    console.log(prettyNumber(number,'number-short')) // => prints '50k'
    console.log(prettyNumber(number,'number-human')) // => prints '500000.00'
    console.log(prettyNumber(number,'number-bytes')) // => prints '48.83 kb'
    console.log(prettyNumber(number,'number-euro')) // => prints '€50k'
    console.log(prettyNumber(number,'number-dollar')) // => prints '$50k'
    console.log(prettyNumber(number,'number-pound')) // => prints '£50k'
    
    number = 0.05
    
    console.log(prettyNumber(number,'number-ratio')) // => prints '5%'

    Formats

    The available formats are listed below:

    number-short

    This will change the thousands to 'k', and the millions to 'm', adding a decimal point afterwards.

    number-human

    This will add a decimal point.

    number-bytes

    This will convert the input from bytes to their binary multiples, where 1 kb = 1024 bytes, 1 mb = 1048576 bytes, and so on.

    number-euro

    Will do the same as number-short, but prefixes a '€' sign.

    number-dollar

    Will do the same as number-short, but prefixes a '$' sign.

    number-pound

    Will do the same as number-short, but prefixes a '£' sign.

    number-ratio

    Will show a percentage. Note that 1 equals 100%.