Package Exports
- @csvenke/compose-rules
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@csvenke/compose-rules) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@csvenke/compose-rules
Simple helper functions for writing composable business rules
Install
Using yarn
yarn add @csvenke/compose-rulesUsing npm
npm install --save @csvenke/compose-rulesUsage
Try it out online with replit
import { and } from "@csvenke/compose-rules";
const isNumber = n => typeof n === "number";
const isLargerThanOne = n => n > 1;
const isLessThanTen = n => n < 10;
const isValidValue = and(isNumber, isLargerThanOne, isLessThanTen);
console.log(isValidValue(4)); // true
console.log(isValidValue(14)); // falseAPI
and
Returns a rule function that returns true if all rules are true.
Example
import { and } from "@csvenke/compose-rules";
const isLargerThanOne = n => n > 1;
const isLessThanTen = n => n < 10;
const hasValidValue = and(isLargerThanOne, isLessThanTen);
console.log(hasValidValue(11)); // false
console.log(hasValidValue(5)); // trueor
Returns a rule function that returns true if some rules are true.
Example
import { or } from "@csvenke/compose-rules";
const isNamedJohn = name => name === "John";
const isNamedJane = name => name === "Jane";
const hasValidName = or(isNamedJohn, isNamedJane);
console.log(hasValidName("Bill")); // false
console.log(hasValidName("Jane")); // truenot
Returns a rule function that returns true if all rules are false.
Example
import { not } from "@csvenke/compose-rules";
const isNamedJohn = name => name === "John";
const isNamedJane = name => name === "Jane";
const hasValidName = not(isNamedJohn, isNamedJane);
console.log(hasValidName("Bill")); // true
console.log(hasValidName("Jane")); // false
console.log(hasValidName("John")); // falseDevelopment
Installing dependencies
yarn installBuilding project
yarn buildRunning tests
yarn testContributing
In lieu of a formal styleguide, take care to maintain the existing coding style.