courtroom

Validation made easy!

Usage no npm install needed!

<script type="module">
  import courtroom from 'https://cdn.skypack.dev/courtroom';
</script>

README

courtroom

Build Status Coverage Status npm version Dependency status Dev Dependency Status Tonic

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:

  1. Clone this repository: git clone https://github.com/Jameskmonger/courtroom.git
  2. Install the NPM modules: npm install
  3. Install the typings: tsd install
  4. Compile the TypeScript - they will automatically be placed into the /build/ folder: gulp
  5. Run the tests: gulp test