Types Validator
A value type validator. Validates the types in an object against a schema, exposing them through an accessor.
Usage
npm install --save types-validator
var types_validator = ; var raw_config = ipaddress: '127.0.0.1' port: 8080 mongo: user: 'db-user' pass: 'db-pass' ; var schema = 'ipaddress': String 'port': Number 'mongo.user': String 'mongo.pass': String; // validate config against schema// NOTE: this will throw an exception if the raw config doesn't match the schemavar config = ; // returned object exposes an accessor for getting config values,// which validates the requested key against the schema at runtimevar port = config; // returns 8080 // nested keys are retrieved using dot notationvar mongo_user = config; // it is not necessary to add every nested key path to the schema,// only the key paths that will be retrieved by your application through// the accessor (config.get())// For exmaple, if we wanted to only validate the 'mongo' config was an object,// and retrieve the full object, we could use this schema instead: var schema = 'ipaddress': String 'port': Number 'mongo': Object;// and retrieve the mongo config (as an object) using:var mongo_config = config; // NOTE: the following will throw an exception as the key has not beed added to the schemavar use_ssl = config; // the schema and the raw config are available on the returned object if neededconfigraw; // ==> raw_configconfigschema; // ==> schema
For further examples and usage (and exceptions), see test/*.js