Skip to content

Tiny code contract programming utility for Deno

License

Notifications You must be signed in to change notification settings

DBC-Works/code-contract-deno

Repository files navigation

Code contract for Deno

Tiny code contract programming utility for Deno.

Usage

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)

functions

codeContract

Return contracted function.

  • fn - target function
  • contract - contract functions container
    • pre - pre condition function
    • post - post condition function
    • invariant - invariant condition function

disableContractCheck

Disable contract check.

enableContractCheck

Enable contract check.

CHANGELOG

CHANGELOG

License

MIT

About

Tiny code contract programming utility for Deno

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published