Comparing version 0.5.1 to 0.6.0
@@ -7,2 +7,3 @@ /** | ||
const deprecate = require('depd')('node-convict'); | ||
const cjson = require('cjson'); | ||
@@ -13,3 +14,7 @@ const validator = require('validator'); | ||
var check = validator.check; | ||
function assert(assertion, err_msg) { | ||
if (!assertion) { | ||
throw new Error(err_msg); | ||
} | ||
} | ||
@@ -25,30 +30,31 @@ // format can be a: | ||
int: function(x) { | ||
check(x, 'must be an integer').isInt(); | ||
assert(validator.isInt(x), 'must be an integer'); | ||
}, | ||
nat: function(x) { | ||
check(x, 'must be a positive integer').isInt().min(0); | ||
assert(validator.isInt(x) && x >= 0, 'must be a positive integer'); | ||
}, | ||
port: function(x) { | ||
check(x, 'Ports must be within range 0 - 65535').isInt().min(0).max(65535); | ||
assert(validator.isInt(x) && x >= 0 && x <= 65535, | ||
'Ports must be within range 0 - 65535'); | ||
}, | ||
url: function(x) { | ||
check(x, 'must be a URL').isUrl(); | ||
assert(validator.isURL(x), 'must be a URL'); | ||
}, | ||
email: function(x) { | ||
check(x, 'must be an email address').isEmail(); | ||
assert(validator.isEmail(x), 'must be an email address'); | ||
}, | ||
ipaddress: function(x) { | ||
check(x, 'must be an IP address').isIP(); | ||
assert(validator.isIP(x), 'must be an IP address'); | ||
}, | ||
ipv4: function(x) { | ||
check(x, 'must be an IPv4 address').isIPv4(); | ||
}, | ||
ipv6: function(x) { | ||
check(x, 'must be an IPv6 address').isIPv6(); | ||
}, | ||
ipv4: deprecate.function(function(x) { | ||
assert(validator.isIP(x), 'must be an IP address'); | ||
}, "There is no IPv4 vs IPv6 addresses checking anymore, use \"ipaddress\" instead."), | ||
ipv6: deprecate.function(function(x) { | ||
assert(validator.isIP(x), 'must be an IP address'); | ||
}, "There is no IPv4 vs IPv6 addresses checking anymore, use \"ipaddress\" instead."), | ||
duration: function(x) { | ||
check(x, 'must be a positive integer').isInt().min(0); | ||
assert(validator.isInt(x) && x >= 0, 'must be a positive integer'); | ||
}, | ||
timestamp: function(x) { | ||
check(x, 'must be a positive integer').isInt().min(0); | ||
assert(validator.isInt(x) && x >= 0, 'must be a positive integer'); | ||
} | ||
@@ -81,6 +87,6 @@ }; | ||
// helper for checking that a value is in the list of valid options | ||
// helper for asserting that a value is in the list of valid options | ||
function contains (options, x) { | ||
check(x, 'must be one of the possible values: ' + | ||
JSON.stringify(options)).isIn(options); | ||
assert(validator.isIn(x, options), 'must be one of the possible values: ' + | ||
JSON.stringify(options)); | ||
} | ||
@@ -135,7 +141,7 @@ | ||
// if the format property is a built-in JavaScript constructor, | ||
// check that the value is of that type | ||
// assert that the value is of that type | ||
newFormat = function(x) { | ||
check(Object.prototype.toString.call(x), 'must be of type ' + | ||
format.name) | ||
.equals(Object.prototype.toString.call(new format())); | ||
assert(Object.prototype.toString.call(x) == | ||
Object.prototype.toString.call(new format()), | ||
'must be of type ' + format.name); | ||
}; | ||
@@ -155,3 +161,3 @@ o.format = format.name.toLowerCase(); | ||
} else if (Array.isArray(format)) { | ||
// check that the value is a valid option | ||
// assert that the value is a valid option | ||
newFormat = contains.bind(null, format); | ||
@@ -171,4 +177,4 @@ | ||
newFormat = function(x) { | ||
check(Object.prototype.toString.call(x), | ||
' should be of type ' + type.replace(/\[.* |]/g, '')).equals(type); | ||
assert(Object.prototype.toString.call(x) == type, | ||
' should be of type ' + type.replace(/\[.* |]/g, '')); | ||
}; | ||
@@ -175,0 +181,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "Unruly configuration management for nodejs", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"homepage": "https://github.com/mozilla/node-convict", | ||
@@ -18,12 +18,13 @@ "repository": { | ||
"cjson": "0.3.0", | ||
"depd": "1.0.0", | ||
"moment": "2.8.3", | ||
"optimist": "0.6.1", | ||
"validator": "2.1.0" | ||
"validator": "3.22.1" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "0.3.2", | ||
"jshint": "2.5.6", | ||
"mocha": "2.0.0", | ||
"jshint": "2.5.10", | ||
"mocha": "2.0.1", | ||
"obj_diff": "0.3.0", | ||
"should": "4.1.0" | ||
"should": "4.2.1" | ||
}, | ||
@@ -30,0 +31,0 @@ "jshintConfig": { |
@@ -116,3 +116,3 @@ # node-convict [!['Build status'][travis_image_url]][travis_page_url] | ||
* `email` | ||
* `ipaddress` - IPv4 addresses | ||
* `ipaddress` - IPv4 and IPv6 addresses | ||
* `duration` - miliseconds or a human readable string (e.g. "5 days") | ||
@@ -119,0 +119,0 @@ * `timestamp` - Unix timestamps or date strings recognized by [moment.js](http://momentjs.com/) |
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
23322
398
5
+ Addeddepd@1.0.0
+ Addeddepd@1.0.0(transitive)
+ Addedvalidator@3.22.1(transitive)
- Removedvalidator@2.1.0(transitive)
Updatedvalidator@3.22.1