1.0.3 • Published 4 years ago

getto-specification v1.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

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 shun@getto.systems

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago