rttc
Advanced tools
Comparing version 9.6.1 to 9.6.2
@@ -19,2 +19,5 @@ /** | ||
* @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` | ||
* property of `E_INVALID_EXEMPLAR`. | ||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
@@ -34,8 +37,15 @@ * Example usage: | ||
// Used below. | ||
var err; | ||
// Check for obvious bad news. | ||
if (_.isUndefined(supposedExemplar)) { | ||
throw new Error('Invalid exemplar: `undefined` is not a valid RTTC exemplar.'); | ||
err = new Error('Invalid exemplar: `undefined` is not a valid RTTC exemplar.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
} | ||
if (_.isNull(supposedExemplar)) { | ||
throw new Error('Invalid exemplar: `null` is not a valid RTTC exemplar.'); | ||
err = new Error('Invalid exemplar: `null` is not a valid RTTC exemplar.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
} | ||
@@ -46,3 +56,5 @@ | ||
if (_.isNull(val)) { | ||
throw new Error('Invalid exemplar: Nested `null`s are not allowed in an RTTC exemplar.'); | ||
err = new Error('Invalid exemplar: Nested `null`s are not allowed in an RTTC exemplar.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
} | ||
@@ -52,3 +64,5 @@ return val; | ||
if (type === 'array' && val.length > 1) { | ||
throw new Error('Invalid exemplar: Nested `null`s are not allowed in an RTTC exemplar.'); | ||
err = new Error('Invalid exemplar: Nested `null`s are not allowed in an RTTC exemplar.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
} | ||
@@ -62,5 +76,7 @@ return val; | ||
if (!_.isEqual(supposedExemplar, rebuiltExemplar)) { | ||
throw new Error('Invalid exemplar: Only strictly JSON-serializable values can qualify to be RTTC exemplars.'); | ||
err = new Error('Invalid exemplar: Only strictly JSON-serializable values can qualify to be RTTC exemplars.'); | ||
err.code = 'E_INVALID_EXEMPLAR'; | ||
throw err; | ||
} | ||
}; |
{ | ||
"name": "rttc", | ||
"version": "9.6.1", | ||
"version": "9.6.2", | ||
"description": "Runtime type-checking for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
262536
5235