Tiny code contract programming utility for Deno.
Use codeContract
function to bind the contract.
import { codeContract } from "./code-contracts.ts";
const func = (lhs: number, rhs: number) => (lhs + rhs);
const contracted = codeContract(func, {
pre: (lhs: number, rhs: number) => 0 < lhs && 0 < rhs,
post: (result: number) => (result < 100),
});
contracted(10, 20); // OK
contracted(99, 1); // NG(throw Error)
Return contracted function.
fn
- target functioncontract
- contract functions containerpre
- pre condition functionpost
- post condition functioninvariant
- invariant condition function
Disable contract check.
Enable contract check.
MIT