@tenets/invariant
v0.6.0
Published
Assertion primitive for impossible internal states, throwing InvariantError — the API surface the tenets ruleset requires (Rule 7.6).
Downloads
496
Readme
@tenets/invariant
invariant(condition, message) for states that are impossible when the code is correct, throwing
InvariantError. Never catch an invariant failure to recover (Rule 2.2) — it marks a programmer
bug, not a recoverable condition.
The tenets ruleset's TypeScript profile fixes these API names (Rule 7.6); your project guide records where the package lives.
Credit
Descends from Facebook's classic invariant (of
fbjs/React lineage) and Alex Reardon's tiny-invariant,
keeping the familiar %s message formatting. This package exists for what production assertion
handling needs beyond a bare throw:
- A typed failure class —
InvariantErrorwith stablecode, optionaldocsUrl, structureddetails, andcause, so crash reporting can group and link failures. - Configurable production stripping —
createInvariant({ mode: 'production' })strips diagnostic messages (which may embed sensitive values) while the check itself always runs; development mode requires messages so diagnostics cannot silently go missing. - Zero dependencies.
