Skip to content
Runtime contracts for TypeScript

Validate at every boundary. Ship with certainty.

Zero-dependency runtime contracts that wrap any function with input and output predicates. Catch violations before they propagate.

contract.ts
import { contract } from "vowwch"

const safeParse = contract(JSON.parse, {
  input: (raw) => typeof raw === "string",
  output: (val) => val !== null,
})

safeParse('{"ok": true}')  // ✓ passes
safeParse(42)              // ✗ input violation

0

dependencies

~900b

gzipped

100%

test coverage

API Surface

Everything you need. Nothing you don't.

Six exports. Full runtime safety. No abstractions to learn.

contract()

Wrap any function with input and output predicates. Violations are caught before they cross module boundaries.

createContractor()

Build a factory with shared defaults. Apply the same mode, guards, and violation handler to every contract in a module.

defineGuard()

Turn any throwing parser into a boolean predicate. Name it, describe it, reuse it across contracts.

batch()

Validate every item in an array with per-element predicates. Invalid items are caught individually, not as a whole.

Three modes

strict throws on violation, warn logs and continues, silent skips all checks. Switch per environment with zero code changes.

Zero dependencies

Single file. No runtime dependencies. Works in Node, Deno, Bun, Cloudflare Workers, and the browser.

Performance

Built for production hot paths.

No allocation per call. No dependency graph. Just predicate checks on the way in and out.

900b

Gzipped bundle

Single file, tree-shakeable

<1ms

Cold start

Zero dependencies to resolve

~0.3μs

Contract overhead

Per-call wrapping cost

44

Tests passing

100% coverage on every export

Start guarding your boundaries.

Install vowwch and add runtime contracts in under a minute.