mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-20 16:14:57 +08:00
35 lines
673 B
TypeScript
35 lines
673 B
TypeScript
|
|
|
|
import ZSchema = require('z-schema');
|
|
|
|
var options: ZSchema.Options = {
|
|
noTypeless: true,
|
|
forceItems: true,
|
|
};
|
|
|
|
var validator: ZSchema.Validator = new ZSchema(options);
|
|
var json: any = {
|
|
foo: 'bar',
|
|
};
|
|
|
|
var schema: any = {
|
|
'type': 'object',
|
|
properties: {
|
|
foo: {
|
|
'type': 'string',
|
|
},
|
|
},
|
|
};
|
|
|
|
validator.validate(json, schema);
|
|
validator.validate(json, schema, function (err: any, valid: boolean) {
|
|
if (err) {
|
|
console.log(err);
|
|
} else {
|
|
console.log('valid = ' + valid);
|
|
}
|
|
});
|
|
|
|
var error: ZSchema.SchemaError = validator.getLastError();
|
|
var errors: ZSchema.SchemaError[] = validator.getLastErrors();
|