package
Asserts your function invariants
npm install annotateGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
annotate allows you to ... guess what ... annotate your functions. For
instance you could document invariants of your function. Or attach a
description to it. It is possible to access this data later on.
This metadata can be used by tools such as annofuzz in order to generate tests. In addition you can access the metadata via REPL.
The usage is quite simple as the following example illustrates:
// let's define some function to annotate
function add(a, b) {
return a + b;
}
// type checkers from annois (https://npmjs.org/package/annois)
var addNumbers = annotate('addNumbers', 'Adds numbers').
on(is.number, is.number, add);
var addStrings = annotate('addStrings', 'Adds strings').
on(is.string, is.string, add);
// you can assert invariants too
var addPositive = annotate('addPositive', 'Adds positive').
on(isPositive, isPositive, add).
satisfies(isPositive); // postcondition
// it is possible to chain guards
The annotate function will create a new function that contains the metadata as
properties _name, _doc, _preconditions and _postconditions. In case
some pre- or postcondition doesn't pass it won't return and gives a warning
instead.
annotate.js and suite.jsannotate is available under MIT. See LICENSE for more details.