GithubHelp home page GithubHelp logo

kaptajnen / si-prefix Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mal/si-prefix

0.0 1.0 0.0 12 KB

SI and IEC compatible numeric formatter for node

License: MIT License

Makefile 3.30% JavaScript 8.89% CoffeeScript 87.81%

si-prefix's Introduction

SI Prefix

Module for converting SI base units into human readable form. It can also be easily extended to create other units.

Build Status

Install

$ npm install si-prefix

Examples

Basic Formatting

var si = require('si-prefix');

var millimetres = si.metre.format(0.035, ' '),          //=> '35 mm'
    nanograms = si.kilogram.suffix(0.00000000094, ' '), //=> 'ng'
    kibibytes = si.byte.convert(2048),                  //=> [ 2, 'KiB' ]
    kilobytes = si.byte.decimal.convert(2048);          //=> [ 2.048, 'kB' ]

Units available by default are:

  • the seven SI base units
    • metre
    • kilogram - note that the base unit for mass is a kilogram, NOT a gram
    • second
    • ampere
    • kelvin
    • mole
    • candela
  • some SI derived units
    • litre
  • a few others
    • byte - using IEC binary prefixes
    • byte.decimal - using SI prefixes
    • meter - alias of metre
    • liter - alias of litre

Custom Units

var si = require('si-prefix');

// scale with hecto and deca prefixes
var scale = new si.Scale({minor: true}),
    unit = new si.Unit(scale, 'm');

var centimetres = unit.format(0.03, ' '); //=> '3 cm'

Other ways you can customise units include changing the prefixes, removing some exponents, altering the logarithm base and shifting prefixes up or down. You can see examples of this in scale.coffee where Scale.Binary and Scale.Mass are defined.

Upcoming

  • Separate flags for hecto, deca, deci and centi
  • Option to switch between mc and µ for micro prefix
  • Other stuff? File issues if you got 'em!

si-prefix's People

Contributors

mal avatar kaptajnen avatar

Watchers

James Cloos 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.