@smartput/shared

v0.1.0

Published

The micro path: one parser, one algebra, one value-class factory.

Readme

@smartput/shared

The micro path: one parser, one algebra, one value-class factory.

No kind, no engine, no dependency at all. Every ratio kind's /validate and /class subpaths are this package plus that kind's table, which is why @smartput/length/validate measures ~1.5 KB rather than ~1.5 KB per kind.

It deliberately does not depend on @smartput/core: importing core would pull decimal.js into a budget the whole design exists to protect. ValidationError is not a subclass of SmartputError for the same reason — same name/code/input shape, no dependency.

Setup

npm add @smartput/shared

Example

import { parse, convert, format, createValueClass } from "@smartput/shared";
import { MASS_UNITS } from "@smartput/mass/units";

parse(MASS_UNITS, "500 g")                                  // {"ok":true,"value":500,"unit":"g","raw":"500"}
convert(MASS_UNITS, "1 kg", "g")                            // 1000
format(MASS_UNITS, parse(MASS_UNITS, "500 g"))              // "500g"
String(createValueClass(MASS_UNITS, "mass").parse("1 kg"))  // "1kg"

Zero dependencies, and not "none for now" — every ratio kind's /validate and /class subpath is this package plus that kind's table, so adding a kind adds a table and not another copy of the algebra.

Entry points

| Import | Contents | | --- | --- | | @smartput/shared | The package root. |

Runtime exports

Type-only exports are erased and do not appear here.

ValidationError · add · as · canonicalOf · coerce · compare · convert · createValueClass · equals · format · fromCanonical · is · negate · offsetOf · parse · patternFor · ratioOf · rebase · scale · sub · toCanonical

Dependencies

None. Not "none for now" — this package is depended on by others precisely because it has none.


Generated by scripts/gen-readmes.ts — run bun run docs:readmes. Every output above was produced by running the line beside it. The full page, with live demos, is docs/packages/shared.md.