This commit is contained in:
Nicolas Dextraze
2017-02-25 14:12:13 -08:00
parent 34e928c440
commit 158ca2d0a7
6 changed files with 2343 additions and 7 deletions

View File

@ -22,9 +22,10 @@ module.exports.isArrayOf = function(expectedType, value, name) {
throw new TypeError([name, " should be an array of ", expectedType.name, "."].join(""));
};
module.exports.isTypeOf = function(expectedType, value, name) {
module.exports.isTypeOf = function(expectedType, value, name, nullAllowed) {
if (nullAllowed && value === null) return;
if (!(value instanceof expectedType))
throw new TypeError([name, " should be of type '", expectedType.name, "'."].join(""));
throw new TypeError([name, " should be of type '", expectedType.name, "'", nullAllowed ? " or null": "", "."].join(""));
};
module.exports.positive = function(value, name) {