Comparing version 9.7.2 to 9.8.0
@@ -63,3 +63,5 @@ /** | ||
// Don't include `minor` property if it's falsy. | ||
if (!err.minor) delete err.minor; | ||
if (!err.minor) { | ||
delete err.minor; | ||
} | ||
@@ -66,0 +68,0 @@ // Expose duplicate-free list of errors as `err.errors` |
@@ -18,6 +18,21 @@ /** | ||
* | ||
* @param {Boolean} prohibitEmptyArrays | ||
* If enabled, if the supposed exemplar contains any empty arrays (`[]`), | ||
* then an error will be thrown (nested or at the top level). Otherwise, | ||
* (and by default) `rttc.validateExemplarStrict()` tolerates the presence | ||
* of `[]`, since most RTTC/machine tooling supports that notation by | ||
* understanding it as `['*']`, purely for backwards compatibility. | ||
* @default true | ||
* | ||
* @throws {Error} If the provided `supposedExemplar` is not a pure RTTC exemplar. | ||
* @property {String} code | ||
* The error intentionally thrown from here always has a `code` | ||
* This error is intentionally thrown, and always has a `code` | ||
* property of `E_INVALID_EXEMPLAR`. | ||
* | ||
* @throws {Error} If the `prohibitEmptyArrays` flag was enabled, and the provided | ||
* `supposedExemplar` contains any empty arrays (nested or at the | ||
* top level). | ||
* @property {String} code | ||
* This error is intentionally thrown, and always has a `code` | ||
* property of `E_DEPRECATED_SYNTAX`. | ||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
@@ -35,3 +50,3 @@ * Example usage: | ||
*/ | ||
module.exports = function validateExemplarStrict (supposedExemplar) { | ||
module.exports = function validateExemplarStrict (supposedExemplar, prohibitEmptyArrays) { | ||
@@ -52,20 +67,38 @@ // Used below. | ||
} | ||
if (prohibitEmptyArrays && _.isEqual(supposedExemplar, [])) { | ||
err = new Error('Invalid exemplar: Empty arrays (`[]`) are not allowed in this RTTC exemplar at any depth. (This error was thrown because `rttc.validateExemplarStrict()` with the `prohibitEmptyArrays` flag enabled. Otherwise, any occurences of `[]` would have been understood as `[\'*\']`.)'); | ||
err.code = 'E_DEPRECATED_SYNTAX'; | ||
throw err; | ||
} | ||
// Check for nested nulls, and ensure serializability while we're at it. | ||
var rebuiltExemplar = rebuild(supposedExemplar, function transformPrimitive (val){ | ||
if (_.isNull(val)) { | ||
err = new Error('Invalid exemplar: Nested `null`s are not allowed in an RTTC exemplar.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
var rebuiltExemplar = rebuild( | ||
supposedExemplar, | ||
function transformPrimitive (val){ | ||
if (_.isNull(val)) { | ||
err = new Error('Invalid exemplar: Nested `null`s are not allowed in an RTTC exemplar.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
} | ||
return val; | ||
}, | ||
function transformDictOrArray(val, type) { | ||
if (type === 'array' && val.length === 0 && prohibitEmptyArrays) { | ||
err = new Error('Invalid exemplar: Empty arrays (`[]`) are not allowed in this RTTC exemplar at any depth. (This error was thrown because `rttc.validateExemplarStrict()` with the `prohibitEmptyArrays` flag enabled. Otherwise, any occurences of `[]` would have been understood as `[\'*\']`.)'); | ||
err.code = 'E_DEPRECATED_SYNTAX'; | ||
throw err; | ||
} | ||
else if (type === 'array' && val.length > 1) { | ||
err = new Error('Invalid exemplar: Multi-item arrays (at any depth) are not allowed in an RTTC exemplar.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
} | ||
else { return val; } | ||
} | ||
return val; | ||
}, function transformDictOrArray(val, type) { | ||
if (type === 'array' && val.length > 1) { | ||
err = new Error('Invalid exemplar: Multi-item arrays (at any depth) are not allowed in an RTTC exemplar.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
} | ||
return val; | ||
}); | ||
); | ||
// Rebuilding the exemplar should have caused it not to change. | ||
@@ -72,0 +105,0 @@ // (if it did, it means it was circular, or that it contained things that |
{ | ||
"name": "rttc", | ||
"version": "9.7.2", | ||
"version": "9.8.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
282171
5542