@smartput/rate
v0.2.0
Published
The money kind, rate snapshots, and the live-rate facade.
Maintainers
Readme
@smartput/rate
The money kind, rate snapshots, and the live-rate facade.
Money is not in BUILTIN_KINDS and never will be: it needs an
injected rate table, so it ships here and the caller registers it. snapshot()
builds a dated immutable table; ecb() and custom() are providers;
createLiveEngine() wraps fetch, cache, TTL and one shared in-flight request.
A rate without an asOf is a number pretending to be a fact, so every
snapshot carries one.
Setup
npm add @smartput/rateExample
import { money, snapshot, ecb } from "@smartput/rate";
import { parseAmount, symbolOf } from "@smartput/currency";
JSON.stringify(parseAmount("$12.50")) // "{\"ok\":false,\"code\":\"nan\",\"input\":\"$12.50\"}"
symbolOf("uah") // "₴"
money.id // "money"money is a kind whose ratios are read from a rate snapshot rather
than fixed, so createLiveEngine is what turns "100 usd in eur" into an
answer. ecb is the European Central Bank daily reference feed;
snapshot is the offline shape it fills. Nothing here calls the network until
you hand it a provider.
Entry points
| Import | Contents |
| --- | --- |
| @smartput/rate | The package root. |
| @smartput/rate/locale/<id> | One language's words for this kind. 17 ship: en, uk, de, fr, es, pt, it, nl, zh, ja, ar, ru, pl, tr, hi, ko, id. |
Runtime exports
Type-only exports are erased and do not appear here.
CURRENCIES · createLiveEngine · custom · ecb · money · snapshot
Dependencies
What it costs
Ceilings, not measurements. bun run check-size bundles each entry with
bun build --minify and fails if a row crosses its ceiling or drops more
than 30 % below it — a budget that is only an upper bound reports a vanished
graph as a triumph.
| Import | Minified | Gzipped | | --- | --- | --- | | rate/locale/en (a vocabulary outside the kind packages) | ≤ 36.1 kB | ≤ 14.2 kB |
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/rate.md.
