Skip to content

Commit

Permalink
feat(units): add/update units, aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 14, 2023
1 parent c7dda99 commit 850e604
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/units/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ 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));
Expand All @@ -16,6 +14,15 @@ 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));

// https://en.wikipedia.org/wiki/Byte#Multiple-byte_units

export const Kibit = defUnit("Kibit", "kibibit", mul(bit, 1024));
export const Mibit = defUnit("Mibit", "mebibit", mul(Kibit, 1024));
export const Gibit = defUnit("Gibit", "gibibit", mul(Mibit, 1024));
export const Tibit = defUnit("Tibit", "tebibit", mul(Gibit, 1024));
export const Pibit = defUnit("Pibit", "pebibit", mul(Tibit, 1024));
export const Eibit = defUnit("Eibit", "exbibit", mul(Pibit, 1024));

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));
Expand Down
6 changes: 6 additions & 0 deletions packages/units/src/electric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export const kΩ = defUnit("kΩ", "kiloohm", prefix("k", Ω));
export const = defUnit("MΩ", "megaohm", prefix("M", Ω));
export const = defUnit("GΩ", "gigaohm", prefix("G", Ω));

// latin aliases
export const ohm = Ω;
export const kohm = ;
export const Mohm = ;
export const Gohm = ;

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));
Expand Down
1 change: 1 addition & 0 deletions packages/units/src/frequency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export const THz = defUnit("THz", "terahertz", prefix("T", Hz));
export const rpm = defUnit("rpm", "rotation per minute", mul(Hz, 1 / 60));

export const ω = defUnit("ω", "radian per second", div(Hz, 2 * Math.PI));
export const omega = ω;
1 change: 1 addition & 0 deletions packages/units/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from "./frequency.js";
export * from "./length.js";
export * from "./luminous.js";
export * from "./mass.js";
export * from "./parts.js";
export * from "./power.js";
export * from "./pressure.js";
export * from "./speed.js";
Expand Down
9 changes: 8 additions & 1 deletion packages/units/src/length.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { coherent, defUnit, mul, prefix } from "./unit.js";

export const m = defUnit("m", "meter", coherent(1));
export const km = defUnit("km", "kilometer", prefix("k", m));
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 angstrom = defUnit("Å", "angstrom", mul(m, 1e-10));

export const au = defUnit("au", "astronomical unit", mul(m, 149597870700));
export const ly = defUnit("ly", "light year", mul(m, 9.4607304725808e15));
export const pc = defUnit("pc", "parsec", mul(au, (180 * 60 * 60) / Math.PI));

export const inch = defUnit("in", "inch", mul(m, 0.0254));
export const mil = defUnit("mil", "mil", mul(inch, 1e-3));
export const thou = mil;

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));
Expand Down
9 changes: 9 additions & 0 deletions packages/units/src/parts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defUnit, dimensionless } from "./unit.js";

export const percent = defUnit("%", "percent", dimensionless(1e-2));
export const permille = defUnit("‰", "permille", dimensionless(1e-3));
export const permyriad = defUnit("‱", "permyriad", dimensionless(1e-4));
export const pcm = defUnit("pcm", "part per cent mille", dimensionless(1e-5));
export const ppm = defUnit("ppm", "part per million", dimensionless(1e-6));
export const ppb = defUnit("ppb", "part per billion", dimensionless(1e-9));
export const ppt = defUnit("ppt", "part per trillion", dimensionless(1e-12));

0 comments on commit 850e604

Please sign in to comment.