Units Converter
A simple library to convert units. Heavily based on convert-units.
An example implementation of the library.
Key Features
- Tree shakable.
- No dependencies.
- Build for es6, cmj and umd.
- Tested to 4 significant figures.
Installation
npm install units-converter --save
Usage
The library provide a simple chained API to transform units of the same type.
The units are broken down to modules, so it is possible and recommended, to load only the unite types that you are using.
import { voltage } from 'units-converter';
voltage(1).from('V').to('mV').value;
or
import * as converter from 'units-converter';
converter.voltage(1).from('V').to('mV').value;
converter.mass(1).from('lb').to('oz').value;
- Convert unit will return an object of the unit specifed in the "to" function
import { length } from 'units-converter';
length(1200).from('mm').to('m');
import { length } from 'units-converter';
length(12000).from('mm').toBest();
length(12000).from('mm').toBest({ exclude: ['m'] });
length(900).from('mm').toBest({ cutOffNumber: 10 });
length(1000).from('mm').toBest({ cutOffNumber: 10 });
- Possibilities will return an array with the abbreviations of the available units
import { voltage } from 'units-converter';
voltage().from('V').possibilities();
- Describe will return an object with all the details of the unit
import { voltage } from 'units-converter';
voltage().describe('V');
- List will return and array with the description of all the available units
import { voltage } from 'units-converter';
voltage().list();
Units
Length
- mm
- cm
- m
- in
- ft-us
- ft
- fathom
- mi
- nMi
Area
Mass
Volume
- mm3
- cm3
- ml
- l
- kl
- m3
- km3
- tsp
- Tbs
- in3
- fl-oz
- cup
- pnt
- qt
- gal
- ft3
- yd3
Volume Flow Rate
- mm3/s
- cm3/s
- ml/s
- cl/s
- dl/s
- l/s
- l/min
- l/h
- kl/s
- kl/min
- kl/h
- m3/s
- m3/min
- m3/h
- km3/s
- tsp/s
- Tbs/s
- in3/s
- in3/min
- in3/h
- fl-oz/s
- fl-oz/min
- fl-oz/h
- cup/s
- pnt/s
- pnt/min
- pnt/h
- qt/s
- gal/s
- gal/min
- gal/h
- ft3/s
- ft3/min
- ft3/h
- yd3/s
- yd3/min
- yd3/h'
Temperature
Time
- ns
- mu
- ms
- s
- min
- h
- d
- week
- month
- year
Frequency
- Hz
- mHz
- kHz
- MHz
- GHz
- THz
- rpm
- deg/s
- rad/s
Speed
Pace
Pressure
Digital
Illuminance
Parts-Per
Voltage
Current
Power
Apparent Power
Reactive Power
Energy
Reactive Energy
Angle
Charge
Force
Acceleration
Road map
-
Add types to support better integration with typescript using projects.
-
Add functionality for the addition of custom units.
-
Add more units, the goal is to approach the amount of units provided by matlab.
-
Rewrite the project with typescript.