CommonJS Utils is a collection of general purpose CommonJS-compliant modules. These modules can be used on Narwhal, Node, and other CommonJS platforms. The modules include:
- json-schema.js – This is a JSON Schema validator module. It can be used to validate data structures using JSON schema definitions. For example:
var validate = require("json-schema").validate; var data = {name: "Test"}; var schema = { properties: { name: {type: "string"}, age: {type: "number"} } }; var validation = validate(data, schema); validation.valid -> false validation.errors -> indicates that age was not provided data.age = 30; var validation = validate(data, schema); validation.valid -> trueThis module also supports using standard native constructors as type definitions. The schema above could be written
more briefly:var schema = { properties: { name: String, age: Number } };
