Module for converting SI base units into human readable form. It can also be easily extended to create other units.
$ npm install si-prefix
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 akilogram
, NOT a gramsecond
ampere
kelvin
mole
candela
- some SI derived units
litre
- a few others
byte
- using IEC binary prefixesbyte.decimal
- using SI prefixesmeter
- alias ofmetre
liter
- alias oflitre
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.
- 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!