unitlib
A modern library for unit conversion and manipulation with zero dependencies and a small bundle size.
Installation:
pnmp install unitlib fraction.js
yarn add unitlib fraction.js
npm install unitlib fraction.js
Example usage:
import { SI } from 'unitlib/systems';
const x = SI.parseQuantity('3.2 kW s / kg').toBaseUnits();
x.value
x.unit.toString()
x.toString()
x.toString({ compact: true, fancyUnicode: true })
x.toString({ forceExponential: true })
x.toParts({ forceExponential: true })
Main concepts
- Quantity, for example “2 km” or “8.2 MiB/s”, is a numerical value together with a unit. You can perform arithmetic operations on quantities, or convert them to a different unit.
- Unit can be either simple, for example “km“ or “W”, or composite, for example “kWh/m²“. Simple units are always simplified to a reduced fraction of base units, while composite units allow for things like “Wh/s” to remain unsimplified.
- System, for example SI, Imperial or IEC, is a collection of base units and their prefixes.