Methods


parseConfig( config, schema ) → {object}

Description
Check a (user) provided config object against a (developer) pre-defined schema object.
Parameters
Name Type Description
config object The actual config object you provide. Property-value pairs describe the config options. Can be recursive.
schema object The schema object the config object must adhere to.
Name Type Description
key object | string Each key describes a config property. Can be object notation or shorthand string notation. See example below.
Returns
Returns the config object checked against the schema object and optionally with default values set.
Examples

Simple usage

parseConfig({
			   aString: "abc",
			   aNumber: 123,
			 }, {
			   aString: {type: "string", required: true},
			   aNumber: "number*"
			   someDefault: {type: "number", default: 456}
			 });
			 

Shorthand notation

{schemaProp: "type:defaultVal*"} //an asterisk at the end denotes a required property
			 

Recursive config

parseConfig({
			   version: "1.2.3",
			   project: {
			     name: "cats",
			     author: "Joe Kerr"
			   }
			 }, {
			   version: "string:0.0.1",
			   project: {
			     name: "string",
			     author: "string:Joe Kerr",
			   }
			 });
			 

Do not process property

{schemaProp: {type: null}}	
Throws
Throws for various errors such as type mismatches or missing required config properties. It is assumed that the function will be called on application start so that a fail fast behaviour is feasible. Plus, unexpected or undefined config variables are likely always exceptions.
Details