typeof-arguments
Advanced tools
Comparing version 3.1.2 to 3.2.0
106
index.js
@@ -1,21 +0,16 @@ | ||
/* global Function */ | ||
const ofType = require('of-type'); | ||
const cliColor = require('cli-color'); | ||
const error = cliColor.red; | ||
const warn = cliColor.blue.bgYellow; | ||
module.exports = function(getArgumentsObject,getExpectedArray,callbackFunction){ | ||
const clb = ofType(callbackFunction,'function'); | ||
validateArguments(getArgumentsObject,getExpectedArray); | ||
for(var i=0;i<getExpectedArray.length;i++){ | ||
if(!ofType(getArgumentsObject[i],getExpectedArray[i])){ | ||
module.exports = function (getArgumentsObject, getExpectedArray, callbackFunction) { | ||
const clb = ofType(callbackFunction, 'function'); | ||
validateArguments(getArgumentsObject, getExpectedArray); | ||
for (var i = 0; i < getExpectedArray.length; i++) { | ||
if (!ofType(getArgumentsObject[i], getExpectedArray[i])) { | ||
var actual = getActualType(getArgumentsObject[i]); | ||
var types = getExpectedTypes(getExpectedArray[i]); | ||
var message = `Invalid argument [${i}]. The [${actual}] ${types.truthness}argument has been passed, while the ${types.message} is expected.`; | ||
if(clb){ | ||
callbackFunction({actual:actual,expected:types.expected,message:message,index:Number(i)}); | ||
if (clb) { | ||
callbackFunction({ actual: actual, expected: types.expected, message: message, index: Number(i) }); | ||
return false; | ||
} else { | ||
var err = new TypeError(message); | ||
throw err; | ||
throw new TypeError(message); | ||
} | ||
@@ -27,77 +22,74 @@ } | ||
function validateArguments(a,o){ | ||
const errActual = warn('typeof-arguments')+': '+error('Invalid module argument. The first argument must be [arguments] Object.'); | ||
const errExpected = warn('typeof-arguments')+': '+error('Invalid module argument. The second argument must be of type [Array].'); | ||
const isActualArguments = ofType(a,'arguments'); | ||
const isExpectedArray = ofType(o,Array); | ||
if(!isActualArguments){ | ||
var err = new TypeError(errActual); | ||
throw err; | ||
function validateArguments(a, o) { | ||
const errActual = 'typeof-arguments: Invalid module argument. The first argument must be [arguments] Object.'; | ||
const errExpected = 'typeof-arguments: Invalid module argument. The second argument must be of type [Array].'; | ||
const isActualArguments = ofType(a, 'arguments'); | ||
const isExpectedArray = ofType(o, Array); | ||
if (!isActualArguments) { | ||
throw new TypeError(errActual); | ||
} | ||
if(!isExpectedArray){ | ||
var err = new TypeError(errExpected); | ||
throw err; | ||
if (!isExpectedArray) { | ||
throw new TypeError(errExpected); | ||
} | ||
} | ||
function getActualType(actualValue){ | ||
if(ofType(actualValue,null)) return "null"; | ||
if(ofType(actualValue,undefined)) return "undefined"; | ||
if(ofType(actualValue,'arguments')) return "arguments"; | ||
function getActualType(actualValue) { | ||
if (ofType(actualValue, null)) return 'null'; | ||
if (ofType(actualValue, undefined)) return 'undefined'; | ||
if (ofType(actualValue, 'arguments')) return 'arguments'; | ||
return actualValue.constructor.name; | ||
} | ||
function getExpectedTypes(expectedType){ | ||
var types = [whenString,whenRegExp,whenObject,whenArray]; | ||
for(var type of types){ | ||
function getExpectedTypes(expectedType) { | ||
var types = [whenString, whenRegExp, whenObject, whenArray]; | ||
for (var type of types) { | ||
var check = type(expectedType); | ||
if(check) return check; | ||
if (check) return check; | ||
} | ||
const err = warn('typeof-arguments')+': '+error(`The expected type is not callable.`); | ||
throw new TypeError(err); | ||
throw new TypeError('typeof-arguments: The expected type is not callable.'); | ||
} | ||
function whenString(stringType){ | ||
if(!ofType(stringType,String)) return null; | ||
function whenString(stringType) { | ||
if (!ofType(stringType, String)) return null; | ||
var msg = `argument of type matching string expression "${stringType}"`; | ||
var truthness = ''; | ||
stringType.split('|').forEach((i)=>{ | ||
if(i.toLowerCase()==='truthy') truthness = '<<falsy>> '; | ||
if(i.toLowerCase()==='falsy') truthness = '<<truthy>> '; | ||
stringType.split('|').forEach((i) => { | ||
if (i.toLowerCase() === 'truthy') truthness = '<<falsy>> '; | ||
if (i.toLowerCase() === 'falsy') truthness = '<<truthy>> '; | ||
}); | ||
return {message:msg,truthness:truthness,expected:stringType}; | ||
return { message: msg, truthness: truthness, expected: stringType }; | ||
} | ||
function whenRegExp(regType){ | ||
if(!ofType(regType,RegExp)) return null; | ||
function whenRegExp(regType) { | ||
if (!ofType(regType, RegExp)) return null; | ||
var msg = `argument of type matching regular expression ${regType}`; | ||
return {message:msg,truthness:truthness(regType),expected:regType.toString()}; | ||
return { message: msg, truthness: truthness(regType), expected: regType.toString() }; | ||
function truthness(regType){ | ||
function truthness(regType) { | ||
var isCaseInsensitive = regType.flags.match(/i/); | ||
var str = regType.toString(); | ||
str = isCaseInsensitive ? str.toLowerCase():str; | ||
if(str.match(/truthy/)) return '<<falsy>> '; | ||
if(str.match(/falsy/)) return '<<truthy>> '; | ||
str = isCaseInsensitive ? str.toLowerCase() : str; | ||
if (str.match(/truthy/)) return '<<falsy>> '; | ||
if (str.match(/falsy/)) return '<<truthy>> '; | ||
return ''; | ||
}; | ||
} | ||
} | ||
function whenObject(objectType){ | ||
if(ofType(objectType,null)) return {message:`argument of type [null]`,truthness:'',expected:'null'}; | ||
if(ofType(objectType,undefined)) return {message:`argument of type [undefined]`,truthness:'',expected:'undefined'}; | ||
if(ofType(objectType,Function)) return {message:`argument of type [${objectType.name}]`,truthness:'',expected:objectType.name}; | ||
function whenObject(objectType) { | ||
if (ofType(objectType, null)) return { message: 'argument of type [null]', truthness: '', expected: 'null' }; | ||
if (ofType(objectType, undefined)) return { message: 'argument of type [undefined]', truthness: '', expected: 'undefined' }; | ||
if (ofType(objectType, Function)) return { message: `argument of type [${objectType.name}]`, truthness: '', expected: objectType.name }; | ||
return null; | ||
} | ||
function whenArray(arrayTypes){ | ||
if(!ofType(arrayTypes,Array)) return null; | ||
function whenArray(arrayTypes) { | ||
if (!ofType(arrayTypes, Array)) return null; | ||
var types = {}; | ||
for(var type of arrayTypes){ | ||
for (var type of arrayTypes) { | ||
var exp = whenObject(type); | ||
if(ofType(exp,null)) return null; | ||
if (ofType(exp, null)) return null; | ||
types[exp.expected] = exp.expected; | ||
} | ||
var expected = Object.getOwnPropertyNames(types).join('|'); | ||
return {message:`argument of type [${expected}]`,truthness:'',expected:expected}; | ||
return { message: `argument of type [${expected}]`, truthness: '', expected: expected }; | ||
} |
{ | ||
"name": "typeof-arguments", | ||
"version": "3.1.2", | ||
"version": "3.2.0", | ||
"description": "Validate the types of arguments passed to the function.", | ||
@@ -20,4 +20,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"cli-color": "^1.2.0", | ||
"of-type": "^2.1.0" | ||
"of-type": "^2.2.0" | ||
}, | ||
@@ -33,5 +32,5 @@ "homepage": "https://github.com/devrafalko/typeof-arguments#readme", | ||
"devDependencies": { | ||
"jasmine": "^2.8.0", | ||
"jasmine": "^3.1.0", | ||
"jasmine-spec-reporter": "^4.2.1" | ||
} | ||
} |
148
readme.md
# Description | ||
`typeof-arguments` is a module that validates arguments' types passed to the enclosing function. | ||
* Any bugs found? Give me to know on dev.rafalko@gmail.com or on [GitHub](https://github.com/devrafalko/typeof-arguments) | ||
* Any bugs found? Give me to know on [GitHub](https://github.com/devrafalko/typeof-arguments) | ||
* Also check out [**`of-type`**](https://www.npmjs.com/package/of-type) package that checks whether the given value is of particular type *(`typeof-arguments` is based on `of-type` package)*. | ||
@@ -11,7 +11,7 @@ * Also check out [**`typeof-properties`**](https://www.npmjs.com/package/typeof-properties) to validate value types of the properties of objects. | ||
```javascript | ||
var argType = require('typeof-arguments'); | ||
const argType = require('typeof-arguments'); | ||
``` | ||
# Usage | ||
### `argType(actual,expected[,callback])` | ||
### `argType(actual, expected[, callback])` | ||
##### `actual` **[Object]** | ||
@@ -25,2 +25,12 @@ * It should always indicate the enclosing function **`arguments`** object | ||
```javascript | ||
test('Paul', 26); | ||
function test(name, age) { | ||
//the name should be of [String] type | ||
//and the age should be of [Number|String|null] type | ||
argType(arguments, ['string', 'number|string|null']); | ||
} | ||
``` | ||
##### The `expected` Types | ||
@@ -32,19 +42,19 @@ There are three ways to check the type of the arguments: | ||
##### [Object:String] | ||
##### 1. [String] expressions | ||
* Possible values: `'null'`, `'undefined'`, or any value equal to `constructor.name`, eg: `'string'`, `'number'`, `'regexp'`, `'array'`, `'object'`, `'boolean'`,`'buffer'`, etc. | ||
* The [String] value is case insensitive: `'String'`, `'string'`, `'StRiNg'` checks if the argument is of type [String]. | ||
* The [String] value can contain multiple allowed types, separated with `|`. eg: `'array|object'` checks if the argument is of type [Array] **`OR`** of type [Object]. | ||
* The [String] value can contain **multiple** allowed types, separated with `|`. eg: `'array|object'` checks if the argument is of type [Array] **`OR`** of type [Object]. | ||
```javascript | ||
test('Paul',26); | ||
test('Paul', 26); | ||
function test(){ | ||
argType(arguments,['string', 'number|string|null']); | ||
function test() { | ||
argType(arguments, ['string', 'number|string|null']); | ||
} | ||
``` | ||
##### [Object:RegExp] | ||
##### 2. [RegExp] expressions | ||
* Possible values: `/null/`, `/undefined/`, or any value matching the `constructor.name`, eg: `/String/`, `/Number/`, `/RegExp/`, `/Array/`, `/Object/`, `/Boolean/`,`/Buffer/`, `/Promise/`, etc. | ||
* For the case insensitivity use `i` flag, eg: `/string/i`, `/regexp/i`, `/typeerror/i` | ||
* For multiple values use regexp `(x|y)` expression, eg: `/String|Number/`, `/TypeError|Error/` | ||
* For **multiple** values use regexp `(x|y)` expression, eg: `/String|Number/`, `/TypeError|Error/` | ||
* Use another regexp features: | ||
@@ -55,18 +65,18 @@ * eg. `/(Type|Range|Syntax)Error/` will match `TypeError`, `RangeError` and `SyntaxError` | ||
```javascript | ||
test('Paul',26); | ||
test('Paul', 26); | ||
function test(){ | ||
argType(arguments,[/string/i, /num|string|null/i]); | ||
function test() { | ||
argType(arguments, [/string/i, /number|string|null/i]); | ||
} | ||
``` | ||
##### [Object:null|undefined|Function|Array] | ||
##### 3. [null|undefined|Function] expressions | ||
* Possible values: `null`, `undefined` or any **constructor** object, eg: `String`, `TypeError`, `Promise`, `Array`, etc. | ||
* For multiple values use array, eg: `[String,Object,Array,null]` | ||
* For **multiple** values use **array**, eg: `[String,Object,Array,null]` | ||
```javascript | ||
test('Paul',26); | ||
test('Paul', 26); | ||
function test(){ | ||
argType(arguments,[String, [Number,String,null]]); | ||
function test() { | ||
argType(arguments, [String, [Number, String, null]]); | ||
} | ||
@@ -77,4 +87,5 @@ ``` | ||
* The value can be: `'arguments'` or `/arguments/`. It returns `true` if the argument is defined as the `arguments` Object | ||
* The value can be : 'instance' or /instance/. It returns `true` for the **instances** of user **classes** or **constructors**. It returns `false` for instances of built-in *(native)* constructors, *eg. for [], "hello world", {}* | ||
* The value can be: `'truthy'` or `/truthy/`. It returns `true` if the argument has the value like: `"abc"`, `true`, `1`, `{}`, `[]`,`function(){}`, etc. | ||
* The value can be: `'falsy'` or `/falsy/`. It returns `true` if the argument has the value like: `""`, `false`, `0`, `null`, `undefined`, etc. | ||
* The value can be: `'falsy'` or `/falsy/`. It returns `true` if the argument has the value like: `""`, `false`, `0`, `null`, `undefined`, `NaN`, etc. | ||
* The value can be: `''` or `'any'` or `/any/` or `[]`, It returns `true` if the argument is of **any type**. | ||
@@ -103,8 +114,8 @@ | ||
```javascript | ||
var argType = require('typeof-arguments'); | ||
const argType = require('typeof-arguments'); | ||
hello("Paul", 26); | ||
hello('Paul', 26); | ||
function hello(name,age){ | ||
argType(arguments,[String,'string|number'],(o)=>{ | ||
function hello(name, age) { | ||
argType(arguments, [String, 'string|number'], (o) => { | ||
console.error(o.message); | ||
@@ -122,9 +133,9 @@ //console.error('Not good! Use ' + o.expected + ' instead of ' + o.actual + ' for argument ' + o.index); | ||
```javascript | ||
var argType = require('typeof-arguments'); | ||
const argType = require('typeof-arguments'); | ||
hello("hello","world!"); | ||
hello('hello', 'world!'); | ||
function hello(paramA,paramB){ | ||
var areValid = argType(arguments,['string','string']); | ||
if(!areValid) return; //stop executing code if at least one argument is of invalid type | ||
function hello(paramA, paramB) { | ||
const valid = argType(arguments, ['string', 'string'], () => { }); | ||
if (!valid) return; //stop executing code if at least one argument is of invalid type | ||
//your code here... | ||
@@ -145,22 +156,22 @@ } | ||
```javascript | ||
var argType = require('typeof-arguments'); | ||
const argType = require('typeof-arguments'); | ||
function test(paramA,paramB,paramC){ | ||
argType(arguments,['number|string','any','null|array']); | ||
function test(paramA, paramB, paramC) { | ||
argType(arguments, ['number|string', 'any', 'null|array']); | ||
} | ||
test("hello", "it's me!", null); | ||
test('hello', 'it\'s me!', null); | ||
//no errors | ||
test(10, 20, [1,2,3]); | ||
test(10, 20, [1, 2, 3]); | ||
//no errors | ||
test(true,20,null); | ||
test(true, 20, null); | ||
//Invalid argument [0]. The [Boolean] argument has been passed, while the argument of type matching string expression "number|string" is expected. | ||
test({name:'Paul'},false,/test/); | ||
test({ name: 'Paul' }, false, /test/); | ||
//Invalid argument [0]. The [Object] argument has been passed, while the argument of type matching string expression "number|string" is expected. | ||
//Invalid argument [2]. The [RegExp] argument has been passed, while the argument of type matching string expression "null|array" is expected. | ||
test(10,20,null,30,40,50,60,70); | ||
test(10, 20, null, 30, 40, 50, 60, 70); | ||
//no errors | ||
@@ -174,6 +185,6 @@ | ||
```javascript | ||
var argType = require('typeof-arguments'); | ||
const argType = require('typeof-arguments'); | ||
function test(paramA,paramB){ | ||
argType(arguments,['truthy|string',/(regexp|falsy)/i]); | ||
function test(paramA, paramB) { | ||
argType(arguments, ['truthy|string', /(regexp|falsy)/i]); | ||
} | ||
@@ -184,16 +195,16 @@ | ||
test('',''); | ||
test('', ''); | ||
//Invalid argument [0]. The [String] <<falsy>> argument has been passed, while the argument of type matching string expression "truthy" is expected. | ||
test(1,0); | ||
test(1, 0); | ||
//no errors | ||
test(0,1); | ||
test(0, 1); | ||
//Invalid argument [0]. The [Number] <<falsy>> argument has been passed, while the argument of type matching string expression "truthy" is expected. | ||
//Invalid argument [1]. The [Number] <<truthy>> argument has been passed, while the argument of type matching regular expression /(regexp|falsy)/i is expected. | ||
test([1,2,3],/test/); | ||
test([1, 2, 3], /test/); | ||
//no errors | ||
test('hello',null); | ||
test('hello', null); | ||
//no errors | ||
@@ -204,6 +215,6 @@ ``` | ||
```javascript | ||
var argType = require('typeof-arguments'); | ||
const argType = require('typeof-arguments'); | ||
function test(paramA,paramB){ | ||
type(arguments,[String,'any','any',Number,/((syntax|type)error)|falsy/i]); | ||
function test(paramA, paramB) { | ||
argType(arguments, [String, 'any', 'any', Number, /((syntax|type)error)|falsy/i]); | ||
} | ||
@@ -214,9 +225,9 @@ | ||
test('Paul',null,false,10); | ||
test('Paul', null, false, 10); | ||
//no errors | ||
test('Paul',null,false,10,new TypeError('error')); | ||
test('Paul', null, false, 10, new TypeError('error')); | ||
//no errors | ||
test('Paul',null,false,10,false); | ||
test('Paul', null, false, 10, false); | ||
//no errors | ||
@@ -227,4 +238,39 @@ | ||
test('Paul',true,true,10,new Error('error')); | ||
test('Paul', true, true, 10, new Error('error')); | ||
//Invalid argument [4]. The [Error] <<truthy>> argument has been passed, while the argument of type matching regular expression /((syntax|type)error)|falsy/i is expected. | ||
``` | ||
### more samples | ||
```javascript | ||
const argType = require('typeof-arguments'); | ||
function test(paramA, paramB) { | ||
argType(arguments, ['instance', 'Name', 'object', 'falsy']); | ||
} | ||
class Name{} | ||
class Age{} | ||
const name = new Name(); | ||
const age = new Age(); | ||
test(); | ||
//Invalid argument [0]. The [undefined] argument has been passed, while the argument of type matching string expression "instance" is expected. | ||
test(name, name, {}, null); | ||
//no errors | ||
test(age, name, {}, NaN); | ||
//no errors | ||
test(age, age, {}, false); | ||
//Invalid argument [1]. The [Age] argument has been passed, while the argument of type matching string expression "Name" is expected. | ||
test({}, name, {}, NaN); | ||
//Invalid argument [0]. The [Object] argument has been passed, while the argument of type matching string expression "instance" is expected. | ||
test(name, {}, {}, 0); | ||
//Invalid argument [1]. The [Object] argument has been passed, while the argument of type matching string expression "Name" is expected. | ||
test(age, name, age, NaN); | ||
//Invalid argument [2]. The [Age] argument has been passed, while the argument of type matching string expression "object" is expected. | ||
``` |
@@ -6,4 +6,4 @@ const Jasmine = require('jasmine'); | ||
jasmine.loadConfig({ | ||
spec_dir: 'tests/', | ||
spec_files: ['tests*.js'] | ||
spec_dir: 'tests/', | ||
spec_files: ['tests*.js'] | ||
}); | ||
@@ -10,0 +10,0 @@ |
@@ -5,4 +5,4 @@ module.exports = [ | ||
expected:{name:10}, | ||
oActual:`null`, | ||
oExpected:`{name:10}`, | ||
oActual:'null', | ||
oExpected:'{name:10}', | ||
message:/Invalid module argument. The first argument must be \[arguments\] Object./ | ||
@@ -13,4 +13,4 @@ }, | ||
expected:undefined, | ||
oActual:`undefined`, | ||
oExpected:`undefined`, | ||
oActual:'undefined', | ||
oExpected:'undefined', | ||
message:/Invalid module argument. The first argument must be \[arguments\] Object./ | ||
@@ -21,4 +21,4 @@ }, | ||
expected:undefined, | ||
oActual:`[1,2,3]`, | ||
oExpected:`undefined`, | ||
oActual:'[1,2,3]', | ||
oExpected:'undefined', | ||
message:/Invalid module argument. The first argument must be \[arguments\] Object./ | ||
@@ -29,4 +29,4 @@ }, | ||
expected:null, | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`null`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'null', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
@@ -37,4 +37,4 @@ }, | ||
expected:null, | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`null`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'null', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
@@ -45,4 +45,4 @@ }, | ||
expected:Number, | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`Number`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'Number', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
@@ -53,4 +53,4 @@ }, | ||
expected:null, | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`null`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'null', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
@@ -61,4 +61,4 @@ }, | ||
expected:(function(){return arguments;})(), | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`(function(){return arguments;})()`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'(function(){return arguments;})()', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
@@ -69,4 +69,4 @@ }, | ||
expected:[false], | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`[false]`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'[false]', | ||
message:/The expected type is not callable./ | ||
@@ -77,4 +77,4 @@ }, | ||
expected:[{}], | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`[{}]`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'[{}]', | ||
message:/The expected type is not callable./ | ||
@@ -85,4 +85,4 @@ }, | ||
expected:[new Date()], | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`[new Date()]`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'[new Date()]', | ||
message:/The expected type is not callable./ | ||
@@ -93,4 +93,4 @@ }, | ||
expected:[[1,2,3]], | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`[[1,2,3]]`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'[[1,2,3]]', | ||
message:/The expected type is not callable./ | ||
@@ -101,4 +101,4 @@ }, | ||
expected:[[Number,null,true]], | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`[[Number,null,true]]`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'[[Number,null,true]]', | ||
message:/The expected type is not callable./ | ||
@@ -109,4 +109,4 @@ }, | ||
expected:[['string']], | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`[['string']]`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:"[['string']]", | ||
message:/The expected type is not callable./ | ||
@@ -117,4 +117,4 @@ }, | ||
expected:[[/string/]], | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`[[/string/]]`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:'[[/string/]]', | ||
message:/The expected type is not callable./ | ||
@@ -125,6 +125,6 @@ }, | ||
expected:[[/string/,'string',null,Number,Boolean]], | ||
oActual:`(function(){return arguments;})()`, | ||
oExpected:`[[/string/,'string',null,Number,Boolean]]`, | ||
oActual:'(function(){return arguments;})()', | ||
oExpected:"[[/string/,'string',null,Number,Boolean]]", | ||
message:/The expected type is not callable./ | ||
} | ||
]; |
@@ -8,3 +8,3 @@ module.exports = [ | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [null] argument has been passed, while the argument of type [String] is expected.` | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type [String] is expected.' | ||
}, | ||
@@ -17,3 +17,3 @@ { | ||
oIndex:1, | ||
oMessage:`Invalid argument [1]. The [String] argument has been passed, while the argument of type [null] is expected.` | ||
oMessage:'Invalid argument [1]. The [String] argument has been passed, while the argument of type [null] is expected.' | ||
}, | ||
@@ -26,3 +26,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [undefined] argument has been passed, while the argument of type [String] is expected.` | ||
oMessage:'Invalid argument [0]. The [undefined] argument has been passed, while the argument of type [String] is expected.' | ||
}, | ||
@@ -35,3 +35,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "string" is expected.` | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "string" is expected.' | ||
}, | ||
@@ -44,3 +44,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "STRING" is expected.` | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "STRING" is expected.' | ||
}, | ||
@@ -53,3 +53,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "number|string|undefined" is expected.` | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "number|string|undefined" is expected.' | ||
}, | ||
@@ -62,3 +62,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching string expression "truthy|undefined" is expected.` | ||
oMessage:'Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching string expression "truthy|undefined" is expected.' | ||
}, | ||
@@ -71,3 +71,3 @@ { | ||
oIndex:2, | ||
oMessage:`Invalid argument [2]. The [String] <<truthy>> argument has been passed, while the argument of type matching string expression "falsy|number" is expected.` | ||
oMessage:'Invalid argument [2]. The [String] <<truthy>> argument has been passed, while the argument of type matching string expression "falsy|number" is expected.' | ||
}, | ||
@@ -80,3 +80,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [null] argument has been passed, while the argument of type matching regular expression /string/i is expected.` | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching regular expression /string/i is expected.' | ||
}, | ||
@@ -89,3 +89,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching regular expression /truthy/ is expected.` | ||
oMessage:'Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching regular expression /truthy/ is expected.' | ||
}, | ||
@@ -98,3 +98,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching regular expression /truthy|undefined|String/ is expected.` | ||
oMessage:'Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching regular expression /truthy|undefined|String/ is expected.' | ||
}, | ||
@@ -107,3 +107,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [String] <<truthy>> argument has been passed, while the argument of type matching regular expression /falsy/ is expected.` | ||
oMessage:'Invalid argument [0]. The [String] <<truthy>> argument has been passed, while the argument of type matching regular expression /falsy/ is expected.' | ||
}, | ||
@@ -116,3 +116,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [Date] <<truthy>> argument has been passed, while the argument of type matching regular expression /falsy|Array/ is expected.` | ||
oMessage:'Invalid argument [0]. The [Date] <<truthy>> argument has been passed, while the argument of type matching regular expression /falsy|Array/ is expected.' | ||
}, | ||
@@ -125,3 +125,3 @@ { | ||
oIndex:2, | ||
oMessage:`Invalid argument [2]. The [Boolean] argument has been passed, while the argument of type matching regular expression /TrUtHy/ is expected.` | ||
oMessage:'Invalid argument [2]. The [Boolean] argument has been passed, while the argument of type matching regular expression /TrUtHy/ is expected.' | ||
}, | ||
@@ -134,3 +134,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [String] argument has been passed, while the argument of type matching regular expression /FaLsY/ is expected.` | ||
oMessage:'Invalid argument [0]. The [String] argument has been passed, while the argument of type matching regular expression /FaLsY/ is expected.' | ||
}, | ||
@@ -143,3 +143,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [String] <<truthy>> argument has been passed, while the argument of type matching regular expression /FaLsY/i is expected.` | ||
oMessage:'Invalid argument [0]. The [String] <<truthy>> argument has been passed, while the argument of type matching regular expression /FaLsY/i is expected.' | ||
}, | ||
@@ -152,3 +152,3 @@ { | ||
oIndex:1, | ||
oMessage:`Invalid argument [1]. The [null] argument has been passed, while the argument of type [String|Array|undefined|Boolean] is expected.` | ||
oMessage:'Invalid argument [1]. The [null] argument has been passed, while the argument of type [String|Array|undefined|Boolean] is expected.' | ||
}, | ||
@@ -161,3 +161,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [Date] argument has been passed, while the argument of type [Array|undefined] is expected.` | ||
oMessage:'Invalid argument [0]. The [Date] argument has been passed, while the argument of type [Array|undefined] is expected.' | ||
}, | ||
@@ -170,3 +170,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [Number] argument has been passed, while the argument of type [Array|undefined] is expected.` | ||
oMessage:'Invalid argument [0]. The [Number] argument has been passed, while the argument of type [Array|undefined] is expected.' | ||
}, | ||
@@ -179,3 +179,3 @@ { | ||
oIndex:0, | ||
oMessage:`Invalid argument [0]. The [String] argument has been passed, while the argument of type [null] is expected.` | ||
oMessage:'Invalid argument [0]. The [String] argument has been passed, while the argument of type [null] is expected.' | ||
}, | ||
@@ -188,4 +188,52 @@ { | ||
oIndex:2, | ||
oMessage:`Invalid argument [2]. The [undefined] argument has been passed, while the argument of type matching regular expression /string/i is expected.` | ||
oMessage:'Invalid argument [2]. The [undefined] argument has been passed, while the argument of type matching regular expression /string/i is expected.' | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))()], | ||
expected:[/name/], | ||
oActual:'Name', | ||
oExpected:'/name/', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [Name] argument has been passed, while the argument of type matching regular expression /name/ is expected.' | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))()], | ||
expected:[Object], | ||
oActual:'Name', | ||
oExpected:'Object', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [Name] argument has been passed, while the argument of type [Object] is expected.' | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))()], | ||
expected:['Age'], | ||
oActual:'Name', | ||
oExpected:'Age', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [Name] argument has been passed, while the argument of type matching string expression "Age" is expected.' | ||
}, | ||
{ | ||
actual:[{}], | ||
expected:['Name'], | ||
oActual:'Object', | ||
oExpected:'Name', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [Object] argument has been passed, while the argument of type matching string expression "Name" is expected.' | ||
}, | ||
{ | ||
actual:[{}], | ||
expected:['instance'], | ||
oActual:'Object', | ||
oExpected:'instance', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [Object] argument has been passed, while the argument of type matching string expression "instance" is expected.' | ||
}, | ||
{ | ||
actual:[{}], | ||
expected:[/instance/], | ||
oActual:'Object', | ||
oExpected:'/instance/', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [Object] argument has been passed, while the argument of type matching regular expression /instance/ is expected.' | ||
} | ||
]; |
@@ -21,3 +21,15 @@ module.exports = [ | ||
expected: ['truthy','any',/any/,Date,/obj/i] | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))(),(()=>new (class Age{}))(), {}], | ||
expected:['instance', /instance/, Object] | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))(),(()=>new (class Age{}))(), {}], | ||
expected:['name', /Age/, Object] | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))(),(()=>new (class Age{}))(), {}], | ||
expected:['any', /truthy/, Object] | ||
} | ||
]; |
@@ -1,2 +0,2 @@ | ||
/* global expect */ | ||
/* global describe, expect, it */ | ||
const path = require('path'); | ||
@@ -10,3 +10,3 @@ const type = require(path.resolve('./index.js')); | ||
it(`type(${scenario[i].oActual},${scenario[i].oExpected}), it should throw TypeError with message "${scenario[i].message}"`,function(){ | ||
let binded = type.bind(this,scenario[i].actual,scenario[i].expected,(o)=>{}); | ||
let binded = type.bind(this,scenario[i].actual,scenario[i].expected,()=>{}); | ||
expect(binded).toThrowError(TypeError,scenario[i].message); | ||
@@ -19,3 +19,3 @@ }); | ||
it(`type(${scenario[i].oActual},${scenario[i].oExpected}), it should throw TypeError with message "${scenario[i].message}"`,function(){ | ||
let binded = type.bind(this,scenario[i].actual,scenario[i].expected,(o)=>{}); | ||
let binded = type.bind(this,scenario[i].actual,scenario[i].expected,()=>{}); | ||
expect(binded).toThrowError(TypeError,scenario[i].message); | ||
@@ -22,0 +22,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
/* global expect */ | ||
/* global jasmine, describe, expect, it */ | ||
const path = require('path'); | ||
@@ -3,0 +3,0 @@ const type = require(path.resolve('./index.js')); |
@@ -1,2 +0,2 @@ | ||
/* global expect */ | ||
/* global jasmine, describe, expect, it */ | ||
const path = require('path'); | ||
@@ -7,3 +7,3 @@ const type = require(path.resolve('./index.js')); | ||
describe('The module function should not throw error and run callback function',function(){ | ||
it(`when the expected array is empty`,function(){ | ||
it('when the expected array is empty',function(){ | ||
let clb = jasmine.createSpy('clb'); | ||
@@ -10,0 +10,0 @@ let binded = test.bind(this,'Paul',22); |
Sorry, the diff of this file is not supported yet
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
34600
1
13
593
263
- Removedcli-color@^1.2.0
- Removedansi-regex@2.1.1(transitive)
- Removedcli-color@1.4.0(transitive)
- Removedd@1.0.2(transitive)
- Removedes5-ext@0.10.64(transitive)
- Removedes6-iterator@2.0.3(transitive)
- Removedes6-symbol@3.1.4(transitive)
- Removedes6-weak-map@2.0.3(transitive)
- Removedesniff@2.0.1(transitive)
- Removedevent-emitter@0.3.5(transitive)
- Removedext@1.7.0(transitive)
- Removedis-promise@2.2.2(transitive)
- Removedlru-queue@0.1.0(transitive)
- Removedmemoizee@0.4.17(transitive)
- Removednext-tick@1.1.0(transitive)
- Removedtimers-ext@0.1.8(transitive)
- Removedtype@2.7.3(transitive)
Updatedof-type@^2.2.0