getto-specification
v1.0.3
Published
predicate factory : caching return value of boolean-returning-function and compose them
Downloads
4
Readme
getto-specification
predicate factory : caching return value of boolean-returning-function and compose them
status: production ready
const specification = require("getto-specification");
const spec = specification.init();
const conditionA = spec.init(() => {
return heavy_condition_checker(); // return Promise
});
const text = "text";
const conditionB = spec.init(() => {
return (text === "text");
});
const compose = spec.all([
conditionA,
spec.not(conditionB),
]);
const result = await compose.matches();
console.log(result);
Table of Contents
Requirements
- Node.js : 10.16.0
Usage
const specification = require("getto-specification");
const spec = specification.init();
const conditionA = spec.init(() => {
return heavy_condition_checker(); // return Promise
});
const text = "text";
const conditionB = spec.init(() => {
return (text === "text");
});
const compose = spec.all([
conditionA,
spec.not(conditionB),
]);
const result = await compose.matches();
console.log(result);
methods
init
const condition = spec.init(() => {
return BOOLEAN;
});
spec.init()
is caching function result
not
const condition = spec.not(another_condition);
return invert condition
all
const condition = spec.all([
conditionA,
conditionB,
]);
all conditions are sync-checking
matches: async () => {
for(let i in conditions) {
const condition = conditions[i];
if (!(await condition.matches())) {
return false;
}
}
return true;
}
Install
npm install --save getto-specification
License
getto-specification is licensed under the MIT license.
Copyright © since 2019 [email protected]