From 22031e6e91977a29fe9a0b702869778975f6c683 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Tue, 14 Mar 2023 00:14:42 +0100 Subject: [PATCH] refactor(units): rename builtin units, update readme --- packages/units/README.md | 359 +++++++++++++++--------------- packages/units/src/accel.ts | 20 +- packages/units/src/angle.ts | 14 +- packages/units/src/area.ts | 20 +- packages/units/src/data.ts | 35 +-- packages/units/src/electric.ts | 33 +-- packages/units/src/energy.ts | 10 +- packages/units/src/force.ts | 6 +- packages/units/src/frequency.ts | 16 +- packages/units/src/length.ts | 28 +-- packages/units/src/luminous.ts | 10 +- packages/units/src/mass.ts | 20 +- packages/units/src/power.ts | 12 +- packages/units/src/pressure.ts | 18 +- packages/units/src/speed.ts | 14 +- packages/units/src/substance.ts | 2 +- packages/units/src/temperature.ts | 4 +- packages/units/src/time.ts | 20 +- packages/units/src/volume.ts | 36 ++- packages/units/test/index.ts | 54 ++--- packages/units/tpl.readme.md | 357 ++++++++++++++--------------- 21 files changed, 554 insertions(+), 534 deletions(-) diff --git a/packages/units/README.md b/packages/units/README.md index 35d0a3d8b8..ebaf00d698 100644 --- a/packages/units/README.md +++ b/packages/units/README.md @@ -97,232 +97,239 @@ The following units are provided as "builtins", here grouped by dimension: #### Acceleration -| Unit name | JS name | Description | -|-----------|----------|---------------------------| -| `m/s2` | `M_S2` | meter per second squared | -| `ft/s2` | `FT_S2` | foot per second squared | -| `rad/s2` | `RAD_S2` | radian per second squared | -| `g0` | `G0` | standard gravity | +| Unit name | Variable name | Description | +|-----------|---------------|---------------------------| +| `m/s2` | `m_s2` | meter per second squared | +| `ft/s2` | `ft_s2` | foot per second squared | +| `rad/s2` | `rad_s2` | radian per second squared | +| `g0` | `g0` | standard gravity | #### Angle -| Unit name | JS name | Description | -|-----------|----------|-------------| -| `arcmin` | `ARCMIN` | arc minute | -| `arcsec` | `ARCSEC` | arc second | -| `deg` | `DEG` | degree | -| `gon` | `GON` | gradian | -| `rad` | `RAD` | radian | -| `sr` | `SR` | steradian | -| `turn` | `TURN` | turn | +| Unit name | Variable name | Description | +|-----------|---------------|-------------| +| `arcmin` | `arcmin` | arc minute | +| `arcsec` | `arcsec` | arc second | +| `deg` | `deg` | degree | +| `gon` | `gon` | gradian | +| `rad` | `rad` | radian | +| `sr` | `sr` | steradian | +| `turn` | `turn` | turn | #### Area -| Unit name | JS name | Description | -|-----------|---------|-------------------| -| `m2` | `M2` | square meter | -| `cm2` | `CM2` | square centimeter | -| `mm2` | `MM2` | square millimeter | -| `km2` | `KM2` | square kilometer | -| `ha` | `HA` | hectar | -| `ac` | `AC` | acre | -| `sqin` | `SQIN` | square inch | -| `sqft` | `SQFT` | square foot | -| `sqmi` | `SQMI` | square mile | +| Unit name | Variable name | Description | +|-----------|---------------|-------------------| +| `m2` | `m2` | square meter | +| `cm2` | `cm2` | square centimeter | +| `mm2` | `mm2` | square millimeter | +| `km2` | `km2` | square kilometer | +| `ha` | `ha` | hectar | +| `ac` | `ac` | acre | +| `sqin` | `sqin` | square inch | +| `sqft` | `sqft` | square foot | +| `sqmi` | `sqmi` | square mile | #### Data -| Unit name | JS name | Description | -|-----------|---------|-----------------| -| `bit` | `BIT` | bit | -| `kbit` | `KBIT` | kilobit | -| `Mbit` | `MBIT` | megabit | -| `Gbit` | `GBIT` | gigabit | -| `Tbit` | `TBIT` | terabit | -| `B` | `BYTE` | byte (8 bit) | -| `KB` | `KBYTE` | kilobyte (1024) | -| `MB` | `MBYTE` | megabyte (1024) | -| `GB` | `GBYTE` | gigabyte (1024) | -| `TB` | `TBYTE` | terabyte (1024) | -| `PB` | `PBYTE` | petabyte (1024) | -| `EB` | `EBYTE` | exabyte (1024) | +| Unit name | Variable name | Description | +|-----------|---------------|-------------------| +| `bit` | `bit` | bit | +| `kbit` | `kbit` | kilobit | +| `Mbit` | `Mbit` | megabit | +| `Gbit` | `Gbit` | gigabit | +| `Tbit` | `Tbit` | terabit | +| `B` | `B` | byte (8 bit) | +| `kB` | `kB` | kilobyte (metric) | +| `MB` | `MB` | megabyte (metric) | +| `GB` | `GB` | gigabyte (metric) | +| `TB` | `TB` | terabyte (metric) | +| `PB` | `PB` | petabyte (metric) | +| `EB` | `EB` | exabyte (metric) | +| `KiB` | `KiB` | kibibyte (1024) | +| `MiB` | `MiB` | mebibyte (1024) | +| `GiB` | `GiB` | gibibyte (1024) | +| `TiB` | `TiB` | tebibyte (1024) | +| `PiB` | `PiB` | pebibyte (1024) | +| `EiB` | `EiB` | exbibyte (1024) | #### Electric current -| Unit | JS name | Description | -|------|-----------|-------------------| -| A | `A` | ampere | -| mA | `MA` | milliampere | -| mAh | `MA_H` | milliampere-hours | -| C | `C` | coulomb | -| V | `V` | volt | -| mV | `MV` | millivolt | -| kV | `KV` | kilovolt | -| F | `F` | farad | -| pF | `PF` | picofarad | -| µF | `µF` | microfarad | -| Ω | `OHM` | ohm | -| kΩ | `KOHM` | kiloohm | -| MΩ | `MOHM` | megaohm | -| GΩ | `GOHM` | gigaohm | -| S | `SIEMENS` | siemens | -| Wb | `WB` | weber | -| T | `TESLA` | tesla | -| H | `HENRY` | henry | +| Unit | Variable name | Description | +|------|---------------|-------------------| +| A | `A` | ampere | +| mA | `mA` | milliampere | +| mAh | `mAh` | milliampere-hours | +| C | `C` | coulomb | +| V | `V` | volt | +| mV | `mV` | millivolt | +| kV | `kV` | kilovolt | +| MV | `MV` | megavolt | +| F | `F` | farad | +| pF | `pF` | picofarad | +| µF | `µF` | microfarad | +| Ω | `Ω` | ohm | +| kΩ | `kΩ` | kiloohm | +| MΩ | `MΩ` | megaohm | +| GΩ | `GΩ` | gigaohm | +| S | `S` | siemens | +| Wb | `Wb` | weber | +| T | `T` | tesla | +| H | `H` | henry | #### Energy -| Unit | JS name | Description | -|------|---------|-------------| -| J | `J` | joule | -| kJ | `KJ` | kilojoule | -| MJ | `MJ` | megajoule | -| GJ | `GJ` | gigajoule | -| cal | `CAL` | calorie | -| kcal | `KCAL` | kilocalorie | +| Unit | Variable name | Description | +|------|---------------|-------------| +| J | `J` | joule | +| kJ | `kJ` | kilojoule | +| MJ | `MJ` | megajoule | +| GJ | `GJ` | gigajoule | +| cal | `cal` | calorie | +| kcal | `kcal` | kilocalorie | #### Force -| Unit | JS name | Description | -|------|---------|-------------| -| `N` | `N` | newton | +| Unit | Variable name | Description | +|------|---------------|-------------| +| `N` | `N` | newton | #### Frequency -| Unit | JS name | Description | -|-------|---------|---------------------| -| `Hz` | `HZ` | hertz | -| `kHz` | `KHZ` | kilohertz | -| `MHz` | `MHZ` | megahertz | -| `GHz` | `GHZ` | gigahertz | -| `THz` | `THZ` | terahertz | -| `rpm` | `RPM` | rotation per minute | -| `ω` | `OMEGA` | radian per second | +| Unit | Variable name | Description | +|-------|---------------|---------------------| +| `Hz` | `Hz` | hertz | +| `kHz` | `KHz` | kilohertz | +| `MHz` | `MHz` | megahertz | +| `GHz` | `GHz` | gigahertz | +| `THz` | `THz` | terahertz | +| `rpm` | `rpm` | rotation per minute | +| `ω` | `ω` | radian per second | #### Length -| Unit name | JS name | Description | -|-----------|---------|-------------------| -| `m` | `M` | meter | -| `cm` | `CM` | centimeter | -| `mm` | `MM` | millimeter | -| `µm` | `µM` | micrometer | -| `nm` | `NM` | nanometer | -| `km` | `KM` | kilometer | -| `au` | `AU` | astronomical unit | -| `in` | `IN` | inch | -| `ft` | `FT` | foot | -| `yd` | `YD` | yard | -| `mi` | `MI` | mile | -| `nmi` | `NMI` | nautical mile | -| `pica` | `PICA` | pica | -| `point` | `POINT` | point | +| Unit name | Variable name | Description | +|-----------|---------------|-------------------| +| `m` | `m` | meter | +| `cm` | `cm` | centimeter | +| `mm` | `mm` | millimeter | +| `µm` | `µm` | micrometer | +| `nm` | `nm` | nanometer | +| `km` | `km` | kilometer | +| `au` | `au` | astronomical unit | +| `in` | `in` | inch | +| `ft` | `ft` | foot | +| `yd` | `yd` | yard | +| `mi` | `mi` | mile | +| `nmi` | `nmi` | nautical mile | +| `pica` | `pica` | pica | +| `point` | `point` | point | #### Luminous intensity -| Unit | JS name | Description | -|------|---------|-------------| -| `cd` | `CD` | candela | -| `lm` | `LM` | lumen | -| `lx` | `LX` | lux | +| Unit | Variable name | Description | +|------|---------------|-------------| +| `cd` | `cd` | candela | +| `lm` | `lm` | lumen | +| `lx` | `lx` | lux | #### Mass -| Unit name | JS name | Description | -|-----------|---------|----------------| -| `µg` | `µG` | microgram | -| `mg` | `mG` | milligram | -| `g` | `G` | gram | -| `kg` | `KG` | kilogram | -| `t` | `T` | tonne | -| `kt` | `KT` | kilotonne | -| `Mt` | `MT` | megatonne | -| `Gt` | `GT` | gigatonne | -| `lb` | `LB` | imperial pound | -| `st` | `ST` | stone | +| Unit name | Variable name | Description | +|-----------|---------------|----------------| +| `µg` | `µg` | microgram | +| `mg` | `mg` | milligram | +| `g` | `g` | gram | +| `kg` | `kg` | kilogram | +| `t` | `t` | tonne | +| `kt` | `kt` | kilotonne | +| `Mt` | `Mt` | megatonne | +| `Gt` | `Gt` | gigatonne | +| `lb` | `lb` | imperial pound | +| `st` | `st` | stone | #### Power -| Unit name | JS name | Description | -|-----------|---------|---------------| -| `W` | `W` | watt | -| `mW` | `MW` | milliwatt | -| `kW` | `KW` | kilowatt | -| `MW` | `MW` | megawatt | -| `GW` | `GW` | gigawatt | -| `TW` | `TW` | terawatt | -| `Wh` | `WH` | watt-hour | -| `kWh` | `KWH` | kilowatt-hour | +| Unit name | Variable name | Description | +|-----------|---------------|---------------| +| `W` | `W` | watt | +| `mW` | `mW` | milliwatt | +| `kW` | `kW` | kilowatt | +| `MW` | `MW` | megawatt | +| `GW` | `GW` | gigawatt | +| `TW` | `TW` | terawatt | +| `Wh` | `Wh` | watt-hour | +| `kWh` | `kWh` | kilowatt-hour | #### Pressure -| Unit name | JS name | Description | -|-----------|---------|-----------------------| -| `Pa` | `PA` | pascal | -| `kPa` | `KPA` | kilopascal | -| `MPa` | `MPA` | megapascal | -| `GPa` | `GPA` | gigapascal | -| `at` | `AT` | technical atmosphere | -| `atm` | `ATM` | atmosphere | -| `bar` | `BAR` | bar | -| `psi` | `PSI` | pound per square inch | +| Unit name | Variable name | Description | +|-----------|---------------|-----------------------| +| `Pa` | `Pa` | pascal | +| `kPa` | `KPa` | kilopascal | +| `MPa` | `MPa` | megapascal | +| `GPa` | `GPa` | gigapascal | +| `at` | `at` | technical atmosphere | +| `atm` | `atm` | atmosphere | +| `bar` | `bar` | bar | +| `psi` | `psi` | pound per square inch | #### Speed -| Unit | JS name | Description | -|--------|---------|--------------------| -| `m/s` | `M_S` | meter per second | -| `km/h` | `KM_H` | kilometer per hour | -| `mph` | `MPH` | mile per hour | -| `kn` | `KN` | knot | +| Unit | Variable name | Description | +|--------|---------------|--------------------| +| `m/s` | `m_s` | meter per second | +| `km/h` | `km_h` | kilometer per hour | +| `mph` | `mph` | mile per hour | +| `kn` | `kn` | knot | #### Substance -| Unit | JS name | Description | -|-------|---------|-------------| -| `mol` | `MOL` | mole | +| Unit | Variable name | Description | +|-------|---------------|-------------| +| `mol` | `mol` | mole | #### Temperature -| Unit | JS name | Description | -|------|---------|-------------------| -| `K` | `K` | kelvin | -| `℃` | `DEG_C` | degree celsius | -| `℉` | `DEG_F` | degree fahrenheit | +| Unit | Variable name | Description | +|------|---------------|-------------------| +| `K` | `K` | kelvin | +| `℃` | `celsius` | degree celsius | +| `℉` | `fahrenheit` | degree fahrenheit | #### Time -| Unit | JS name | Description | -|-------|---------|--------------------| -| s | `S` | second | -| ms | `MS` | millisecond | -| µs | `µS` | microsecond | -| ns | `NS` | nanosecond | -| min | `MIN` | minute | -| h | `H` | hour | -| day | `DAY` | day | -| week | `WEEK` | week | -| month | `MONTH` | month (30 days) | -| year | `YEAR` | year (365.25 days) | +| Unit | Variable name | Description | +|-------|---------------|--------------------| +| s | `s` | second | +| ms | `ms` | millisecond | +| µs | `µs` | microsecond | +| ns | `ns` | nanosecond | +| min | `min` | minute | +| h | `h` | hour | +| day | `d` | day | +| week | `week` | week | +| month | `month` | month (30 days) | +| year | `year` | year (365.25 days) | #### Volume -| Unit | JS name | Description | -|-------------|-----------|----------------------| -| `m3` | `M3` | cubic meter | -| `mm3` | `MM3` | cubic millimeter | -| `cm3` | `CM3` | cubic centimeter | -| `km3` | `KM3` | cubic kilometer | -| `l` | `L` | liter | -| `cl` | `CL` | centiliter | -| `ml` | `ML` | milliliter | -| `imp gal` | `GAL` | imperial gallon | -| `imp pt` | `PT` | imperial pint | -| `imp fl oz` | `FLOZ` | imperial fluid ounce | -| `us gal` | `US_GAL` | US gallon | -| `us pt` | `US_PT` | US pint | -| `us cup` | `US_CUP` | US cup | -| `us fl oz` | `US_FLOZ` | US fluid ounce | +| Unit | Variable name | Description | +|------------|---------------|----------------------| +| `m3` | `m3` | cubic meter | +| `mm3` | `mm3` | cubic millimeter | +| `cm3` | `cm3` | cubic centimeter | +| `km3` | `km3` | cubic kilometer | +| `l` | `l` | liter | +| `cl` | `cl` | centiliter | +| `ml` | `ml` | milliliter | +| `gal` | `gal` | imperial gallon | +| `pt` | `pt` | imperial pint | +| `fl oz` | `floz` | imperial fluid ounce | +| `us gal` | `us_gal` | US gallon | +| `us pt` | `us_pt` | US pint | +| `us cup` | `us_cup` | US cup | +| `us fl oz` | `us_floz` | US fluid ounce | ### Creating & deriving units @@ -375,7 +382,7 @@ For Node.js REPL: const units = await import("@thi.ng/units"); ``` -Package sizes (brotli'd, pre-treeshake): ESM: 3.17 KB +Package sizes (brotli'd, pre-treeshake): ESM: 3.21 KB ## Dependencies diff --git a/packages/units/src/accel.ts b/packages/units/src/accel.ts index 3198a3419f..5b4dd3f6c3 100644 --- a/packages/units/src/accel.ts +++ b/packages/units/src/accel.ts @@ -1,24 +1,24 @@ -import { RAD } from "./angle.js"; -import { FT, M } from "./length.js"; -import { S } from "./time.js"; +import { rad } from "./angle.js"; +import { ft, m } from "./length.js"; +import { s } from "./time.js"; import { defUnit, div, mul, pow } from "./unit.js"; -export const M_S2 = defUnit( +export const m_s2 = defUnit( "m/s2", "meter per second squared", - div(M, pow(S, 2)) + div(m, pow(s, 2)) ); -export const FT_S2 = defUnit( +export const ft_s2 = defUnit( "ft/s2", "foot per second squared", - div(FT, pow(S, 2)) + div(ft, pow(s, 2)) ); -export const RAD_S2 = defUnit( +export const rad_s2 = defUnit( "rad/s2", "radian per second squared", - div(RAD, pow(S, 2)) + div(rad, pow(s, 2)) ); -export const G0 = defUnit("g0", "standard gravity", mul(M_S2, 9.80665)); +export const g0 = defUnit("g0", "standard gravity", mul(m_s2, 9.80665)); diff --git a/packages/units/src/angle.ts b/packages/units/src/angle.ts index 4f65b6d66b..8c116a5f19 100644 --- a/packages/units/src/angle.ts +++ b/packages/units/src/angle.ts @@ -2,11 +2,11 @@ import { defUnit, dimensionless, mul } from "./unit.js"; const PI = Math.PI; -export const RAD = defUnit("rad", "radian", dimensionless(1, 0, true)); -export const DEG = defUnit("deg", "degree", mul(RAD, PI / 180)); -export const GON = defUnit("gon", "gradian", mul(RAD, PI / 200)); -export const TURN = defUnit("turn", "turn", mul(RAD, 2 * PI)); -export const ARCMIN = defUnit("arcmin", "arc minute", mul(RAD, PI / 10800)); -export const ARCSEC = defUnit("arcsec", "arc second", mul(RAD, PI / 648000)); +export const rad = defUnit("rad", "radian", dimensionless(1, 0, true)); +export const deg = defUnit("deg", "degree", mul(rad, PI / 180)); +export const gon = defUnit("gon", "gradian", mul(rad, PI / 200)); +export const turn = defUnit("turn", "turn", mul(rad, 2 * PI)); +export const arcmin = defUnit("arcmin", "arc minute", mul(rad, PI / 10800)); +export const arcsec = defUnit("arcsec", "arc second", mul(rad, PI / 648000)); -export const SR = defUnit("sr", "steradian", dimensionless(1, 0, true)); +export const sr = defUnit("sr", "steradian", dimensionless(1, 0, true)); diff --git a/packages/units/src/area.ts b/packages/units/src/area.ts index c064377b3c..4008ff9aab 100644 --- a/packages/units/src/area.ts +++ b/packages/units/src/area.ts @@ -1,13 +1,13 @@ -import { CM, FT, IN, KM, M, MI, MM } from "./length.js"; +import { cm, ft, inch, km, m, mi, mm } from "./length.js"; import { defUnit, mul, pow } from "./unit.js"; -export const M2 = defUnit("m2", "square meter", pow(M, 2)); -export const MM2 = defUnit("mm2", "square millimeter", pow(MM, 2)); -export const CM2 = defUnit("cm2", "square centimeter", pow(CM, 2)); -export const KM2 = defUnit("km2", "square kilometer", pow(KM, 2)); -export const HA = defUnit("ha", "hectar", mul(M2, 1e4)); +export const m2 = defUnit("m2", "square meter", pow(m, 2)); +export const mm2 = defUnit("mm2", "square millimeter", pow(mm, 2)); +export const cm2 = defUnit("cm2", "square centimeter", pow(cm, 2)); +export const km2 = defUnit("km2", "square kilometer", pow(km, 2)); +export const ha = defUnit("ha", "hectar", mul(m2, 1e4)); -export const AC = defUnit("ac", "acre", mul(M2, 4046.86)); -export const SQIN = defUnit("sqin", "square inch", pow(IN, 2)); -export const SQFT = defUnit("sqft", "square foot", pow(FT, 2)); -export const SQMI = defUnit("sqmi", "square mile", pow(MI, 2)); +export const ac = defUnit("ac", "acre", mul(m2, 4046.86)); +export const sqin = defUnit("sqin", "square inch", pow(inch, 2)); +export const sqft = defUnit("sqft", "square foot", pow(ft, 2)); +export const sqmi = defUnit("sqmi", "square mile", pow(mi, 2)); diff --git a/packages/units/src/data.ts b/packages/units/src/data.ts index 9c8868c091..5ffa05b173 100644 --- a/packages/units/src/data.ts +++ b/packages/units/src/data.ts @@ -1,15 +1,24 @@ import { defUnit, dimensionless, mul, prefix } from "./unit.js"; -export const BIT = defUnit("bit", "bit", dimensionless(1, 0, true)); -export const KBIT = defUnit("kbit", "kilobit", prefix("k", BIT)); -export const MBIT = defUnit("Mbit", "megabit", prefix("M", BIT)); -export const GBIT = defUnit("Gbit", "gigabit", prefix("G", BIT)); -export const TBIT = defUnit("Tbit", "terabit", prefix("T", BIT)); - -export const BYTE = defUnit("B", "byte", mul(BIT, 8, true)); -export const KBYTE = defUnit("KB", "kilobyte", mul(BYTE, 1024)); -export const MBYTE = defUnit("MB", "megabyte", mul(KBYTE, 1024)); -export const GBYTE = defUnit("GB", "gigabyte", mul(MBYTE, 1024)); -export const TBYTE = defUnit("TB", "terabyte", mul(GBYTE, 1024)); -export const PBYTE = defUnit("PB", "petabyte", mul(TBYTE, 1024)); -export const EBYTE = defUnit("EB", "exabyte", mul(PBYTE, 1024)); +export const bit = defUnit("bit", "bit", dimensionless(1, 0, true)); +export const kbit = defUnit("kbit", "kilobit", prefix("k", bit)); +export const Mbit = defUnit("Mbit", "megabit", prefix("M", bit)); +export const Gbit = defUnit("Gbit", "gigabit", prefix("G", bit)); +export const Tbit = defUnit("Tbit", "terabit", prefix("T", bit)); + +// https://en.wikipedia.org/wiki/Byte#Multiple-byte_units + +export const B = defUnit("B", "byte", mul(bit, 8, true)); +export const kB = defUnit("kB", "kilobyte", prefix("k", B)); +export const MB = defUnit("MB", "megabyte", prefix("M", B)); +export const GB = defUnit("GB", "gigabyte", prefix("G", B)); +export const TB = defUnit("TB", "terabyte", prefix("T", B)); +export const PB = defUnit("PB", "petabyte", prefix("P", B)); +export const EB = defUnit("EB", "exabyte", prefix("E", B)); + +export const KiB = defUnit("KiB", "kibibyte", mul(B, 1024)); +export const MiB = defUnit("MiB", "mebibyte", mul(KiB, 1024)); +export const GiB = defUnit("GiB", "gibibyte", mul(MiB, 1024)); +export const TiB = defUnit("TiB", "tebibyte", mul(GiB, 1024)); +export const PiB = defUnit("PiB", "pebibyte", mul(TiB, 1024)); +export const EiB = defUnit("EiB", "exbibyte", mul(PiB, 1024)); diff --git a/packages/units/src/electric.ts b/packages/units/src/electric.ts index d055c8ed2d..abc67b627a 100644 --- a/packages/units/src/electric.ts +++ b/packages/units/src/electric.ts @@ -1,28 +1,29 @@ -import { M2 } from "./area.js"; +import { m2 } from "./area.js"; import { J } from "./energy.js"; -import { H, S } from "./time.js"; +import { h, s } from "./time.js"; import { defUnit, div, mul, prefix, unit } from "./unit.js"; export const A = defUnit("A", "ampere", unit(3, 1, 0, true)); -export const MA = defUnit("mA", "milliampere", prefix("m", A)); -export const MA_H = defUnit("mAh", "milliampere-hour", mul(MA, H)); +export const mA = defUnit("mA", "milliampere", prefix("m", A)); +export const mAh = defUnit("mAh", "milliampere-hour", mul(mA, h)); -export const C = defUnit("C", "coulomb", mul(A, S, true)); +export const C = defUnit("C", "coulomb", mul(A, s, true)); export const V = defUnit("V", "volt", div(J, C, true)); -export const MV = defUnit("mV", "millivolt", prefix("m", V)); -export const KV = defUnit("kV", "kilovolt", prefix("k", V)); +export const mV = defUnit("mV", "millivolt", prefix("m", V)); +export const kV = defUnit("kV", "kilovolt", prefix("k", V)); +export const MV = defUnit("MV", "megavolt", prefix("M", V)); export const F = defUnit("F", "farad", div(C, V, true)); -export const PF = defUnit("pF", "picofarad", prefix("p", F)); +export const pF = defUnit("pF", "picofarad", prefix("p", F)); export const µF = defUnit("µF", "microfarad", prefix("µ", F)); -export const OHM = defUnit("Ω", "ohm", div(V, A, true)); -export const KOHM = defUnit("kΩ", "kiloohm", prefix("k", OHM)); -export const MOHM = defUnit("MΩ", "megaohm", prefix("M", OHM)); -export const GOHM = defUnit("GΩ", "gigaohm", prefix("G", OHM)); +export const Ω = defUnit("Ω", "ohm", div(V, A, true)); +export const kΩ = defUnit("kΩ", "kiloohm", prefix("k", Ω)); +export const MΩ = defUnit("MΩ", "megaohm", prefix("M", Ω)); +export const GΩ = defUnit("GΩ", "gigaohm", prefix("G", Ω)); -export const SIEMENS = defUnit("S", "siemens", div(A, V, true)); -export const WB = defUnit("Wb", "weber", mul(V, S, true)); -export const TESLA = defUnit("T", "tesla", div(WB, M2, true)); -export const HENRY = defUnit("H", "henry", div(WB, A, true)); +export const S = defUnit("S", "siemens", div(A, V, true)); +export const Wb = defUnit("Wb", "weber", mul(V, s, true)); +export const T = defUnit("T", "tesla", div(Wb, m2, true)); +export const H = defUnit("H", "henry", div(Wb, A, true)); diff --git a/packages/units/src/energy.ts b/packages/units/src/energy.ts index b47235991e..00a36eb6ac 100644 --- a/packages/units/src/energy.ts +++ b/packages/units/src/energy.ts @@ -1,10 +1,10 @@ import { N } from "./force.js"; -import { M } from "./length.js"; +import { m } from "./length.js"; import { defUnit, mul, prefix } from "./unit.js"; -export const J = defUnit("J", "joule", mul(N, M, true)); -export const KJ = defUnit("kJ", "kilojoule", prefix("k", J)); +export const J = defUnit("J", "joule", mul(N, m, true)); +export const kJ = defUnit("kJ", "kilojoule", prefix("k", J)); export const MJ = defUnit("MJ", "megajoule", prefix("M", J)); export const GJ = defUnit("GJ", "gigajoule", prefix("G", J)); -export const CAL = defUnit("cal", "calorie", mul(J, 4.184, true)); -export const KCAL = defUnit("kcal", "kilocalorie", prefix("k", CAL)); +export const cal = defUnit("cal", "calorie", mul(J, 4.184, true)); +export const kcal = defUnit("kcal", "kilocalorie", prefix("k", cal)); diff --git a/packages/units/src/force.ts b/packages/units/src/force.ts index 919acf172a..65b6c06737 100644 --- a/packages/units/src/force.ts +++ b/packages/units/src/force.ts @@ -1,5 +1,5 @@ -import { M_S2 } from "./accel.js"; -import { KG } from "./mass.js"; +import { m_s2 } from "./accel.js"; +import { kg } from "./mass.js"; import { defUnit, mul } from "./unit.js"; -export const N = defUnit("N", "newton", mul(KG, M_S2, true)); +export const N = defUnit("N", "newton", mul(kg, m_s2, true)); diff --git a/packages/units/src/frequency.ts b/packages/units/src/frequency.ts index aef97d587f..b35c869864 100644 --- a/packages/units/src/frequency.ts +++ b/packages/units/src/frequency.ts @@ -1,11 +1,11 @@ -import { S } from "./time.js"; +import { s } from "./time.js"; import { defUnit, div, mul, prefix, reciprocal } from "./unit.js"; -export const HZ = defUnit("Hz", "hertz", reciprocal(S, true)); -export const KHZ = defUnit("kHz", "kilohertz", prefix("k", HZ)); -export const MHZ = defUnit("MHz", "megahertz", prefix("M", HZ)); -export const GHZ = defUnit("GHz", "gigahertz", prefix("G", HZ)); -export const THZ = defUnit("THz", "terahertz", prefix("T", HZ)); -export const RPM = defUnit("rpm", "rotation per minute", mul(HZ, 1 / 60)); +export const Hz = defUnit("Hz", "hertz", reciprocal(s, true)); +export const kHz = defUnit("kHz", "kilohertz", prefix("k", Hz)); +export const MHz = defUnit("MHz", "megahertz", prefix("M", Hz)); +export const GHz = defUnit("GHz", "gigahertz", prefix("G", Hz)); +export const THz = defUnit("THz", "terahertz", prefix("T", Hz)); +export const rpm = defUnit("rpm", "rotation per minute", mul(Hz, 1 / 60)); -export const OMEGA = defUnit("ω", "radian per second", div(HZ, 2 * Math.PI)); +export const ω = defUnit("ω", "radian per second", div(Hz, 2 * Math.PI)); diff --git a/packages/units/src/length.ts b/packages/units/src/length.ts index c7135351cf..57231a52e1 100644 --- a/packages/units/src/length.ts +++ b/packages/units/src/length.ts @@ -1,18 +1,18 @@ import { defUnit, mul, prefix, unit } from "./unit.js"; -export const M = defUnit("m", "meter", unit(1, 1, 0, true)); -export const CM = defUnit("cm", "centimeter", prefix("c", M)); -export const MM = defUnit("mm", "millimeter", prefix("m", M)); -export const µM = defUnit("µm", "micrometer", prefix("µ", M)); -export const NM = defUnit("nm", "nanometer", prefix("n", M)); -export const KM = defUnit("km", "kilometer", prefix("k", M)); -export const AU = defUnit("au", "astronomical unit", mul(M, 149597870700)); +export const m = defUnit("m", "meter", unit(1, 1, 0, true)); +export const cm = defUnit("cm", "centimeter", prefix("c", m)); +export const mm = defUnit("mm", "millimeter", prefix("m", m)); +export const µm = defUnit("µm", "micrometer", prefix("µ", m)); +export const nm = defUnit("nm", "nanometer", prefix("n", m)); +export const km = defUnit("km", "kilometer", prefix("k", m)); +export const au = defUnit("au", "astronomical unit", mul(m, 149597870700)); -export const IN = defUnit("in", "inch", mul(M, 0.0254)); -export const FT = defUnit("ft", "foot", mul(IN, 12)); -export const YD = defUnit("yd", "yard", mul(FT, 3)); -export const MI = defUnit("mi", "mile", mul(YD, 1760)); -export const NMI = defUnit("nmi", "nautical mile", mul(M, 1852)); +export const inch = defUnit("in", "inch", mul(m, 0.0254)); +export const ft = defUnit("ft", "foot", mul(inch, 12)); +export const yd = defUnit("yd", "yard", mul(ft, 3)); +export const mi = defUnit("mi", "mile", mul(yd, 1760)); +export const nmi = defUnit("nmi", "nautical mile", mul(m, 1852)); -export const PICA = defUnit("pica", "pica", mul(IN, 1 / 6)); -export const POINT = defUnit("point", "point", mul(IN, 1 / 72)); +export const pica = defUnit("pica", "pica", mul(inch, 1 / 6)); +export const point = defUnit("point", "point", mul(inch, 1 / 72)); diff --git a/packages/units/src/luminous.ts b/packages/units/src/luminous.ts index cc90c84ac2..acd05ffd74 100644 --- a/packages/units/src/luminous.ts +++ b/packages/units/src/luminous.ts @@ -1,8 +1,8 @@ -import { SR } from "./angle.js"; -import { M2 } from "./area.js"; +import { sr } from "./angle.js"; +import { m2 } from "./area.js"; import { defUnit, div, mul, unit } from "./unit.js"; -export const CD = defUnit("cd", "candela", unit(6, 1, 0, true)); +export const cd = defUnit("cd", "candela", unit(6, 1, 0, true)); -export const LM = defUnit("lm", "lumen", mul(CD, SR)); -export const LX = defUnit("lx", "lux", div(LM, M2)); +export const lm = defUnit("lm", "lumen", mul(cd, sr)); +export const lx = defUnit("lx", "lux", div(lm, m2)); diff --git a/packages/units/src/mass.ts b/packages/units/src/mass.ts index cdb77121c0..1eff3e2fb8 100644 --- a/packages/units/src/mass.ts +++ b/packages/units/src/mass.ts @@ -1,14 +1,14 @@ import { defUnit, mul, prefix, unit } from "./unit.js"; -export const G = defUnit("g", "gram", unit(0, 1e-3, 0, true)); -export const KG = defUnit("kg", "kilogram", prefix("k", G)); -export const MG = defUnit("mg", "milligram", prefix("m", G)); -export const µG = defUnit("µg", "microgram", prefix("µ", G)); +export const g = defUnit("g", "gram", unit(0, 1e-3, 0, true)); +export const kg = defUnit("kg", "kilogram", prefix("k", g)); +export const mg = defUnit("mg", "milligram", prefix("m", g)); +export const µg = defUnit("µg", "microgram", prefix("µ", g)); -export const T = defUnit("t", "tonne", prefix("M", G, true)); -export const KT = defUnit("kt", "kilotonne", prefix("k", T)); -export const MT = defUnit("Mt", "megatonne", prefix("M", T)); -export const GT = defUnit("Gt", "gigatonne", prefix("G", T)); +export const t = defUnit("t", "tonne", prefix("M", g, true)); +export const kt = defUnit("kt", "kilotonne", prefix("k", t)); +export const Mt = defUnit("Mt", "megatonne", prefix("M", t)); +export const Gt = defUnit("Gt", "gigatonne", prefix("G", t)); -export const LB = defUnit("lb", "imperial pound", mul(KG, 0.45359237)); -export const ST = defUnit("st", "stone", mul(LB, 14)); +export const lb = defUnit("lb", "imperial pound", mul(kg, 0.45359237)); +export const st = defUnit("st", "stone", mul(lb, 14)); diff --git a/packages/units/src/power.ts b/packages/units/src/power.ts index fb48215f25..6f2626aeec 100644 --- a/packages/units/src/power.ts +++ b/packages/units/src/power.ts @@ -1,13 +1,13 @@ import { J } from "./energy.js"; -import { H, S } from "./time.js"; +import { h, s } from "./time.js"; import { defUnit, div, mul, prefix } from "./unit.js"; -export const W = defUnit("W", "watt", div(J, S, true)); -export const MILLI_W = defUnit("mW", "milliwatt", prefix("m", W)); -export const KW = defUnit("kW", "kilowatt", prefix("k", W)); +export const W = defUnit("W", "watt", div(J, s, true)); +export const mW = defUnit("mW", "milliwatt", prefix("m", W)); +export const kW = defUnit("kW", "kilowatt", prefix("k", W)); export const MW = defUnit("MW", "megawatt", prefix("M", W)); export const GW = defUnit("GW", "gigawatt", prefix("G", W)); export const TW = defUnit("TW", "terawatt", prefix("T", W)); -export const W_H = defUnit("Wh", "watt-hour", mul(W, H, true)); -export const KW_H = defUnit("kWh", "kilowatt-hour", prefix("k", W_H)); +export const Wh = defUnit("Wh", "watt-hour", mul(W, h, true)); +export const kWh = defUnit("kWh", "kilowatt-hour", prefix("k", Wh)); diff --git a/packages/units/src/pressure.ts b/packages/units/src/pressure.ts index eec018ea55..30d49e7c95 100644 --- a/packages/units/src/pressure.ts +++ b/packages/units/src/pressure.ts @@ -1,13 +1,13 @@ -import { M2 } from "./area.js"; +import { m2 } from "./area.js"; import { N } from "./force.js"; import { defUnit, div, mul, prefix } from "./unit.js"; -export const PA = defUnit("Pa", "pascal", div(N, M2, true)); -export const KPA = defUnit("kPa", "kilopascal", prefix("k", PA)); -export const MPA = defUnit("MPa", "megapascal", prefix("M", PA)); -export const GPA = defUnit("GPa", "gigapascal", prefix("G", PA)); +export const Pa = defUnit("Pa", "pascal", div(N, m2, true)); +export const kPa = defUnit("kPa", "kilopascal", prefix("k", Pa)); +export const MPa = defUnit("MPa", "megapascal", prefix("M", Pa)); +export const GPa = defUnit("GPa", "gigapascal", prefix("G", Pa)); -export const AT = defUnit("at", "technical atmosphere", mul(PA, 98066.5)); -export const ATM = defUnit("atm", "atmosphere", mul(PA, 101325)); -export const BAR = defUnit("bar", "bar", mul(PA, 1e5, true)); -export const PSI = defUnit("psi", "pound per square inch", mul(PA, 6894.757)); +export const at = defUnit("at", "technical atmosphere", mul(Pa, 98066.5)); +export const atm = defUnit("atm", "atmosphere", mul(Pa, 101325)); +export const bar = defUnit("bar", "bar", mul(Pa, 1e5, true)); +export const psi = defUnit("psi", "pound per square inch", mul(Pa, 6894.757)); diff --git a/packages/units/src/speed.ts b/packages/units/src/speed.ts index 487ce82382..522c31bb54 100644 --- a/packages/units/src/speed.ts +++ b/packages/units/src/speed.ts @@ -1,9 +1,9 @@ import { defUnit, div } from "./unit.js"; -import { FT, KM, M, MI, NMI } from "./length.js"; -import { H, S } from "./time.js"; +import { ft, km, m, mi, nmi } from "./length.js"; +import { h, s } from "./time.js"; -export const M_S = defUnit("m/s", "meter per second", div(M, S)); -export const KM_H = defUnit("km/h", "kilometer per hour", div(KM, H)); -export const FT_S = defUnit("ft/s", "foot per second", div(FT, S)); -export const MPH = defUnit("mph", "mile per hour", div(MI, H)); -export const KNOT = defUnit("kn", "knot", div(NMI, H)); +export const m_s = defUnit("m/s", "meter per second", div(m, s)); +export const km_h = defUnit("km/h", "kilometer per hour", div(km, h)); +export const ft_s = defUnit("ft/s", "foot per second", div(ft, s)); +export const mph = defUnit("mph", "mile per hour", div(mi, h)); +export const kn = defUnit("kn", "knot", div(nmi, h)); diff --git a/packages/units/src/substance.ts b/packages/units/src/substance.ts index 80fecbda4a..bbbf5f6779 100644 --- a/packages/units/src/substance.ts +++ b/packages/units/src/substance.ts @@ -1,3 +1,3 @@ import { defUnit, unit } from "./unit.js"; -export const MOL = defUnit("mol", "mole", unit(5, 1, 0, true)); +export const mol = defUnit("mol", "mole", unit(5, 1, 0, true)); diff --git a/packages/units/src/temperature.ts b/packages/units/src/temperature.ts index 198963a5a3..1c3e952760 100644 --- a/packages/units/src/temperature.ts +++ b/packages/units/src/temperature.ts @@ -1,8 +1,8 @@ import { defUnit, unit } from "./unit.js"; export const K = defUnit("K", "kelvin", unit(4, 1)); -export const DEG_C = defUnit("℃", "degree celsius", unit(4, 1, 273.15)); -export const DEG_F = defUnit( +export const celsius = defUnit("℃", "degree celsius", unit(4, 1, 273.15)); +export const fahrenheit = defUnit( "℉", "degree fahrenheit", unit(4, 1 / 1.8, 459.67 / 1.8) diff --git a/packages/units/src/time.ts b/packages/units/src/time.ts index 20bd612f06..2a89932a8c 100644 --- a/packages/units/src/time.ts +++ b/packages/units/src/time.ts @@ -1,12 +1,12 @@ import { defUnit, mul, prefix, unit } from "./unit.js"; -export const S = defUnit("s", "second", unit(2, 1, 0, true)); -export const MS = defUnit("ms", "millisecond", prefix("m", S)); -export const µS = defUnit("µs", "microsecond", prefix("µ", S)); -export const NS = defUnit("ns", "nanosecond", prefix("n", S)); -export const MIN = defUnit("min", "minute", mul(S, 60)); -export const H = defUnit("h", "hour", mul(MIN, 60)); -export const DAY = defUnit("day", "day", mul(H, 24)); -export const WEEK = defUnit("week", "week", mul(DAY, 7)); -export const MONTH = defUnit("month", "month", mul(DAY, 30)); -export const YEAR = defUnit("year", "year", mul(DAY, 365.25)); +export const s = defUnit("s", "second", unit(2, 1, 0, true)); +export const ms = defUnit("ms", "millisecond", prefix("m", s)); +export const µs = defUnit("µs", "microsecond", prefix("µ", s)); +export const ns = defUnit("ns", "nanosecond", prefix("n", s)); +export const min = defUnit("min", "minute", mul(s, 60)); +export const h = defUnit("h", "hour", mul(min, 60)); +export const d = defUnit("day", "day", mul(h, 24)); +export const week = defUnit("week", "week", mul(d, 7)); +export const month = defUnit("month", "month", mul(d, 30)); +export const year = defUnit("year", "year", mul(d, 365.25)); diff --git a/packages/units/src/volume.ts b/packages/units/src/volume.ts index b4e4fb7165..4b638aa451 100644 --- a/packages/units/src/volume.ts +++ b/packages/units/src/volume.ts @@ -1,27 +1,23 @@ -import { CM, KM, M, MM } from "./length.js"; +import { cm, km, m, mm } from "./length.js"; import { defUnit, mul, pow, prefix } from "./unit.js"; -export const M3 = defUnit("m3", "cubic meter", pow(M, 3)); -export const MM3 = defUnit("mm3", "cubic millimeter", pow(MM, 3)); -export const CM3 = defUnit("cm3", "cubic centimeter", pow(CM, 3)); -export const KM3 = defUnit("km3", "cubic kilometer", pow(KM, 3)); -export const L = defUnit("l", "liter", mul(M3, 1e-3, true)); -export const CL = defUnit("cl", "centiliter", prefix("c", L)); -export const ML = defUnit("ml", "milliliter", prefix("m", L)); +export const m3 = defUnit("m3", "cubic meter", pow(m, 3)); +export const mm3 = defUnit("mm3", "cubic millimeter", pow(mm, 3)); +export const cm3 = defUnit("cm3", "cubic centimeter", pow(cm, 3)); +export const km3 = defUnit("km3", "cubic kilometer", pow(km, 3)); +export const l = defUnit("l", "liter", mul(m3, 1e-3, true)); +export const cl = defUnit("cl", "centiliter", prefix("c", l)); +export const ml = defUnit("ml", "milliliter", prefix("m", l)); -export const GAL = defUnit("imp gal", "imperial gallon", mul(L, 4.54609)); -export const PT = defUnit("imp pt", "imperial pint", mul(GAL, 1 / 8)); -export const FLOZ = defUnit( - "imp fl oz", - "imperial fluid ounce", - mul(GAL, 1 / 160) -); +export const gal = defUnit("gal", "imperial gallon", mul(l, 4.54609)); +export const pt = defUnit("pt", "imperial pint", mul(gal, 1 / 8)); +export const floz = defUnit("fl oz", "imperial fluid ounce", mul(gal, 1 / 160)); -export const US_GAL = defUnit("us gal", "us gallon", mul(L, 3.785411784)); -export const US_PT = defUnit("us pt", "us pint", mul(US_GAL, 1 / 8)); -export const US_CUP = defUnit("us cup", "us cup", mul(US_GAL, 1 / 16)); -export const US_FLOZ = defUnit( +export const us_gal = defUnit("us gal", "us gallon", mul(l, 3.785411784)); +export const us_pt = defUnit("us pt", "us pint", mul(us_gal, 1 / 8)); +export const us_cup = defUnit("us cup", "us cup", mul(us_gal, 1 / 16)); +export const us_floz = defUnit( "us fl oz", "us fluid ounce", - mul(US_GAL, 1 / 128) + mul(us_gal, 1 / 128) ); diff --git a/packages/units/test/index.ts b/packages/units/test/index.ts index d894436529..b2c3af45d6 100644 --- a/packages/units/test/index.ts +++ b/packages/units/test/index.ts @@ -2,22 +2,22 @@ import { eqDelta } from "@thi.ng/math"; import { group } from "@thi.ng/testament"; import * as assert from "assert"; import { - ARCMIN, - CM, + arcmin, + cm, convert, - DEG, - FT, - GON, - IN, - KM, - M, - MI, - MM, - NM, - RAD, - TURN, + deg, + ft, + gon, + inch, + km, + m, + mi, + mm, + nm, + rad, + turn, Unit, - YD, + yd, } from "../src/index.js"; const PI = Math.PI; @@ -30,21 +30,21 @@ const check = (x: number, src: Unit, y: number, dest: Unit) => { group("units", { angle: () => { - check(1, RAD, 180 / PI, DEG); - check(TAU, RAD, 1, TURN); - check(360, DEG, 400, GON); - check(1 / 60, DEG, 1, ARCMIN); + check(1, rad, 180 / PI, deg); + check(TAU, rad, 1, turn); + check(360, deg, 400, gon); + check(1 / 60, deg, 1, arcmin); }, length: () => { - check(1, M, 1000, MM); - check(1000, MM, 1, M); - check(1, M, 100, CM); - check(1, KM, 1000, M); - check(25.4e6, NM, 1, IN); - check(25.4, MM, 1, IN); - check(12, IN, 1, FT); - check(36, IN, 1, YD); - check(1760 * 36, IN, 1, MI); + check(1, m, 1000, mm); + check(1000, mm, 1, m); + check(1, m, 100, cm); + check(1, km, 1000, m); + check(25.4e6, nm, 1, inch); + check(25.4, mm, 1, inch); + check(12, inch, 1, ft); + check(36, inch, 1, yd); + check(1760 * 36, inch, 1, mi); }, }); diff --git a/packages/units/tpl.readme.md b/packages/units/tpl.readme.md index 976c06d6f7..caf1d1d810 100644 --- a/packages/units/tpl.readme.md +++ b/packages/units/tpl.readme.md @@ -59,232 +59,239 @@ The following units are provided as "builtins", here grouped by dimension: #### Acceleration -| Unit name | JS name | Description | -|-----------|----------|---------------------------| -| `m/s2` | `M_S2` | meter per second squared | -| `ft/s2` | `FT_S2` | foot per second squared | -| `rad/s2` | `RAD_S2` | radian per second squared | -| `g0` | `G0` | standard gravity | +| Unit name | Variable name | Description | +|-----------|---------------|---------------------------| +| `m/s2` | `m_s2` | meter per second squared | +| `ft/s2` | `ft_s2` | foot per second squared | +| `rad/s2` | `rad_s2` | radian per second squared | +| `g0` | `g0` | standard gravity | #### Angle -| Unit name | JS name | Description | -|-----------|----------|-------------| -| `arcmin` | `ARCMIN` | arc minute | -| `arcsec` | `ARCSEC` | arc second | -| `deg` | `DEG` | degree | -| `gon` | `GON` | gradian | -| `rad` | `RAD` | radian | -| `sr` | `SR` | steradian | -| `turn` | `TURN` | turn | +| Unit name | Variable name | Description | +|-----------|---------------|-------------| +| `arcmin` | `arcmin` | arc minute | +| `arcsec` | `arcsec` | arc second | +| `deg` | `deg` | degree | +| `gon` | `gon` | gradian | +| `rad` | `rad` | radian | +| `sr` | `sr` | steradian | +| `turn` | `turn` | turn | #### Area -| Unit name | JS name | Description | -|-----------|---------|-------------------| -| `m2` | `M2` | square meter | -| `cm2` | `CM2` | square centimeter | -| `mm2` | `MM2` | square millimeter | -| `km2` | `KM2` | square kilometer | -| `ha` | `HA` | hectar | -| `ac` | `AC` | acre | -| `sqin` | `SQIN` | square inch | -| `sqft` | `SQFT` | square foot | -| `sqmi` | `SQMI` | square mile | +| Unit name | Variable name | Description | +|-----------|---------------|-------------------| +| `m2` | `m2` | square meter | +| `cm2` | `cm2` | square centimeter | +| `mm2` | `mm2` | square millimeter | +| `km2` | `km2` | square kilometer | +| `ha` | `ha` | hectar | +| `ac` | `ac` | acre | +| `sqin` | `sqin` | square inch | +| `sqft` | `sqft` | square foot | +| `sqmi` | `sqmi` | square mile | #### Data -| Unit name | JS name | Description | -|-----------|---------|-----------------| -| `bit` | `BIT` | bit | -| `kbit` | `KBIT` | kilobit | -| `Mbit` | `MBIT` | megabit | -| `Gbit` | `GBIT` | gigabit | -| `Tbit` | `TBIT` | terabit | -| `B` | `BYTE` | byte (8 bit) | -| `KB` | `KBYTE` | kilobyte (1024) | -| `MB` | `MBYTE` | megabyte (1024) | -| `GB` | `GBYTE` | gigabyte (1024) | -| `TB` | `TBYTE` | terabyte (1024) | -| `PB` | `PBYTE` | petabyte (1024) | -| `EB` | `EBYTE` | exabyte (1024) | +| Unit name | Variable name | Description | +|-----------|---------------|-------------------| +| `bit` | `bit` | bit | +| `kbit` | `kbit` | kilobit | +| `Mbit` | `Mbit` | megabit | +| `Gbit` | `Gbit` | gigabit | +| `Tbit` | `Tbit` | terabit | +| `B` | `B` | byte (8 bit) | +| `kB` | `kB` | kilobyte (metric) | +| `MB` | `MB` | megabyte (metric) | +| `GB` | `GB` | gigabyte (metric) | +| `TB` | `TB` | terabyte (metric) | +| `PB` | `PB` | petabyte (metric) | +| `EB` | `EB` | exabyte (metric) | +| `KiB` | `KiB` | kibibyte (1024) | +| `MiB` | `MiB` | mebibyte (1024) | +| `GiB` | `GiB` | gibibyte (1024) | +| `TiB` | `TiB` | tebibyte (1024) | +| `PiB` | `PiB` | pebibyte (1024) | +| `EiB` | `EiB` | exbibyte (1024) | #### Electric current -| Unit | JS name | Description | -|------|-----------|-------------------| -| A | `A` | ampere | -| mA | `MA` | milliampere | -| mAh | `MA_H` | milliampere-hours | -| C | `C` | coulomb | -| V | `V` | volt | -| mV | `MV` | millivolt | -| kV | `KV` | kilovolt | -| F | `F` | farad | -| pF | `PF` | picofarad | -| µF | `µF` | microfarad | -| Ω | `OHM` | ohm | -| kΩ | `KOHM` | kiloohm | -| MΩ | `MOHM` | megaohm | -| GΩ | `GOHM` | gigaohm | -| S | `SIEMENS` | siemens | -| Wb | `WB` | weber | -| T | `TESLA` | tesla | -| H | `HENRY` | henry | +| Unit | Variable name | Description | +|------|---------------|-------------------| +| A | `A` | ampere | +| mA | `mA` | milliampere | +| mAh | `mAh` | milliampere-hours | +| C | `C` | coulomb | +| V | `V` | volt | +| mV | `mV` | millivolt | +| kV | `kV` | kilovolt | +| MV | `MV` | megavolt | +| F | `F` | farad | +| pF | `pF` | picofarad | +| µF | `µF` | microfarad | +| Ω | `Ω` | ohm | +| kΩ | `kΩ` | kiloohm | +| MΩ | `MΩ` | megaohm | +| GΩ | `GΩ` | gigaohm | +| S | `S` | siemens | +| Wb | `Wb` | weber | +| T | `T` | tesla | +| H | `H` | henry | #### Energy -| Unit | JS name | Description | -|------|---------|-------------| -| J | `J` | joule | -| kJ | `KJ` | kilojoule | -| MJ | `MJ` | megajoule | -| GJ | `GJ` | gigajoule | -| cal | `CAL` | calorie | -| kcal | `KCAL` | kilocalorie | +| Unit | Variable name | Description | +|------|---------------|-------------| +| J | `J` | joule | +| kJ | `kJ` | kilojoule | +| MJ | `MJ` | megajoule | +| GJ | `GJ` | gigajoule | +| cal | `cal` | calorie | +| kcal | `kcal` | kilocalorie | #### Force -| Unit | JS name | Description | -|------|---------|-------------| -| `N` | `N` | newton | +| Unit | Variable name | Description | +|------|---------------|-------------| +| `N` | `N` | newton | #### Frequency -| Unit | JS name | Description | -|-------|---------|---------------------| -| `Hz` | `HZ` | hertz | -| `kHz` | `KHZ` | kilohertz | -| `MHz` | `MHZ` | megahertz | -| `GHz` | `GHZ` | gigahertz | -| `THz` | `THZ` | terahertz | -| `rpm` | `RPM` | rotation per minute | -| `ω` | `OMEGA` | radian per second | +| Unit | Variable name | Description | +|-------|---------------|---------------------| +| `Hz` | `Hz` | hertz | +| `kHz` | `KHz` | kilohertz | +| `MHz` | `MHz` | megahertz | +| `GHz` | `GHz` | gigahertz | +| `THz` | `THz` | terahertz | +| `rpm` | `rpm` | rotation per minute | +| `ω` | `ω` | radian per second | #### Length -| Unit name | JS name | Description | -|-----------|---------|-------------------| -| `m` | `M` | meter | -| `cm` | `CM` | centimeter | -| `mm` | `MM` | millimeter | -| `µm` | `µM` | micrometer | -| `nm` | `NM` | nanometer | -| `km` | `KM` | kilometer | -| `au` | `AU` | astronomical unit | -| `in` | `IN` | inch | -| `ft` | `FT` | foot | -| `yd` | `YD` | yard | -| `mi` | `MI` | mile | -| `nmi` | `NMI` | nautical mile | -| `pica` | `PICA` | pica | -| `point` | `POINT` | point | +| Unit name | Variable name | Description | +|-----------|---------------|-------------------| +| `m` | `m` | meter | +| `cm` | `cm` | centimeter | +| `mm` | `mm` | millimeter | +| `µm` | `µm` | micrometer | +| `nm` | `nm` | nanometer | +| `km` | `km` | kilometer | +| `au` | `au` | astronomical unit | +| `in` | `in` | inch | +| `ft` | `ft` | foot | +| `yd` | `yd` | yard | +| `mi` | `mi` | mile | +| `nmi` | `nmi` | nautical mile | +| `pica` | `pica` | pica | +| `point` | `point` | point | #### Luminous intensity -| Unit | JS name | Description | -|------|---------|-------------| -| `cd` | `CD` | candela | -| `lm` | `LM` | lumen | -| `lx` | `LX` | lux | +| Unit | Variable name | Description | +|------|---------------|-------------| +| `cd` | `cd` | candela | +| `lm` | `lm` | lumen | +| `lx` | `lx` | lux | #### Mass -| Unit name | JS name | Description | -|-----------|---------|----------------| -| `µg` | `µG` | microgram | -| `mg` | `mG` | milligram | -| `g` | `G` | gram | -| `kg` | `KG` | kilogram | -| `t` | `T` | tonne | -| `kt` | `KT` | kilotonne | -| `Mt` | `MT` | megatonne | -| `Gt` | `GT` | gigatonne | -| `lb` | `LB` | imperial pound | -| `st` | `ST` | stone | +| Unit name | Variable name | Description | +|-----------|---------------|----------------| +| `µg` | `µg` | microgram | +| `mg` | `mg` | milligram | +| `g` | `g` | gram | +| `kg` | `kg` | kilogram | +| `t` | `t` | tonne | +| `kt` | `kt` | kilotonne | +| `Mt` | `Mt` | megatonne | +| `Gt` | `Gt` | gigatonne | +| `lb` | `lb` | imperial pound | +| `st` | `st` | stone | #### Power -| Unit name | JS name | Description | -|-----------|---------|---------------| -| `W` | `W` | watt | -| `mW` | `MW` | milliwatt | -| `kW` | `KW` | kilowatt | -| `MW` | `MW` | megawatt | -| `GW` | `GW` | gigawatt | -| `TW` | `TW` | terawatt | -| `Wh` | `WH` | watt-hour | -| `kWh` | `KWH` | kilowatt-hour | +| Unit name | Variable name | Description | +|-----------|---------------|---------------| +| `W` | `W` | watt | +| `mW` | `mW` | milliwatt | +| `kW` | `kW` | kilowatt | +| `MW` | `MW` | megawatt | +| `GW` | `GW` | gigawatt | +| `TW` | `TW` | terawatt | +| `Wh` | `Wh` | watt-hour | +| `kWh` | `kWh` | kilowatt-hour | #### Pressure -| Unit name | JS name | Description | -|-----------|---------|-----------------------| -| `Pa` | `PA` | pascal | -| `kPa` | `KPA` | kilopascal | -| `MPa` | `MPA` | megapascal | -| `GPa` | `GPA` | gigapascal | -| `at` | `AT` | technical atmosphere | -| `atm` | `ATM` | atmosphere | -| `bar` | `BAR` | bar | -| `psi` | `PSI` | pound per square inch | +| Unit name | Variable name | Description | +|-----------|---------------|-----------------------| +| `Pa` | `Pa` | pascal | +| `kPa` | `KPa` | kilopascal | +| `MPa` | `MPa` | megapascal | +| `GPa` | `GPa` | gigapascal | +| `at` | `at` | technical atmosphere | +| `atm` | `atm` | atmosphere | +| `bar` | `bar` | bar | +| `psi` | `psi` | pound per square inch | #### Speed -| Unit | JS name | Description | -|--------|---------|--------------------| -| `m/s` | `M_S` | meter per second | -| `km/h` | `KM_H` | kilometer per hour | -| `mph` | `MPH` | mile per hour | -| `kn` | `KN` | knot | +| Unit | Variable name | Description | +|--------|---------------|--------------------| +| `m/s` | `m_s` | meter per second | +| `km/h` | `km_h` | kilometer per hour | +| `mph` | `mph` | mile per hour | +| `kn` | `kn` | knot | #### Substance -| Unit | JS name | Description | -|-------|---------|-------------| -| `mol` | `MOL` | mole | +| Unit | Variable name | Description | +|-------|---------------|-------------| +| `mol` | `mol` | mole | #### Temperature -| Unit | JS name | Description | -|------|---------|-------------------| -| `K` | `K` | kelvin | -| `℃` | `DEG_C` | degree celsius | -| `℉` | `DEG_F` | degree fahrenheit | +| Unit | Variable name | Description | +|------|---------------|-------------------| +| `K` | `K` | kelvin | +| `℃` | `celsius` | degree celsius | +| `℉` | `fahrenheit` | degree fahrenheit | #### Time -| Unit | JS name | Description | -|-------|---------|--------------------| -| s | `S` | second | -| ms | `MS` | millisecond | -| µs | `µS` | microsecond | -| ns | `NS` | nanosecond | -| min | `MIN` | minute | -| h | `H` | hour | -| day | `DAY` | day | -| week | `WEEK` | week | -| month | `MONTH` | month (30 days) | -| year | `YEAR` | year (365.25 days) | +| Unit | Variable name | Description | +|-------|---------------|--------------------| +| s | `s` | second | +| ms | `ms` | millisecond | +| µs | `µs` | microsecond | +| ns | `ns` | nanosecond | +| min | `min` | minute | +| h | `h` | hour | +| day | `d` | day | +| week | `week` | week | +| month | `month` | month (30 days) | +| year | `year` | year (365.25 days) | #### Volume -| Unit | JS name | Description | -|-------------|-----------|----------------------| -| `m3` | `M3` | cubic meter | -| `mm3` | `MM3` | cubic millimeter | -| `cm3` | `CM3` | cubic centimeter | -| `km3` | `KM3` | cubic kilometer | -| `l` | `L` | liter | -| `cl` | `CL` | centiliter | -| `ml` | `ML` | milliliter | -| `imp gal` | `GAL` | imperial gallon | -| `imp pt` | `PT` | imperial pint | -| `imp fl oz` | `FLOZ` | imperial fluid ounce | -| `us gal` | `US_GAL` | US gallon | -| `us pt` | `US_PT` | US pint | -| `us cup` | `US_CUP` | US cup | -| `us fl oz` | `US_FLOZ` | US fluid ounce | +| Unit | Variable name | Description | +|------------|---------------|----------------------| +| `m3` | `m3` | cubic meter | +| `mm3` | `mm3` | cubic millimeter | +| `cm3` | `cm3` | cubic centimeter | +| `km3` | `km3` | cubic kilometer | +| `l` | `l` | liter | +| `cl` | `cl` | centiliter | +| `ml` | `ml` | milliliter | +| `gal` | `gal` | imperial gallon | +| `pt` | `pt` | imperial pint | +| `fl oz` | `floz` | imperial fluid ounce | +| `us gal` | `us_gal` | US gallon | +| `us pt` | `us_pt` | US pint | +| `us cup` | `us_cup` | US cup | +| `us fl oz` | `us_floz` | US fluid ounce | ### Creating & deriving units