Lightweight schemas for everywhere, whenever.
The flexible lightweight testing library.
It allows for quick simple validations as well as complex nested validation.
Collections, objects and more are supported out of the box and it can be easily extended!
npm install the
var the = ;var schema = objectusername: length5 30password:phoneNumbers:;var doc =username: 'Hello'password: 'World'phoneNumbers:'123''555-555-5555';schema; // Throw an error unless doc matches the schema.
The above schema defines the following constraints:
"name": "ValidationError""message": "Validation Failed""errors":// The key is the full path of the error. In this case, the first phone number.'phoneNumbers.0':// Array of errors for this path.// The name of the failed validator.type: 'phone'// The value that was at the path (that failed).value: '123'
npm testto run tests.
Please feel free to recommend more default tests and/or submit a PR!