0.8.11 • Published 10 months ago
unitlib v0.8.11
unitlib
A modern library for unit conversion and manipulation with zero dependencies and a small bundle size.
Installation:
pnmp install unitlib fraction.js
# or
yarn add unitlib fraction.js
# or
npm install unitlib fraction.js
Example usage:
import { SI } from 'unitlib/systems';
const x = SI.parseQuantity('3.2 kW s / kg').toBaseUnits();
x.value // 3200
x.unit.toString() // "m^2 / s^2"
x.toString() // "3200 m^2 / s^2"
x.toString({ compact: true, fancyUnicode: true }) // "3200m²/s²"
x.toString({ forceExponential: true }) // "3.2 * 10^3 m^2 / s^2"
x.toParts({ forceExponential: true })
// [
// { type: 'multiplicator', string: '3.2', number: 3.2 },
// { type: 'multiplicationSign', string: ' * ' },
// { type: 'base', string: '10', number: 10 },
// { type: 'exponent', string: '^3', number: 3 },
// { type: 'unit', string: 'm^2', prefix: '', baseUnit: 'm', exponent: { type: 'exponent', string: '^2', number: 2 } },
// { type: 'divisionSign', string: ' / ' },
// { type: 'unit', string: 's^2', prefix: '', baseUnit: 's', exponent: { type: 'exponent', string: '^2', number: 2 } }
// ]
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.
0.8.9
10 months ago
0.8.11
10 months ago
0.8.10
10 months ago
0.8.8
1 year ago
0.8.7
1 year ago
0.8.5
1 year ago
0.8.4
1 year ago
0.8.6
1 year ago
0.8.3
1 year ago
0.8.2
1 year ago
0.8.1
1 year ago
0.8.0
1 year ago
0.7.0
1 year ago
0.6.2
1 year ago
0.6.1
1 year ago
0.6.0
1 year ago
0.5.3
1 year ago
0.5.2
2 years ago
0.5.1
2 years ago
0.5.0
2 years ago
0.4.5
2 years ago
0.4.4
2 years ago
0.4.7
2 years ago
0.4.6
2 years ago
0.4.1
2 years ago
0.4.0
2 years ago
0.4.3
2 years ago
0.4.2
2 years ago
0.3.0
3 years ago
0.2.3
3 years ago
0.2.1
3 years ago
0.1.2
3 years ago
0.2.0
3 years ago
0.2.2
3 years ago
0.1.3
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago