@thi.ng/units 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,6 +45,10 @@
45
45
  - [Quantities](#quantities)
46
46
  - [Constants](#constants)
47
47
  - [Domain-specific language](#domain-specific-language)
48
+ - [CLI usage](#cli-usage)
49
+ - [Unit calculator](#unit-calculator)
50
+ - [Unit conversion](#unit-conversion)
51
+ - [List units](#list-units)
48
52
  - [Status](#status)
49
53
  - [Installation](#installation)
50
54
  - [Dependencies](#dependencies)
@@ -54,7 +58,7 @@
54
58
 
55
59
  ## About
56
60
 
57
- Extensible SI unit creation, conversions, quantities & calculations (incl. Lisp-like DSL and ~170 predefined units & constants).
61
+ Extensible SI unit creation, conversions, quantities & calculations, CLI calculator (incl. Lisp-like DSL and ~170 predefined units & constants).
58
62
 
59
63
  All unit definitions, quantities & conversions are based on the SI unit system &
60
64
  concepts described here:
@@ -656,6 +660,70 @@ console.log($eval(`(kg (* 200mm 300mm 0.5in glass))`));
656
660
  // 1.905
657
661
  ```
658
662
 
663
+ ## CLI usage
664
+
665
+ Since v1.4.0 a small CLI is included with the following commands:
666
+
667
+ ```bash
668
+ npx @thi.ng/units
669
+
670
+ # █ █ █ │
671
+ # ██ █ │
672
+ # █ █ █ █ █ █ █ █ │ @thi.ng/units v1.4.0
673
+ # █ █ █ █ █ █ █ █ █ │ Unit converter & calculator
674
+ # █ │
675
+ # █ █ │
676
+ #
677
+ # Available commands:
678
+ #
679
+ # calc : Unit calculator (S-expression)
680
+ # convert : Unit conversion (x srcunit destunit)
681
+ # list : List known units (optionally filtered by given pattern)
682
+ ```
683
+
684
+ ### Unit calculator
685
+
686
+ The `calc` command takes a [DSL S-expression](#domain-specific-language) and
687
+ prints the result (the expression should be wrapped in single quotes):
688
+
689
+ ```bash
690
+ # calculate the weight of a A4 sheet of paper with 320 grams per square meter
691
+ npx @thi.ng/units calc '(g (* 320gsm (area din_a4)))'
692
+
693
+ # 19.958399999999997
694
+ ```
695
+
696
+ ### Unit conversion
697
+
698
+ The `convert` command takes a quantity, source unit and destination unit, and
699
+ prints the result:
700
+
701
+ ```bash
702
+ # convert 40 degree celsius to fahrenheit
703
+ npx @thi.ng/units convert 40 celsius fahrenheit
704
+
705
+ # 103.99999999999993
706
+ ```
707
+
708
+ ### List units
709
+
710
+ The `list` command prints out all known units, incl. aliases and full name for
711
+ each unit. THe output can be filtered via optionally given pattern (regexp):
712
+
713
+ ```bash
714
+ # list all units matching `gram`
715
+ npx @thi.ng/units list gram
716
+
717
+ # symbol aliases name
718
+ # ------------------------------------------------------------------------
719
+ # g gram gram
720
+ # g/m2 gsm, gram_per_square_meter gram per square meter
721
+ # kg kilogram kilogram
722
+ # kg/m3 kilogram_per_cubic_meter kilogram per cubic meter
723
+ # mg milligram milligram
724
+ # µg microgram microgram
725
+ ```
726
+
659
727
  ## Status
660
728
 
661
729
  **BETA** - possibly breaking changes forthcoming
@@ -688,15 +756,18 @@ For Node.js REPL:
688
756
  const units = await import("@thi.ng/units");
689
757
  ```
690
758
 
691
- Package sizes (brotli'd, pre-treeshake): ESM: 5.74 KB
759
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.93 KB
692
760
 
693
761
  ## Dependencies
694
762
 
695
763
  - [@thi.ng/api](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/api)
764
+ - [@thi.ng/args](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/args)
696
765
  - [@thi.ng/checks](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/checks)
766
+ - [@thi.ng/compare](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/compare)
697
767
  - [@thi.ng/equiv](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/equiv)
698
768
  - [@thi.ng/errors](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/errors)
699
769
  - [@thi.ng/sexpr](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/sexpr)
770
+ - [@thi.ng/strings](https://codeberg.org/thi.ng/umbrella/src/branch/develop/packages/strings)
700
771
 
701
772
  Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
702
773
 
package/bin/units ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # https://stackoverflow.com/a/246128/294515
4
+ SOURCE="${BASH_SOURCE[0]}"
5
+ while [ -L "$SOURCE" ]; do
6
+ DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
7
+ SOURCE="$(readlink "$SOURCE")"
8
+ [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
9
+ done
10
+ DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
11
+ DIR="$(dirname $DIR)"
12
+
13
+ # prefer using bun
14
+ if [ -x "$(command -v bun)" ]; then
15
+ CMD=bun
16
+ else
17
+ CMD=node
18
+ fi
19
+
20
+ /usr/bin/env $CMD "$DIR/cli.js" "$DIR" "$@"
package/cli.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import "./units/index.js";
2
+ export interface CLIOpts {
3
+ }
4
+ //# sourceMappingURL=cli.d.ts.map
package/cli.js ADDED
@@ -0,0 +1,62 @@
1
+ import { cliApp, THING_HEADER } from "@thi.ng/args";
2
+ import { compareByKey } from "@thi.ng/compare/keys";
3
+ import { defFormat } from "@thi.ng/strings/format";
4
+ import { padRight } from "@thi.ng/strings/pad-right";
5
+ import { $eval } from "./dsl.js";
6
+ import { ALIASES, UNITS } from "./unit.js";
7
+ import "./units/index.js";
8
+ cliApp({
9
+ name: "units",
10
+ start: 3,
11
+ opts: {},
12
+ commands: {
13
+ list: {
14
+ desc: "List known units (optionally filtered by given pattern)",
15
+ opts: {},
16
+ inputs: [0, 1],
17
+ fn: async ({ inputs }) => {
18
+ const re = inputs.length ? new RegExp(inputs[0]) : null;
19
+ const fmt = defFormat([
20
+ padRight(10),
21
+ padRight(32),
22
+ (x) => x
23
+ ]);
24
+ console.log(
25
+ fmt("symbol", "aliases", "name"),
26
+ "\n" + "-".repeat(72)
27
+ );
28
+ for (let [sym, aliases] of Object.entries(ALIASES).sort(
29
+ compareByKey(0)
30
+ )) {
31
+ if (re && !(re.test(UNITS[sym].name) || [...aliases, sym].some((x) => re.test(x))))
32
+ continue;
33
+ console.log(fmt(sym, aliases.join(", "), UNITS[sym].name));
34
+ }
35
+ }
36
+ },
37
+ convert: {
38
+ desc: "Unit conversion (x srcunit destunit)",
39
+ opts: {},
40
+ inputs: 3,
41
+ fn: async ({ inputs }) => {
42
+ console.log($eval(`(${inputs[2]} ${inputs[0]}${inputs[1]})`));
43
+ }
44
+ },
45
+ calc: {
46
+ desc: "Unit calculator (S-expression)",
47
+ opts: {},
48
+ inputs: 1,
49
+ fn: async ({ inputs }) => {
50
+ console.log($eval(inputs[0]));
51
+ }
52
+ }
53
+ },
54
+ ctx: async (ctx) => ctx,
55
+ usage: {
56
+ prefix: THING_HEADER(
57
+ "@thi.ng/units",
58
+ "1.4.0",
59
+ "Unit converter & calculator"
60
+ ) + "\n"
61
+ }
62
+ });
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@thi.ng/units",
3
- "version": "1.3.1",
4
- "description": "Extensible SI unit creation, conversions, quantities & calculations (incl. Lisp-like DSL and ~170 predefined units & constants)",
3
+ "version": "1.4.0",
4
+ "description": "Extensible SI unit creation, conversions, quantities & calculations, CLI calculator (incl. Lisp-like DSL and ~170 predefined units & constants)",
5
5
  "type": "module",
6
6
  "module": "./index.js",
7
7
  "typings": "./index.d.ts",
8
+ "bin": "bin/units",
8
9
  "sideEffects": false,
9
10
  "repository": {
10
11
  "type": "git",
@@ -40,16 +41,19 @@
40
41
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
41
42
  },
42
43
  "dependencies": {
43
- "@thi.ng/api": "^8.12.21",
44
- "@thi.ng/checks": "^3.9.1",
45
- "@thi.ng/equiv": "^2.1.110",
46
- "@thi.ng/errors": "^2.6.10",
47
- "@thi.ng/sexpr": "^1.1.31"
44
+ "@thi.ng/api": "^8.12.22",
45
+ "@thi.ng/args": "^3.2.20",
46
+ "@thi.ng/checks": "^3.9.2",
47
+ "@thi.ng/compare": "^2.5.10",
48
+ "@thi.ng/equiv": "^2.1.111",
49
+ "@thi.ng/errors": "^2.6.11",
50
+ "@thi.ng/sexpr": "^1.1.32",
51
+ "@thi.ng/strings": "^3.12.4"
48
52
  },
49
53
  "devDependencies": {
50
54
  "esbuild": "^0.28.0",
51
- "typedoc": "^0.28.18",
52
- "typescript": "^5.9.3"
55
+ "typedoc": "^0.28.19",
56
+ "typescript": "^6.0.3"
53
57
  },
54
58
  "keywords": [
55
59
  "acceleration",
@@ -59,6 +63,7 @@
59
63
  "bytes",
60
64
  "calculation",
61
65
  "capacitance",
66
+ "cli",
62
67
  "conversion",
63
68
  "current",
64
69
  "dsl",
@@ -106,6 +111,9 @@
106
111
  "./api": {
107
112
  "default": "./api.js"
108
113
  },
114
+ "./cli": {
115
+ "default": "./cli.js"
116
+ },
109
117
  "./constants/densities": {
110
118
  "default": "./constants/densities.js"
111
119
  },
@@ -189,5 +197,5 @@
189
197
  "status": "beta",
190
198
  "year": 2021
191
199
  },
192
- "gitHead": "dcaa4e2beb427e434a68cba1259a9bf9983a569a"
200
+ "gitHead": "983c49325b676db85989505c240b976db73fa8a8"
193
201
  }
package/unit.d.ts CHANGED
@@ -4,6 +4,12 @@ import { type Dimensions, type MaybeUnit, type NamedUnit, type Prefix, type Unit
4
4
  * Cache/registry for all units defined via {@link defUnit}.
5
5
  */
6
6
  export declare const UNITS: Record<string, NamedUnit>;
7
+ /**
8
+ * Cache/registry of all unit symbols defined via {@link defUnit}. The keys of
9
+ * this object are the canonical symbols of each unit. The values are string
10
+ * arrays of known aliases.
11
+ */
12
+ export declare const ALIASES: Record<string, string[]>;
7
13
  /**
8
14
  * Defines a "raw" (anonymous) unit using given dimension(s), scale factor, zero
9
15
  * offset and `coherent` flag indicating if the unit is the coherent one for
@@ -32,19 +38,24 @@ export declare const coherent: (dim: Dimensions | number) => Unit;
32
38
  */
33
39
  export declare const dimensionless: (scale: number, offset?: number, coherent?: boolean) => Unit;
34
40
  /**
35
- * Takes a unit symbol, full unit name and pre-defined {@link Unit} impl and
36
- * registers it in the {@link UNITS} cache for further lookups by symbol name.
41
+ * Takes one or multiple unit symbols, full unit name and pre-defined
42
+ * {@link Unit} impl, then registers unit in the {@link UNITS} cache for further
43
+ * lookups by given symbol names.
37
44
  *
38
45
  * @remarks
46
+ * Since v1.4.0, the unit is also registered under a modified lowercased version
47
+ * of `name`, where all spaces are being replaced by `_`. All registered aliases
48
+ * will be stored in {@link ALIASES}.
49
+ *
39
50
  * By default throws an error if attempting to register a unit with an existing
40
51
  * symbol. If `force` is true, the existing unit will be overwritten.
41
52
  *
42
- * @param sym
53
+ * @param syms
43
54
  * @param name
44
55
  * @param unit
45
56
  * @param force
46
57
  */
47
- export declare const defUnit: (sym: string, name: string, unit: Unit, force?: boolean) => NamedUnit;
58
+ export declare const defUnit: (syms: string | string[], name: string, unit: Unit, force?: boolean) => NamedUnit;
48
59
  /**
49
60
  * Attempts to find a unit by given symbol ID/name. Throws error if unit is
50
61
  * unknown.
package/unit.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  PREFIXES
10
10
  } from "./api.js";
11
11
  const UNITS = {};
12
+ const ALIASES = {};
12
13
  const unit = (dim, scale, offset = 0, coherent2 = false) => ({
13
14
  dim: isNumber(dim) ? __oneHot(dim) : dim,
14
15
  scale,
@@ -17,9 +18,20 @@ const unit = (dim, scale, offset = 0, coherent2 = false) => ({
17
18
  });
18
19
  const coherent = (dim) => unit(dim, 1, 0, true);
19
20
  const dimensionless = (scale, offset = 0, coherent2 = false) => unit(NONE.dim, scale, offset, coherent2);
20
- const defUnit = (sym, name, unit2, force = false) => {
21
- if (UNITS[sym] && !force) illegalArgs(`attempt to override unit: ${sym}`);
22
- return UNITS[sym] = { ...unit2, sym, name };
21
+ const defUnit = (syms, name, unit2, force = false) => {
22
+ const $syms = isArray(syms) ? syms : [syms];
23
+ assert($syms.length > 0, `require at least one unit symbol`);
24
+ const $name = name.toLowerCase().replaceAll(" ", "_");
25
+ if (!$syms.includes($name)) $syms.push($name);
26
+ const canonical = $syms[0];
27
+ ALIASES[canonical] = [];
28
+ for (let sym of $syms) {
29
+ if (UNITS[sym] && !force)
30
+ illegalArgs(`attempt to override unit: ${sym}`);
31
+ UNITS[sym] = { ...unit2, sym, name };
32
+ if (sym !== canonical) ALIASES[canonical].push(sym);
33
+ }
34
+ return UNITS[canonical];
23
35
  };
24
36
  const asUnit = (id) => {
25
37
  for (let i = 0; i < id.length; i++) {
@@ -163,6 +175,7 @@ const __combineQ = (op, a, b) => {
163
175
  );
164
176
  };
165
177
  export {
178
+ ALIASES,
166
179
  Quantity,
167
180
  UNITS,
168
181
  add,
package/units/area.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { cm, ft, inch, km, m, mi, mm } from "./length.js";
2
2
  import { defUnit, mul, pow } from "../unit.js";
3
- const m2 = defUnit("m2", "square meter", pow(m, 2));
4
- const mm2 = defUnit("mm2", "square millimeter", pow(mm, 2));
5
- const cm2 = defUnit("cm2", "square centimeter", pow(cm, 2));
6
- const km2 = defUnit("km2", "square kilometer", pow(km, 2));
3
+ const m2 = defUnit(["m2", "sqm"], "square meter", pow(m, 2));
4
+ const mm2 = defUnit(["mm2", "sqmm"], "square millimeter", pow(mm, 2));
5
+ const cm2 = defUnit(["cm2", "sqcm"], "square centimeter", pow(cm, 2));
6
+ const km2 = defUnit(["km2", "sqkm"], "square kilometer", pow(km, 2));
7
7
  const ha = defUnit("ha", "hectar", mul(m2, 1e4));
8
8
  const ac = defUnit("ac", "acre", mul(m2, 4046.86));
9
9
  const sqin = defUnit("sqin", "square inch", pow(inch, 2));
@@ -1,8 +1,4 @@
1
1
  export declare const g_m2: import("../api.js").NamedUnit;
2
- /**
3
- * Alias for {@link g_m2}
4
- */
5
- export declare const gsm: import("../api.js").NamedUnit;
6
2
  export declare const kg_m3: import("../api.js").NamedUnit;
7
3
  export declare const dpi: import("../api.js").NamedUnit;
8
4
  //# sourceMappingURL=density.d.ts.map
package/units/density.js CHANGED
@@ -3,13 +3,15 @@ import { m2 } from "./area.js";
3
3
  import { inch } from "./length.js";
4
4
  import { g, kg } from "./mass.js";
5
5
  import { m3 } from "./volume.js";
6
- const g_m2 = defUnit("g/m2", "gram per square meter", div(g, m2));
7
- const gsm = defUnit("gsm", "gram per square meter", div(g, m2));
6
+ const g_m2 = defUnit(
7
+ ["g/m2", "gsm"],
8
+ "gram per square meter",
9
+ div(g, m2)
10
+ );
8
11
  const kg_m3 = defUnit("kg/m3", "kilogram per cubic meter", div(kg, m3));
9
12
  const dpi = defUnit("dpi", "dots per inch", reciprocal(inch));
10
13
  export {
11
14
  dpi,
12
15
  g_m2,
13
- gsm,
14
16
  kg_m3
15
17
  };
package/units/electric.js CHANGED
@@ -4,7 +4,7 @@ import { h, s } from "./time.js";
4
4
  import { coherent, defUnit, div, mul, prefix } from "../unit.js";
5
5
  const A = defUnit("A", "ampere", coherent(3));
6
6
  const mA = defUnit("mA", "milliampere", prefix("m", A));
7
- const mAh = defUnit("mAh", "milliampere-hour", mul(mA, h));
7
+ const mAh = defUnit("mAh", "milliampere hour", mul(mA, h));
8
8
  const C = defUnit("C", "coulomb", mul(A, s, true));
9
9
  const V = defUnit("V", "volt", div(J, C, true));
10
10
  const mV = defUnit("mV", "millivolt", prefix("m", V));
package/units/force.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare const N: import("../api.js").NamedUnit;
2
+ export declare const kN: import("../api.js").NamedUnit;
2
3
  //# sourceMappingURL=force.d.ts.map
package/units/force.js CHANGED
@@ -1,7 +1,9 @@
1
+ import { defUnit, mul, prefix } from "../unit.js";
1
2
  import { m_s2 } from "./accel.js";
2
3
  import { kg } from "./mass.js";
3
- import { defUnit, mul } from "../unit.js";
4
4
  const N = defUnit("N", "newton", mul(kg, m_s2, true));
5
+ const kN = defUnit("kN", "kilonewton", prefix("k", N));
5
6
  export {
6
- N
7
+ N,
8
+ kN
7
9
  };
package/units/power.js CHANGED
@@ -7,8 +7,8 @@ const kW = defUnit("kW", "kilowatt", prefix("k", W));
7
7
  const MW = defUnit("MW", "megawatt", prefix("M", W));
8
8
  const GW = defUnit("GW", "gigawatt", prefix("G", W));
9
9
  const TW = defUnit("TW", "terawatt", prefix("T", W));
10
- const Wh = defUnit("Wh", "watt-hour", mul(W, h, true));
11
- const kWh = defUnit("kWh", "kilowatt-hour", prefix("k", Wh));
10
+ const Wh = defUnit("Wh", "watt hour", mul(W, h, true));
11
+ const kWh = defUnit("kWh", "kilowatt hour", prefix("k", Wh));
12
12
  export {
13
13
  GW,
14
14
  MW,
@@ -1,9 +1,9 @@
1
1
  import { coherent, defUnit, unit } from "../unit.js";
2
2
  const K = defUnit("K", "kelvin", coherent(4));
3
- const celsius = defUnit("\u2103", "degree celsius", unit(4, 1, 273.15));
3
+ const celsius = defUnit("\u2103", "celsius", unit(4, 1, 273.15));
4
4
  const fahrenheit = defUnit(
5
5
  "\u2109",
6
- "degree fahrenheit",
6
+ "fahrenheit",
7
7
  unit(4, 1 / 1.8, 459.67 / 1.8)
8
8
  );
9
9
  export {
package/units/time.js CHANGED
@@ -5,10 +5,10 @@ const \u00B5s = defUnit("\xB5s", "microsecond", prefix("\xB5", s));
5
5
  const ns = defUnit("ns", "nanosecond", prefix("n", s));
6
6
  const min = defUnit("min", "minute", mul(s, 60));
7
7
  const h = defUnit("h", "hour", mul(min, 60));
8
- const d = defUnit("day", "day", mul(h, 24));
9
- const week = defUnit("week", "week", mul(d, 7));
10
- const month = defUnit("month", "month", mul(d, 30));
11
- const year = defUnit("year", "year", mul(d, 365.25));
8
+ const d = defUnit("d", "day", mul(h, 24));
9
+ const week = defUnit("w", "week", mul(d, 7));
10
+ const month = defUnit("mo", "month", mul(d, 30));
11
+ const year = defUnit("y", "year", mul(d, 365.25));
12
12
  export {
13
13
  d,
14
14
  h,
package/units/volume.d.ts CHANGED
@@ -2,6 +2,9 @@ export declare const m3: import("../api.js").NamedUnit;
2
2
  export declare const mm3: import("../api.js").NamedUnit;
3
3
  export declare const cm3: import("../api.js").NamedUnit;
4
4
  export declare const km3: import("../api.js").NamedUnit;
5
+ export declare const cuin: import("../api.js").NamedUnit;
6
+ export declare const cuft: import("../api.js").NamedUnit;
7
+ export declare const cumi: import("../api.js").NamedUnit;
5
8
  export declare const l: import("../api.js").NamedUnit;
6
9
  export declare const cl: import("../api.js").NamedUnit;
7
10
  export declare const ml: import("../api.js").NamedUnit;
package/units/volume.js CHANGED
@@ -1,9 +1,12 @@
1
- import { cm, km, m, mm } from "./length.js";
2
1
  import { defUnit, mul, pow, prefix } from "../unit.js";
2
+ import { cm, ft, inch, km, m, mi, mm } from "./length.js";
3
3
  const m3 = defUnit("m3", "cubic meter", pow(m, 3));
4
4
  const mm3 = defUnit("mm3", "cubic millimeter", pow(mm, 3));
5
5
  const cm3 = defUnit("cm3", "cubic centimeter", pow(cm, 3));
6
6
  const km3 = defUnit("km3", "cubic kilometer", pow(km, 3));
7
+ const cuin = defUnit("cuin", "cubic inch", pow(inch, 3));
8
+ const cuft = defUnit("cuft", "cubic foot", pow(ft, 3));
9
+ const cumi = defUnit("cumi", "cubic mile", pow(mi, 3));
7
10
  const l = defUnit("l", "liter", mul(m3, 1e-3, true));
8
11
  const cl = defUnit("cl", "centiliter", prefix("c", l));
9
12
  const ml = defUnit("ml", "milliliter", prefix("m", l));
@@ -11,17 +14,20 @@ const drop = defUnit("drop", "drop", mul(ml, 1 / 20));
11
14
  const gal = defUnit("gal", "imperial gallon", mul(l, 4.54609));
12
15
  const pt = defUnit("pt", "imperial pint", mul(gal, 1 / 8));
13
16
  const floz = defUnit("fl_oz", "imperial fluid ounce", mul(gal, 1 / 160));
14
- const us_gal = defUnit("us_gal", "us gallon", mul(l, 3.785411784));
15
- const us_pt = defUnit("us_pt", "us pint", mul(us_gal, 1 / 8));
16
- const us_cup = defUnit("us_cup", "us cup", mul(us_gal, 1 / 16));
17
+ const us_gal = defUnit("us_gal", "US gallon", mul(l, 3.785411784));
18
+ const us_pt = defUnit("us_pt", "US pint", mul(us_gal, 1 / 8));
19
+ const us_cup = defUnit("us_cup", "US cup", mul(us_gal, 1 / 16));
17
20
  const us_floz = defUnit(
18
21
  "us_fl_oz",
19
- "us fluid ounce",
22
+ "US fluid ounce",
20
23
  mul(us_gal, 1 / 128)
21
24
  );
22
25
  export {
23
26
  cl,
24
27
  cm3,
28
+ cuft,
29
+ cuin,
30
+ cumi,
25
31
  drop,
26
32
  floz,
27
33
  gal,
package/api.d.ts DELETED
@@ -1,101 +0,0 @@
1
- export interface Unit {
2
- /**
3
- * SI base dimension vector ({@link Dimensions})
4
- */
5
- dim: Dimensions;
6
- /**
7
- * Scaling factor relative to the coherent unit
8
- */
9
- scale: number;
10
- /**
11
- * Zero offset value
12
- */
13
- offset: number;
14
- /**
15
- * True, if this unit is coherent.
16
- *
17
- * @remarks
18
- * Reference:
19
- * - https://en.wikipedia.org/wiki/Coherence_(units_of_measurement)
20
- */
21
- coherent: boolean;
22
- }
23
- export interface NamedUnit extends Unit {
24
- /**
25
- * Symbol under which this unit can be looked up with via {@link asUnit} and
26
- * others.
27
- */
28
- sym: string;
29
- /**
30
- * This unit's human readable description/name.
31
- */
32
- name: string;
33
- }
34
- export type MaybeUnit = Unit | string;
35
- /**
36
- * Vector of the 7 basic SI unit dimensions.
37
- *
38
- * @remarks
39
- * In order:
40
- *
41
- * - 0 = mass
42
- * - 1 = length
43
- * - 2 = time
44
- * - 3 = current
45
- * - 4 = temperature
46
- * - 5 = amount of substance
47
- * - 6 = luminous intensity
48
- *
49
- * Note: For dimensionless units, all dimensions are zero.
50
- *
51
- * Reference:
52
- * https://en.wikipedia.org/wiki/SI_base_unit
53
- */
54
- export type Dimensions = [
55
- number,
56
- number,
57
- number,
58
- number,
59
- number,
60
- number,
61
- number
62
- ];
63
- /**
64
- * A known metric prefix.
65
- */
66
- export type Prefix = keyof typeof PREFIXES;
67
- /**
68
- * @remarks
69
- * Reference:
70
- * https://en.wikipedia.org/wiki/Metric_prefix
71
- */
72
- export declare const PREFIXES: {
73
- Q: number;
74
- R: number;
75
- Y: number;
76
- Z: number;
77
- E: number;
78
- P: number;
79
- T: number;
80
- G: number;
81
- M: number;
82
- k: number;
83
- h: number;
84
- d: number;
85
- c: number;
86
- m: number;
87
- µ: number;
88
- n: number;
89
- p: number;
90
- f: number;
91
- a: number;
92
- z: number;
93
- y: number;
94
- r: number;
95
- q: number;
96
- };
97
- /**
98
- * Dimensionless unit preset.
99
- */
100
- export declare const NONE: Unit;
101
- //# sourceMappingURL=api.d.ts.map