UNPKG

@thi.ng/units

Version:

Extensible SI unit creation, conversions, quantities & calculations, CLI calculator (incl. Lisp-like DSL and ~170 predefined units & constants)

45 lines (44 loc) 1.36 kB
import { defUnit, mul, pow, prefix } from "../unit.js"; import { cm, ft, inch, km, m, mi, mm } from "./length.js"; const m3 = defUnit("m3", "cubic meter", pow(m, 3)); const mm3 = defUnit("mm3", "cubic millimeter", pow(mm, 3)); const cm3 = defUnit("cm3", "cubic centimeter", pow(cm, 3)); const km3 = defUnit("km3", "cubic kilometer", pow(km, 3)); const cuin = defUnit("cuin", "cubic inch", pow(inch, 3)); const cuft = defUnit("cuft", "cubic foot", pow(ft, 3)); const cumi = defUnit("cumi", "cubic mile", pow(mi, 3)); const l = defUnit("l", "liter", mul(m3, 1e-3, true)); const cl = defUnit("cl", "centiliter", prefix("c", l)); const ml = defUnit("ml", "milliliter", prefix("m", l)); const drop = defUnit("drop", "drop", mul(ml, 1 / 20)); const gal = defUnit("gal", "imperial gallon", mul(l, 4.54609)); const pt = defUnit("pt", "imperial pint", mul(gal, 1 / 8)); const floz = defUnit("fl_oz", "imperial fluid ounce", mul(gal, 1 / 160)); const us_gal = defUnit("us_gal", "US gallon", mul(l, 3.785411784)); const us_pt = defUnit("us_pt", "US pint", mul(us_gal, 1 / 8)); const us_cup = defUnit("us_cup", "US cup", mul(us_gal, 1 / 16)); const us_floz = defUnit( "us_fl_oz", "US fluid ounce", mul(us_gal, 1 / 128) ); export { cl, cm3, cuft, cuin, cumi, drop, floz, gal, km3, l, m3, ml, mm3, pt, us_cup, us_floz, us_gal, us_pt };