Schema Validation: define a schema, validate the world

SchemaValidation enable you to build a validation by a schema to validate variables and generate reports. This package is open to define Schema Language and Reporter, that means, you can define a schema in different styles you like, and translate the report into different formats as you wish.

With this release, I also published a (by now, the only) schema language : sl-js. I try to design it to use just plain js things to express a schema, which is easy to read, write and reflects the structure of target object clearly.

All the words above mean that you can define a schema like this:

var schema = ['optional', {
    id: 'isNumber',
    name: 'isString',
    role: ['optional', ['oneOf', 'isString', ['in', [1, 2]]]],
    birth: ['optional', ['class', Date]],
    profile: ['optional', 'isObject', {
        nickname: ['optional', 'isString'],
        about: ['optional', 'isString'],
        email: ['optional', '.isEmail', ['.contains:', '@qq.com']]
    }],
    phones: ['each', 'isString'],
    options: ['isObject', [{
        bindPhone: 'isBoolean',
        bindEmail: 'isBoolean'
    }]]
}];

And then, test, validate or check your variables:

var sv = new SchemaValidation(schema);
sv.test(a); // => boolean
sv.validate(a); // => report
sv.check(a); // if fail, throw Match.Error with report

Oh, you can’t run these codes directly because you need to make some installations and setup before that. For more, please see github:

I am looking forward to any idea, suggestion or help from you, for this project, or my english : )