@rusintez/schema
v1.1.1
Published
Schema utils
Downloads
3
Readme
Schema utils
Installation
$ npm install @rusintez/schema --save
Example
// import
const Schema = require('@rusintez/schema');
// initialize
const { v } = new Schema();
// create a schema
const User = v().object().keys({
username: v().string().required()
});
// validate
User.validate({ foo: 'bar' }) // throws: username is not a string
// build
const user = new User({ username: 'baz' }); // user === { username: 'baz' }
// describe
User.describe() // { schema: { object: true, keys: { username: { string: true, required: true } } }, types: {} }
Usage
Build
const schema = v().default(42);
const value = new schema(); // 42
Validate
Describe
Reference
Plug-ins
Built-ins
Author
Vladimir Popov [email protected]
License
ISC