README
criteria-pattern-core
Library classes for the criteria-pattern package.
Provides the Criterion class which can be extended to satisfy the
interface criterias
expects and the Result class that each Criterion#call
must
return.
Installation
npm install --save criterias-basics
Usage
import Basics from 'criteria-pattern-basics';
This library provides the following Criterion:
Boolean
Casts its value to a boolean.
basics.boolean();
Number
Casts a value to a number.
basics.number();
String
Casts a value to a string.
basics.string();
Array
Splits a string into an array or wraps a value in one. You can pass a character to treat as the sperator.
basics.array(',')
Equals
Checks if the value is equal to the value supplied.
basics.equals(44).satisfy(33); // returns Failure
TypeOf
Checks if the value satisfies the type specified.
basics.typeOf('string').satisfy('a decent string'); // returns 'a decent string';
Match
Test the value against a regular expression.
basics.match(^/[\w]/).satisfy('@'); //returns Failure;
Range
Tests whether the value falls within a specific range.
basics.range(3, 14).satisfy(12); //returns 12;