Socket
Book a DemoInstallSign in
Socket

si-prefix

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

si-prefix

SI and IEC compatible numeric formatter

0.2.0
latest
Source
npmnpm
Version published
Weekly downloads
259
793.1%
Maintainers
1
Weekly downloads
 
Created
Source

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!

FAQ

Why is it called si-prefix when it deals with suffixes?

<_<;;

_>;;

Keywords

SI prefix

FAQs

Package last updated on 04 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.