courtroom
v0.7.1-1.1
Published
Validation made easy!
Downloads
5
Readme
courtroom
Validation-tastic :no_entry:
Install
$ npm install courtroom
Usage
const Courtroom = require('courtroom');
const c = new Courtroom();
let issues;
c.trial('password').laws.minLength(10);
issues = c.judge({password: 'hunter2'});
judge()
returns an array containing issues:
[{
property: 'password',
law: 'minLength',
value: 'hunter2',
details: { minimum: 10 }
}]
You can try this example on Tonic.
Laws
is(string)
Property must exactly match given string
not(string)
Property may take any value other than given string
contains(string)
Property must contain the given string
maxLength(number)
Property length must be less than given number
minLength(number)
Property length must be greater than given number
matches(RegExp)
Property matches a given regular expression
must(Function)
The function must return true for the property to be valid.
Contribute
Setup :wrench:
- Clone this repository:
git clone https://github.com/Jameskmonger/courtroom.git
- Install the NPM modules:
npm install
- Install the typings:
tsd install
- Compile the TypeScript - they will automatically be placed into the /build/ folder:
gulp
- Run the tests:
gulp test