1.0.2 • Published 2 years ago

metrics-unit-convertion v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Metrics Unit Convertion for javascript

Simple and small (~5Ko) javascript library without dependency to convert metrics between units.

Installation

npm install --save metrics-unit-convertion

Usage

import convert from "metrics-unit-convertion"

const resu = convert(10).from("Kg").to("g");

console.log(resu) ; // 10000

Not in the usage

Standard case

You can not convert from one measurement metric system to another. This example return undefined :

import convert from "metrics-unit-convertion"

const resu = convert(10).from("m³").to("m²");

console.log(resu) ; // undefined

Exception case

There is an exception for liquids, gases or solids like water or fuel for example. In this case, you must provide the volumetric mass density of this liquid.

import convert from "metrics-unit-convertion"

const watterDensity = 1 ;// 1Kg/l at 25°C for 1 atm
const resu = convert(10).from("Kg").withFactor(watterDensity).to("l");
console.log(resu) ; // 1 l

const fuelDensity = 0.79 ;// 0.79 Kg/l  
const resu = convert(10).from("Kg").withFactor(fuelDensity).to("l");
console.log(resu) ; // 12,65822 l

measurement's list

MeasurementSymbolSIName of unit
Angle
radxradian
°degree of arc
Distance /Length / Height
mxmeter
ftfeet
NmNautical Miles
KmKilometers
FLFlight Level (1 FL = 100 feet)
Frequency
HzxHertz
KHzKiloHertz
MHzMegaHertz
GHzGigaHertz
Mass
KgxKilogram
tton
lbspounds
Pressure
PaxPascal
barbar
atmatmosphere
mbarmillibar
HPaHectoPascal
Temperature
KxKelvin
°CDegre Celsius
°FDegre Farenheit
Area
xsquare meter
Km²square Kilometer
Speed
m/sxmeters per second
Km/hKilometers per hour
ktknots ( nautical mile per hour)
ft/minfeet per minute
Volume
xcube meter
Km³cube Kilometer
lliter
Mass Density
Kg/lKilogram per liter
Kg/m³xKilogram per cube meter
t/m³ton per cube meter
Acceleration
m/s²xmeters per square second
g0standard gravity
g*(without a suffix) the local acceleration due to local gravity and centrifugal acceleration, which varies depending on one's position on Earth
flow rate
Kg/mKilogram per meter
l/mliter per meter
lbs/mpounds per meter
  • -> not implemented

License

This library is freely distributable under the terms of the MIT license.