T0007 — @callis/ucum package

Part of the roadmap. Phase 1 · wave 3 · size L.

Goal

Full UCUM unit conversion as an opt-in package with no runtime dependencies. The UnitSystem interface it implements, and the split between core and this package, are described in T0006 design notes.

Scope

  • packages/ucum (@callis/ucum), exporting a UnitSystem implementation named ucum.
  • The unchanged UCUM essence file, ucum-essence.xml from a pinned commit of ucum-org/ucum, with its checksum. A script (packages/ucum/scripts/) embeds the file byte for byte as a string module; the package reads it when it is first imported and resolves prefixes, base units and units to exact magnitudes and dimension vectors in memory (data decision).
  • A UCUM expression parser covering prefixes, atoms, exponents, . and /, {annotations} (ignored for conversion), 10*n and 10^n.
  • Conversion and dimension analysis, canonical multiply/divide, and the special units Cel and [degF]. Other special units are reported as not convertible.
  • @callis/core exports Decimal, MAX_DECIMAL_DIGITS, the UnitSystem types and minimalUnitSystem, which the package needs to implement and extend the unit system. Calendar keywords keep the rules of the minimal unit system.
  • License check (owner condition, ADR-0007): confirm that redistributing the UCUM data under the UCUM license next to MIT code is allowed. Document the result in the package README and include the required notice.

Design notes

UCUM data and license

The UCUM license (Version 1.1) allows reproducing and distributing the Work, but not modifying it or creating derivative works (section 3a), and asks for a copyright notice, a reference to the license and its disclaimer when the Work is distributed whole (section 3b). Neither the license nor the upstream issues about it (ucum-org/ucum#253, #260) grant permission for tables generated from the file, so the planned generator was dropped before any generated data was committed.

Owner decision (2026-11-05): ship the full ucum-essence.xml unchanged and parse it at startup. In the package:

  • data/ucum-essence.xml and UCUM-LICENSE.md are byte for byte the upstream files; data/source.json pins the commit and their SHA-256 checksums.
  • src/essence/ucum-essence-xml.ts holds the same text as one string, generated by scripts/embed-essence.ts under the UCUM notice, so the package needs no file system, DOM or network access. The bundle keeps it as a separate file, dist/essence/ucum-essence-xml.js.
  • The MIT-licensed code reads that string once, on first import, and keeps the resolved tables in memory only. No generated subset, converted table or altered definition is stored or distributed.
  • LICENSE.md (MIT for the code, the UCUM notice for the data), SOURCE.md and UCUM-LICENSE.md ship in the package. Tests check the checksums and the byte identity of the embedded string; check:package checks the packed tarball, including the bundled string.

The cost, measured on Node.js 24.18 on an Apple M2 (pnpm --filter @callis/ucum measure, 30 runs; see the package README): 16.7 kB minified and gzipped (4.9 kB code, 11.8 kB UCUM text), 22.7 kB gzipped as built (budget 24 kB), and a median of 9.7 ms to import the package in a fresh process, after @callis/core (9.3–10.0 ms across runs).

Interpretations

The unit algebra, arbitrary and special units, calendar keywords against other UCUM time units, and UCUM's §9 exponents are recorded in spec notes.

Acceptance criteria

  • 1 'kg' = 1000 'g', 1 'cm' < 1 'm', 12 'cm2' / 3 'cm' = 4.0 'cm', 1 'mg/dL' converts to 'g/L', and 100 'Cel' > 50 '[degF]'.
  • Unknown or invalid units return undefined instead of throwing.
  • No runtime dependency; the gzip size is reported in the PR.
  • The conformance groups testQuantity and testQuantityUnitComparison pass once T0010 is merged.
  • The license check is documented and the UCUM notice is included. @callis/ucum is not published (T0025) until this is done.