Comparing version 8.1.7 to 9.0.0
@@ -26,4 +26,3 @@ /** | ||
// Jump into recursive validation | ||
var result = validateRecursive(expected, actual, errors, true); | ||
// (the true => `ensureSerializable` -- i.e. ensure the thing is JSON-serializable) | ||
var result = validateRecursive(expected, actual, errors, []); | ||
@@ -30,0 +29,0 @@ // Strip out "E_NOT_STRICTLY_VALID" errors- they are ok if we're just coercing. |
@@ -32,4 +32,4 @@ /** | ||
hash += err.expected; | ||
if (err.keyName) { | ||
hash += err.keyName; | ||
if (err.hops) { | ||
hash += err.hops.join('.'); | ||
} | ||
@@ -36,0 +36,0 @@ return hash; |
@@ -19,8 +19,7 @@ /** | ||
* @param {Array} errors [errors encountered along the way are pushed here] | ||
* @param {Boolean} ensureSerializable [no longer used] | ||
* @param {Object} meta [used in error messages] | ||
* @param {Boolean} strict | ||
* @param {Array} hops [used in error messages] | ||
* @param {Boolean} strict [if set, validation will be strict] | ||
* @return {===} coerced value | ||
*/ | ||
module.exports = function _validateRecursive (expected, actual, errors, ensureSerializable, meta, strict){ | ||
module.exports = function _validateRecursive (expected, actual, errors, hops, strict){ | ||
@@ -116,9 +115,7 @@ // Look up expected type from `types` object using `expected`. | ||
} | ||
if (meta && meta.keyName) { | ||
msg = 'For key `'+meta.keyName+'`: ' + msg; | ||
if (hops.length > 0) { | ||
msg = '@ `'+hops.join('.')+'`: ' + msg; | ||
} | ||
var err = new Error(msg); | ||
if (meta && meta.keyName) { | ||
err.keyName = meta.keyName; | ||
} | ||
err.hops = hops; | ||
err.actual = actual; | ||
@@ -153,3 +150,3 @@ err.expected = expected; | ||
// But also push an error | ||
// But also push an `E_NOT_EVEN_CLOSE` error | ||
errors.push((function (){ | ||
@@ -165,9 +162,7 @@ var msg = ''; | ||
msg += ' Attempted to coerce the specified value to match, but it wasn\'t similar enough to the expected value.'; | ||
if (meta && meta.keyName) { | ||
msg = 'For key `'+meta.keyName+'`: ' + msg; | ||
if (hops.length > 0) { | ||
msg = '@ `'+hops.join('.')+'`: ' + msg; | ||
} | ||
var err = new Error(msg); | ||
if (meta && meta.keyName) { | ||
err.keyName = meta.keyName; | ||
} | ||
err.hops = hops; | ||
err.actual = actual; | ||
@@ -186,2 +181,3 @@ err.expected = expected; | ||
if (isExpectingAnything) { | ||
// Note that, in this case, we return a mutable reference. | ||
return coercedValue; | ||
@@ -205,3 +201,3 @@ } | ||
var arrayItemTpl = expected[0]; | ||
return _.reduce(coercedValue, function (memo, coercedVal){ | ||
return _.reduce(coercedValue, function (memo, coercedVal, i){ | ||
@@ -212,3 +208,3 @@ // Never consider `undefined` a real array item. Because things cannot be and also not be. | ||
} | ||
memo.push(_validateRecursive(arrayItemTpl, coercedVal, errors, ensureSerializable, undefined, strict)); | ||
memo.push(_validateRecursive(arrayItemTpl, coercedVal, errors, hops.concat(i), strict)); | ||
return memo; | ||
@@ -226,4 +222,3 @@ }, []); | ||
return _.reduce(expected, function (memo, expectedVal, expectedKey) { | ||
var keyName = (meta && meta.keyName ? (meta.keyName + '.') : '') + expectedKey; | ||
memo[expectedKey] = _validateRecursive(expected[expectedKey], coercedValue[expectedKey], errors, ensureSerializable, {keyName: keyName}, strict); | ||
memo[expectedKey] = _validateRecursive(expected[expectedKey], coercedValue[expectedKey], errors, hops.concat(expectedKey), strict); | ||
return memo; | ||
@@ -230,0 +225,0 @@ }, {}); |
@@ -23,5 +23,4 @@ /** | ||
var errors = []; | ||
var result = validateRecursive(expected, actual, errors, true, undefined, true); | ||
// (first `true` => `ensureSerializable` -- i.e. ensure the thing is JSON-serializable, if possible) | ||
// (second `true` => `strict` -- i.e. don't ignore minor type errors) | ||
var result = validateRecursive(expected, actual, errors, [], true); | ||
// ( `true` => `strict` -- i.e. don't ignore minor type errors) | ||
@@ -28,0 +27,0 @@ // If there are still errors, coallesce the remaining list of errors into a single |
@@ -27,5 +27,4 @@ /** | ||
var errors = []; | ||
var result = validateRecursive(expected, actual, errors, true, undefined, false); | ||
// (the `true` => `ensureSerializable` -- i.e. ensure the thing is JSON-serializable, if possible) | ||
// (the `false` => `strict` -- i.e. ignore minor type errors) | ||
var result = validateRecursive(expected, actual, errors, [], false); | ||
// ( `false` => `strict` -- i.e. ignore minor type errors) | ||
@@ -32,0 +31,0 @@ // If there are still errors, coallesce the remaining list of errors into a single |
{ | ||
"name": "rttc", | ||
"version": "8.1.7", | ||
"version": "9.0.0", | ||
"description": "Runtime type-checking for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
213730
4559