@smartput/tempo
v0.2.0
Published
Beats per minute, and its bridge to duration.
Maintainers
Readme
@smartput/tempo
Beats per minute, and its bridge to duration.
Canonical in beats per minute — two units, the second-smallest table in the repo.
Three doors, one table. The kind descriptor is for the
engine, /validate is free functions over JS numbers, /class is an
immutable value class — and all three read the same UnitTable, so a unit
added once is added everywhere. See Validating without the
engine.
Setup
npm add @smartput/tempoExample
import { parseTempo, asTempo, formatTempo } from "@smartput/tempo/validate";
import { Tempo } from "@smartput/tempo/class";
parseTempo("120 bpm") // {"ok":true,"value":120,"unit":"bpm","raw":"120"}
asTempo("120 bpm", "hz") // {"ok":true,"value":2,"unit":"hz","raw":"2"}
formatTempo(parseTempo("120 bpm")) // "120bpm"
String(Tempo.parse("120 bpm")) // "120bpm"
// …and the same table through the engine:
engine.evaluate("120 bpm in hz").formatted // "2 hertz"
engine.evaluate("2 hz in bpm").formatted // "120 bpm"parse and as never throw — they answer { ok: true, … } or
{ ok: false, code, input }. The value class throws on bad input and
Tempo.tryParse does not. All three read the one UnitTable below.
Entry points
| Import | Contents |
| --- | --- |
| @smartput/tempo | The package root. |
| @smartput/tempo/units | The UnitTable: ratios and aliases, with no engine and no Decimal. |
| @smartput/tempo/validate | Free functions over JS numbers. Ok \| Err, never a throw. |
| @smartput/tempo/class | The immutable value class. |
| @smartput/tempo/locale/<id> | One language's words for this kind. 17 ship: en, de, fr, es, pt, it, nl, zh, ja, ar, ru, pl, tr, hi, ko, id, uk. |
Units
Read from the table itself, not typed out — a unit added to
the source appears here on the next bun run docs:packages. Ratios are decimal
strings, which is what lets the engine widen them to Decimal without a float
in between.
TEMPO_UNITS
| Unit | Ratio to bpm | Aliases |
| --- | --- | --- |
| bpm | 1 | bpm |
| hz | 60 | hz hertz |
Runtime exports
Type-only exports are erased and do not appear here.
TEMPO_UNITS · tempo
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 | | --- | --- | --- | | tempo/validate parseTempo only | ≤ 1.1 kB | ≤ 650 B | | tempo/class | ≤ 4.5 kB | ≤ 1.8 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/tempo.md.
