A function that takes n Rules and composes them into one Rule
Returns composer that returns true if all rules returns true
import { and } from "@csvenke/compose-rules";
// Returns true if number is larger than one
const isLargerThanOne = n => n > 1;
// Returns true if number is less than ten
const isLessThanTen = n => n < 10;
// Returns true if all rules returns true
const isValidValue = and(isLargerThanOne, isLessThanTen);
console.log(isValidValue(11)); // false
console.log(isValidValue(5)); // true
Returns composer that returns true if all rules returns false
import { not } from "@csvenke/compose-rules";
// Returns true if name is John
const isNamedJohn = name => name === "John"
// Returns true if name is Jane
const isNamedJane = name => name === "Jane";
// Returns true if name is not John or Jane
const isValidName = not(isNamedJohn, isNamedJane);
console.log(isValidName("Billy")) // true
console.log(isValidName("John")) // false
console.log(isValidName("Jane")) // false
Returns composer that returns true if some rules returns true
import { or } from "@csvenke/compose-rules";
// Returns true if name is John
const isNamedJohn = name => name === "John"
// Returns true if name is Jane
const isNamedJane = name => name === "Jane";
// Returns true if name is John or Jane
const isValidName = or(isNamedJohn, isNamedJane);
console.log(isValidName("Billy")) // false
console.log(isValidName("John")) // true
console.log(isValidName("Jane")) // true
Returns composer that returns false if all rules returns true
import { nand } from "@csvenke/compose-rules";
// Returns true if number is larger than one
const isLargerThanOne = n => n > 1;
// Returns true if number is less than ten
const isLessThanTen = n => n < 10;
// Returns false if all rules returns true
const isValidValue = nand(isLargerThanOne, isLessThanTen);
console.log(isValidValue(11)); // true
console.log(isValidValue(5)); // false
Returns composer that returns false if some rules returns true
import { nor } from "@csvenke/compose-rules";
// Returns true if name is John
const isNamedJohn = name => name === "John"
// Returns true if name is Jane
const isNamedJane = name => name === "Jane";
// Returns false if name is John or Jane
const isValidName = nor(isNamedJohn, isNamedJane);
console.log(isValidName("Billy")) // true
console.log(isValidName("John")) // false
console.log(isValidName("Jane")) // false
Generated using TypeDoc
A function that takes n arguments and returns true or false
v2.3.1