Introspectable contracts programming for JavaScript
Last updated 4 years ago by jonnor .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install agree 
SYNC missed versions from official npm registry.

Build Status

Agree: Contract programming for JavaScript

Agree is a library for implementing Contract Programming / Design by contract in JavaScript, including preconditions, postconditions and class invariants.

It is inspired by projects like, but requires no build steps, no non-standard language features, and is introspectable.


Experimental as of November 2016.

  • Functions, method and class invariants work
  • Support for asyncronous functions using Promise (ES6/A+ compatible)
  • Contracts can be reusable, and used to define interfaces (having multiple implementations)
  • Some proof-of-concept documentation and testing tools exists
  • Library has not been used in any real applications yet

TODO 0.1 "minimally useful"

  • Lock down the core contracts API
  • Add more tests for core functionality
  • Do use-case exploration of a browser/frontend example
  • Remove CoffeeScript as run-time dependency
  • Setup build automated tests for browser
  • Stabilize and document the testing and documentation tools


  • Add support for more types of invariants, including on properties

For details see TODO/FIXME/XXX/MAYBE comments in the code.


Add Agree to your project using NPM

npm install --save agree
npm install --save-dev agree-tools


MIT, see


HTTP server

See the tests under ./spec/ for full reference.


agree-tools uses the introspection features of Agree to provide support for testing and documentation, driven by the contracts/code.


  • No special dependencies, works anywhere (browser, node.js, etc), usable as library
  • That contracts are used is completely transparent to consuming code
  • Can start using contracts stepwise, starting with just some functions/methods
  • JavaScript-friendly fluent API (even if written with CoffeeScript)
  • Preconditions can, and are encouraged to, be used for input validation


  • HTTP REST apis: specifying behavior, validating request, consistent error handling
  • NoFlo components: verifying data on inports, specifying component behavior
  • Interfaces: multiple implementations of same interface fully described


Functions, classes and instances built with Agree know their associated contracts. This allows to query the code about its properties, to generate documentation, test-cases and aid in debugging of failures.

Agree is partially related other work by author on introspectable programming, including Finito (finite state machines) and NoFlo/MicroFlo (dataflow).

Current Tags

  • 0.0.8                                ...           latest (4 years ago)

5 Versions

  • 0.0.8                                ...           4 years ago
  • 0.0.7                                ...           4 years ago
  • 0.0.6                                ...           4 years ago
  • 0.0.4                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (2)
Dev Dependencies (13)
Dependents (1)

Copyright 2014 - 2016 © |