Giter VIP home page Giter VIP logo

unitex's Introduction

unitex

Unitex is a unit and number formatter that has wide coverage over unit formatting operations.

Usage

var unit = require('unitex');

unit.format(1234); // '1.234k'
unit.format(1024, { unit: 'B', base: 1024, atomic: true }), // '1 KB'

API

unit.format(number[, options])

options:

base - unit increment - default: 1000
prefix - current base exponent - default: 0
precision - output precision - default: 3
unit - unit symbol - default: '' (if not provided, there will be no space between the number and the unit prefix, override with '')
atomic - whether to use granular IEC units - default: false (for countable values, like bytes)
round - whether to round towards zero when atomic - default: false
trailing - whether output should have trailing zeros - default: false
delimiter - decimal separator - default: '.'
unit.format(1234); // '1.234k'
unit.format(1024, { unit: 'B', base: 1024, atomic: true }); // '1 KB'
unit.format(5555, { precision: 1 }); // '5.5k'

unit.formatter(options)

Uses the same options as unit.format, but caches the options for convenience and better performance.

var fmt = unit.formatter({ unit: 'B', base: 1024, atomic: true });
fmt(1024); // '1 KB'

Todo

  • Implement inverse format

unitex's People

Stargazers

 avatar

Watchers

 avatar  avatar

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.