UNPKG

@thi.ng/units

Version:

Extensible SI unit creation, conversions, quantities & calculations (incl. ~170 predefined units & constants)

52 lines (51 loc) 1.62 kB
import { defUnit, dimensionless, mul, prefix } from "../unit.js"; const bit = defUnit("bit", "bit", dimensionless(1, 0, true)); const kbit = defUnit("kbit", "kilobit", prefix("k", bit)); const Mbit = defUnit("Mbit", "megabit", prefix("M", bit)); const Gbit = defUnit("Gbit", "gigabit", prefix("G", bit)); const Tbit = defUnit("Tbit", "terabit", prefix("T", bit)); const B = defUnit("B", "byte", mul(bit, 8, true)); const kB = defUnit("kB", "kilobyte", prefix("k", B)); const MB = defUnit("MB", "megabyte", prefix("M", B)); const GB = defUnit("GB", "gigabyte", prefix("G", B)); const TB = defUnit("TB", "terabyte", prefix("T", B)); const PB = defUnit("PB", "petabyte", prefix("P", B)); const EB = defUnit("EB", "exabyte", prefix("E", B)); const Kibit = defUnit("Kibit", "kibibit", mul(bit, 1024)); const Mibit = defUnit("Mibit", "mebibit", mul(Kibit, 1024)); const Gibit = defUnit("Gibit", "gibibit", mul(Mibit, 1024)); const Tibit = defUnit("Tibit", "tebibit", mul(Gibit, 1024)); const Pibit = defUnit("Pibit", "pebibit", mul(Tibit, 1024)); const Eibit = defUnit("Eibit", "exbibit", mul(Pibit, 1024)); const KiB = defUnit("KiB", "kibibyte", mul(B, 1024)); const MiB = defUnit("MiB", "mebibyte", mul(KiB, 1024)); const GiB = defUnit("GiB", "gibibyte", mul(MiB, 1024)); const TiB = defUnit("TiB", "tebibyte", mul(GiB, 1024)); const PiB = defUnit("PiB", "pebibyte", mul(TiB, 1024)); const EiB = defUnit("EiB", "exbibyte", mul(PiB, 1024)); export { B, EB, EiB, Eibit, GB, Gbit, GiB, Gibit, KiB, Kibit, MB, Mbit, MiB, Mibit, PB, PiB, Pibit, TB, Tbit, TiB, Tibit, bit, kB, kbit };