Comparing version 0.2.1 to 0.2.2
@@ -49,3 +49,3 @@ /* | ||
var coerceTypes = {}; | ||
var converters = {}; | ||
@@ -243,4 +243,4 @@ function validate (instance, schema, errors) { | ||
if (typeof v === 'string') { | ||
if (coerceTypes.hasOwnProperty(format)) { | ||
return coerceTypes[format](v); | ||
if (converters.hasOwnProperty(format)) { | ||
return converters[format](v); | ||
} | ||
@@ -385,5 +385,10 @@ switch (format) { | ||
// Add a type with a validatino function | ||
// A coerce function is optional | ||
convict.addType = function(name, validator, coerce) { | ||
if (typeof validator !== 'function') { | ||
// A converter function is optional | ||
convict.addFormat = function(name, validate, coerce) { | ||
if (typeof name === 'object') { | ||
name = name.name; | ||
validate = name.validate; | ||
coerce = name.coerce; | ||
} | ||
if (typeof validate !== 'function') { | ||
throw new Error('Validation function for ' + name + ' must be a function.'); | ||
@@ -394,9 +399,9 @@ } | ||
} | ||
types[name] = validator; | ||
if (coerce) coerceTypes[name] = coerce; | ||
types[name] = validate; | ||
if (coerce) converters[name] = coerce; | ||
}; | ||
convict.addTypes = function(newTypes) { | ||
Object.keys(newTypes).forEach(function(type) { | ||
convict.addType(type, newTypes[type].validate, newTypes[type].coerce); | ||
convict.addFormats = function(formats) { | ||
Object.keys(formats).forEach(function(type) { | ||
convict.addFormat(type, formats[type].validate, formats[type].coerce); | ||
}); | ||
@@ -403,0 +408,0 @@ }; |
@@ -5,3 +5,3 @@ { | ||
"description": "Unruly configuration management for nodejs", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/lloyd/node-convict", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -9,3 +9,3 @@ const should = require('should'); | ||
it('should parse a config specification', function() { | ||
convict.addTypes({ | ||
convict.addFormats({ | ||
prime: { | ||
@@ -12,0 +12,0 @@ validate: function(val) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46323
1267