typeof-arguments
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -1,1 +0,1 @@ | ||
var typeofArguments=function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){__webpack_require__.o(exports,name)||Object.defineProperty(exports,name,{enumerable:!0,get:getter})},__webpack_require__.r=function(exports){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(exports,"__esModule",{value:!0})},__webpack_require__.t=function(value,mode){if(1&mode&&(value=__webpack_require__(value)),8&mode)return value;if(4&mode&&"object"==typeof value&&value&&value.__esModule)return value;var ns=Object.create(null);if(__webpack_require__.r(ns),Object.defineProperty(ns,"default",{enumerable:!0,value:value}),2&mode&&"string"!=typeof value)for(var key in value)__webpack_require__.d(ns,key,function(key){return value[key]}.bind(null,key));return ns},__webpack_require__.n=function(module){var getter=module&&module.__esModule?function(){return module.default}:function(){return module};return __webpack_require__.d(getter,"a",getter),getter},__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=1)}([function(module,exports,__webpack_require__){(function(global){module.exports=function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){__webpack_require__.o(exports,name)||Object.defineProperty(exports,name,{enumerable:!0,get:getter})},__webpack_require__.r=function(exports){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(exports,"__esModule",{value:!0})},__webpack_require__.t=function(value,mode){if(1&mode&&(value=__webpack_require__(value)),8&mode)return value;if(4&mode&&"object"==typeof value&&value&&value.__esModule)return value;var ns=Object.create(null);if(__webpack_require__.r(ns),Object.defineProperty(ns,"default",{enumerable:!0,value:value}),2&mode&&"string"!=typeof value)for(var key in value)__webpack_require__.d(ns,key,function(key){return value[key]}.bind(null,key));return ns},__webpack_require__.n=function(module){var getter=module&&module.__esModule?function(){return module.default}:function(){return module};return __webpack_require__.d(getter,"a",getter),getter},__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=0)}([function(module,__webpack_exports__,__webpack_require__){"use strict";function _typeof(obj){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj})(obj)}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}__webpack_require__.r(__webpack_exports__);var _g=function(){return global||window}.bind(void 0),OfType=function(){function OfType(){!function(instance,Constructor){if(!(instance instanceof OfType))throw new TypeError("Cannot call a class as a function")}(this);var _this=this;return function(value,type){return _this._setInitials(arguments,value,type),_this._validate()}}var Constructor,protoProps;return Constructor=OfType,(protoProps=[{key:"_setInitials",value:function(_arguments,value,type){this._arguments=_arguments,this._value=value,this._type=type}},{key:"_validate",value:function(){return!!this.isTypeDefined&&(this.isTypeNull?this.isValueNull:this.isTypeUndefined?void 0===this._value:this.isTypeFunction?this._typeConstructor():this.isTypeArray?this._typeArray():this.isTypeString?this._typeString():!!this.isTypeRegExp&&this._typeRegexp())}},{key:"_typeConstructor",value:function(){return!this.isValueUndefined&&!this.isValueNull&&Object.getPrototypeOf(this._value).constructor.name===this._type.name}},{key:"_typeArray",value:function(){if(!this._type.length)return!0;var _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=this._type[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var t=_step.value;if(null===t&&this.isValueNull)return!0;if(void 0===t&&this.isValueUndefined)return!0;if(!this.isValueNull&&!this.isValueUndefined&&null!==t&&void 0!==t&&Object.getPrototypeOf(this._value).constructor.name===t.name)return!0}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator.return||_iterator.return()}finally{if(_didIteratorError)throw _iteratorError}}return!1}},{key:"_typeString",value:function(){var _this2=this,typeList=this._type.toLowerCase().split("|");if(1===typeList.length&&""===typeList[0]||typeList.some(function(i){return"any"===i}))return!0;if(typeList.some(function(i){return"truthy"===i})&&this._value)return!0;if(typeList.some(function(i){return"falsy"===i})&&!this._value)return!0;if(this.isValueUndefined&&typeList.some(function(i){return"undefined"===i}))return!0;if(this.isValueNull&&typeList.some(function(i){return"null"===i}))return!0;if(this.isValueNull||void 0===this._value)return!1;var valueConstructor=Object.getPrototypeOf(this._value).constructor;return!!(this.argumentsRegExp.test(this._value.toString())&&valueConstructor&&"Object"===valueConstructor.name&&typeList.some(function(i){return"arguments"===i}))||!!(typeList.some(function(i){return"instance"===i})&&this.isValueObject&&valueConstructor&&valueConstructor!==_g()[valueConstructor.name])||!(!typeList.some(function(i){return"objectable"===i})||!this.isObjectInstance)||typeList.some(function(i){return i===Object.getPrototypeOf(_this2._value).constructor.name.toLowerCase()})}},{key:"_typeRegexp",value:function(){if(this._exec("any")||this._type.test(""))return!0;if(this._exec("truthy")&&this._value)return!0;if(this._exec("falsy")&&!this._value)return!0;if(this._type.test("undefined")&&this.isValueUndefined)return!0;if(this._type.test("null")&&this.isValueNull)return!0;if(this.isValueNull||void 0===this._value)return!1;var valueConstructor=Object.getPrototypeOf(this._value).constructor;return!!(this._exec("arguments")&&valueConstructor&&"Object"===valueConstructor.name&&this.argumentsRegExp.test(this._value.toString()))||!!(this._exec("instance")&&this.isValueObject&&valueConstructor&&valueConstructor!==_g()[valueConstructor.name])||!(!this._exec("objectable")||!this.isObjectInstance)||this._type.test(Object.getPrototypeOf(this._value).constructor.name)}},{key:"_exec",value:function(name){var _exec=this._type.exec(name);return null!==_exec&&_exec[0]===name}},{key:"isTypeDefined",get:function(){return this._arguments.length>=2}},{key:"isTypeString",get:function(){return"string"==typeof this._type}},{key:"isTypeFunction",get:function(){return"function"==typeof this._type}},{key:"isTypeUndefined",get:function(){return void 0===this._type}},{key:"isValueUndefined",get:function(){return void 0===this._value}},{key:"isTypeNull",get:function(){return null===this._type}},{key:"isValueNull",get:function(){return null===this._value}},{key:"isValueObject",get:function(){return"object"===_typeof(this._value)}},{key:"isObjectInstance",get:function(){return this._value instanceof Object}},{key:"isTypeArray",get:function(){return!this.isTypeNull&&"object"===_typeof(this._type)&&"Array"===this._type.constructor.name}},{key:"isTypeRegExp",get:function(){return this._type&&"RegExp"===this._type.constructor.name}},{key:"argumentsRegExp",get:function(){return/^\[object Arguments\]$/i}}])&&_defineProperties(Constructor.prototype,protoProps),OfType}();__webpack_exports__.default=new OfType}]).default}).call(this,__webpack_require__(2))},function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,"default",function(){return typeofArguments});var of_type__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),of_type__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(of_type__WEBPACK_IMPORTED_MODULE_0__);function _construct(Parent,args,Class){return(_construct=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(Parent,args,Class){var a=[null];a.push.apply(a,args);var instance=new(Function.bind.apply(Parent,a));return Class&&_setPrototypeOf(instance,Class.prototype),instance}).apply(null,arguments)}function _setPrototypeOf(o,p){return(_setPrototypeOf=Object.setPrototypeOf||function(o,p){return o.__proto__=p,o})(o,p)}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}var TypeofArguments=function(){function TypeofArguments(getArgumentsObject,getExpectedArray,callbackFunction){!function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}(this,TypeofArguments),this.validateArguments(getArgumentsObject,getExpectedArray);for(var i=0;i<getExpectedArray.length;i++)if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(getArgumentsObject[i],getExpectedArray[i])){var actual=this.getActualType(getArgumentsObject[i]),types=this.getExpectedTypes(getExpectedArray[i]),message="Invalid argument [".concat(i,"]. The [").concat(actual,"] ").concat(types.truthness,"argument has been passed, while the ").concat(types.message," is expected.");if(of_type__WEBPACK_IMPORTED_MODULE_0___default()(callbackFunction,"function"))return callbackFunction({actual:actual,expected:types.expected,message:message,index:Number(i)}),function(){return!1};throw new TypeError(message)}return function(){return!0}}var Constructor,protoProps,staticProps;return Constructor=TypeofArguments,(protoProps=[{key:"validateArguments",value:function(actual,expected){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(actual,"arguments"))throw new TypeError("typeof-arguments: Invalid module argument. The first argument must be [arguments] Object.");if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(expected,Array))throw new TypeError("typeof-arguments: Invalid module argument. The second argument must be of type [Array].")}},{key:"getActualType",value:function(actualValue){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,null)?"null":of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,void 0)?"undefined":of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,"arguments")?"arguments":actualValue.constructor.name}},{key:"getExpectedTypes",value:function(expectedType){for(var types=["whenString","whenRegExp","whenObject","whenArray"],_i=0;_i<types.length;_i++){var check=this[types[_i]](expectedType);if(check)return check}throw new TypeError("typeof-arguments: The expected type is not callable.")}},{key:"whenString",value:function(stringType){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(stringType,String))return null;var msg='argument of type matching string expression "'.concat(stringType,'"'),truthness="";return stringType.split("|").forEach(function(i){"truthy"===i.toLowerCase()&&(truthness="<<falsy>> "),"falsy"===i.toLowerCase()&&(truthness="<<truthy>> ")}),{message:msg,truthness:truthness,expected:stringType}}},{key:"whenRegExp",value:function(regType){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(regType,RegExp)?{message:"argument of type matching regular expression ".concat(regType),truthness:function(regType){var isCaseInsensitive=regType.flags.match(/i/),str=regType.toString();return(str=isCaseInsensitive?str.toLowerCase():str).match(/truthy/)?"<<falsy>> ":str.match(/falsy/)?"<<truthy>> ":""}(regType),expected:regType.toString()}:null}},{key:"whenObject",value:function(objectType){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,null)?{message:"argument of type [null]",truthness:"",expected:"null"}:of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,void 0)?{message:"argument of type [undefined]",truthness:"",expected:"undefined"}:of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,Function)?{message:"argument of type [".concat(objectType.name,"]"),truthness:"",expected:objectType.name}:null}},{key:"whenArray",value:function(arrayTypes){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(arrayTypes,Array))return null;var types={},_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=arrayTypes[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var type=_step.value,exp=this.whenObject(type);if(of_type__WEBPACK_IMPORTED_MODULE_0___default()(exp,null))return null;types[exp.expected]=exp.expected}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator.return||_iterator.return()}finally{if(_didIteratorError)throw _iteratorError}}var expected=Object.getOwnPropertyNames(types).join("|");return{message:"argument of type [".concat(expected,"]"),truthness:"",expected:expected}}}])&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),TypeofArguments}();function typeofArguments(){return _construct(TypeofArguments,Array.prototype.slice.call(arguments))()}},function(module,exports){var g;g=function(){return this}();try{g=g||new Function("return this")()}catch(e){"object"==typeof window&&(g=window)}module.exports=g}]).default; | ||
var typeofArguments=function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){__webpack_require__.o(exports,name)||Object.defineProperty(exports,name,{enumerable:!0,get:getter})},__webpack_require__.r=function(exports){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(exports,"__esModule",{value:!0})},__webpack_require__.t=function(value,mode){if(1&mode&&(value=__webpack_require__(value)),8&mode)return value;if(4&mode&&"object"==typeof value&&value&&value.__esModule)return value;var ns=Object.create(null);if(__webpack_require__.r(ns),Object.defineProperty(ns,"default",{enumerable:!0,value:value}),2&mode&&"string"!=typeof value)for(var key in value)__webpack_require__.d(ns,key,function(key){return value[key]}.bind(null,key));return ns},__webpack_require__.n=function(module){var getter=module&&module.__esModule?function(){return module.default}:function(){return module};return __webpack_require__.d(getter,"a",getter),getter},__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=1)}([function(module,exports,__webpack_require__){(function(global){module.exports=function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){__webpack_require__.o(exports,name)||Object.defineProperty(exports,name,{enumerable:!0,get:getter})},__webpack_require__.r=function(exports){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(exports,"__esModule",{value:!0})},__webpack_require__.t=function(value,mode){if(1&mode&&(value=__webpack_require__(value)),8&mode)return value;if(4&mode&&"object"==typeof value&&value&&value.__esModule)return value;var ns=Object.create(null);if(__webpack_require__.r(ns),Object.defineProperty(ns,"default",{enumerable:!0,value:value}),2&mode&&"string"!=typeof value)for(var key in value)__webpack_require__.d(ns,key,function(key){return value[key]}.bind(null,key));return ns},__webpack_require__.n=function(module){var getter=module&&module.__esModule?function(){return module.default}:function(){return module};return __webpack_require__.d(getter,"a",getter),getter},__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=0)}([function(module,__webpack_exports__,__webpack_require__){"use strict";function _typeof(obj){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj})(obj)}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}__webpack_require__.r(__webpack_exports__);var _g=function(){return global||window}.bind(void 0),OfType=function(){function OfType(){!function(instance,Constructor){if(!(instance instanceof OfType))throw new TypeError("Cannot call a class as a function")}(this);var _this=this;return function(value,type){return _this._setInitials(arguments,value,type),_this._validate()}}return _defineProperties(OfType.prototype,[{key:"_setInitials",value:function(_arguments,value,type){this._arguments=_arguments,this._value=value,this._type=type}},{key:"_validate",value:function(){return!!this.isTypeDefined&&(this.isTypeNull?this.isValueNull:this.isTypeUndefined?void 0===this._value:this.isTypeFunction?this._typeConstructor():this.isTypeArray?this._typeArray():this.isTypeString?this._typeString():!!this.isTypeRegExp&&this._typeRegexp())}},{key:"_typeConstructor",value:function(){return!this.isValueUndefined&&!this.isValueNull&&Object.getPrototypeOf(this._value).constructor.name===this._type.name}},{key:"_typeArray",value:function(){if(!this._type.length)return!0;var _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=this._type[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var t=_step.value;if(null===t&&this.isValueNull)return!0;if(void 0===t&&this.isValueUndefined)return!0;if(!this.isValueNull&&!this.isValueUndefined&&null!=t&&Object.getPrototypeOf(this._value).constructor.name===t.name)return!0}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator.return||_iterator.return()}finally{if(_didIteratorError)throw _iteratorError}}return!1}},{key:"_typeString",value:function(){var _this2=this,typeList=this._type.toLowerCase().split("|");if(1===typeList.length&&""===typeList[0]||typeList.some(function(i){return"any"===i}))return!0;if(typeList.some(function(i){return"truthy"===i})&&this._value)return!0;if(typeList.some(function(i){return"falsy"===i})&&!this._value)return!0;if(this.isValueUndefined&&typeList.some(function(i){return"undefined"===i}))return!0;if(this.isValueNull&&typeList.some(function(i){return"null"===i}))return!0;if(this.isValueNull||void 0===this._value)return!1;var valueConstructor=Object.getPrototypeOf(this._value).constructor;return!!(this.argumentsRegExp.test(this._value.toString())&&valueConstructor&&"Object"===valueConstructor.name&&typeList.some(function(i){return"arguments"===i}))||!!(typeList.some(function(i){return"instance"===i})&&this.isValueObject&&valueConstructor&&valueConstructor!==_g()[valueConstructor.name])||!(!typeList.some(function(i){return"objectable"===i})||!this.isObjectInstance)||typeList.some(function(i){return i===Object.getPrototypeOf(_this2._value).constructor.name.toLowerCase()})}},{key:"_typeRegexp",value:function(){if(this._exec("any")||this._type.test(""))return!0;if(this._exec("truthy")&&this._value)return!0;if(this._exec("falsy")&&!this._value)return!0;if(this._type.test("undefined")&&this.isValueUndefined)return!0;if(this._type.test("null")&&this.isValueNull)return!0;if(this.isValueNull||void 0===this._value)return!1;var valueConstructor=Object.getPrototypeOf(this._value).constructor;return!!(this._exec("arguments")&&valueConstructor&&"Object"===valueConstructor.name&&this.argumentsRegExp.test(this._value.toString()))||!!(this._exec("instance")&&this.isValueObject&&valueConstructor&&valueConstructor!==_g()[valueConstructor.name])||!(!this._exec("objectable")||!this.isObjectInstance)||this._type.test(Object.getPrototypeOf(this._value).constructor.name)}},{key:"_exec",value:function(name){var _exec=this._type.exec(name);return null!==_exec&&_exec[0]===name}},{key:"isTypeDefined",get:function(){return 2<=this._arguments.length}},{key:"isTypeString",get:function(){return"string"==typeof this._type}},{key:"isTypeFunction",get:function(){return"function"==typeof this._type}},{key:"isTypeUndefined",get:function(){return void 0===this._type}},{key:"isValueUndefined",get:function(){return void 0===this._value}},{key:"isTypeNull",get:function(){return null===this._type}},{key:"isValueNull",get:function(){return null===this._value}},{key:"isValueObject",get:function(){return"object"===_typeof(this._value)}},{key:"isObjectInstance",get:function(){return this._value instanceof Object}},{key:"isTypeArray",get:function(){return!this.isTypeNull&&"object"===_typeof(this._type)&&"Array"===this._type.constructor.name}},{key:"isTypeRegExp",get:function(){return this._type&&"RegExp"===this._type.constructor.name}},{key:"argumentsRegExp",get:function(){return/^\[object Arguments\]$/i}}]),OfType}();__webpack_exports__.default=new OfType}]).default}).call(this,__webpack_require__(2))},function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,"default",function(){return typeofArguments});var of_type__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),of_type__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(of_type__WEBPACK_IMPORTED_MODULE_0__);function _construct(Parent,args,Class){return(_construct=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(Parent,args,Class){var a=[null];a.push.apply(a,args);var instance=new(Function.bind.apply(Parent,a));return Class&&_setPrototypeOf(instance,Class.prototype),instance}).apply(null,arguments)}function _setPrototypeOf(o,p){return(_setPrototypeOf=Object.setPrototypeOf||function(o,p){return o.__proto__=p,o})(o,p)}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}var TypeofArguments=function(){function TypeofArguments(getArgumentsObject,getExpectedArray,callbackFunction){if(function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}(this,TypeofArguments),!of_type__WEBPACK_IMPORTED_MODULE_0___default()(getArgumentsObject,"arguments"))throw new TypeError("typeof-arguments: The [0] argument must be the [arguments] Object.");if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(getExpectedArray,Array))throw new TypeError("typeof-arguments: The [1] argument must be of type [Array].");for(var index=0;index<getExpectedArray.length;index++)if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(getArgumentsObject[index],getExpectedArray[index])){var actual=this.getActualType(getArgumentsObject[index]),types=this.getExpectedTypes(getExpectedArray[index]),textActual="[".concat(actual,"] ").concat(types.addons,"argument"),textExpected=types.message,message="Invalid argument [".concat(index,"]. The ").concat(textActual," has been passed, while the ").concat(textExpected," is expected.");if(of_type__WEBPACK_IMPORTED_MODULE_0___default()(callbackFunction,"function"))return callbackFunction({index:index,actual:actual,expected:types.expected,message:message,textActual:textActual,textExpected:textExpected}),function(){return!1};throw new TypeError(message)}return function(){return!0}}var Constructor,protoProps,staticProps;return Constructor=TypeofArguments,(protoProps=[{key:"getActualType",value:function(actualValue){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,null)?"null":of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,void 0)?"undefined":of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,"arguments")?"arguments":actualValue.constructor.name}},{key:"getExpectedTypes",value:function(expectedType){for(var types=["whenString","whenRegExp","whenObject","whenArray"],_i=0;_i<types.length;_i++){var check=this[types[_i]](expectedType);if(check)return check}throw new TypeError("typeof-arguments: The expected type is not callable.")}},{key:"whenString",value:function(stringType){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(stringType,String))return null;var msg='argument of type matching string expression "'.concat(stringType,'"'),truthness="",objectable="";return stringType.split("|").forEach(function(i){"truthy"===i.toLowerCase()&&(truthness="<<falsy>> "),"falsy"===i.toLowerCase()&&(truthness="<<truthy>> "),"objectable"===i.toLowerCase()&&(objectable="<<non-objectable>> ")}),{message:msg,addons:truthness+objectable,expected:stringType}}},{key:"whenRegExp",value:function(regType){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(regType,RegExp)?{message:"argument of type matching regular expression ".concat(regType),addons:function(regType){var isCaseInsensitive=regType.flags.match(/i/),str=regType.toString();str=isCaseInsensitive?str.toLowerCase():str;var truthness="",objectable="";str.match(/truthy/)&&(truthness="<<falsy>> ");str.match(/falsy/)&&(truthness="<<truthy>> ");str.match(/objectable/)&&(objectable="<<non-objectable>> ");return truthness+objectable}(regType),expected:regType.toString()}:null}},{key:"whenObject",value:function(objectType){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,null)?{message:"argument of type [null]",addons:"",expected:"null"}:of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,void 0)?{message:"argument of type [undefined]",addons:"",expected:"undefined"}:of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,Function)?{message:"argument of type [".concat(objectType.name,"]"),addons:"",expected:objectType.name}:null}},{key:"whenArray",value:function(arrayTypes){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(arrayTypes,Array))return null;var types={},_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=arrayTypes[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var _type=_step.value,exp=this.whenObject(_type);if(of_type__WEBPACK_IMPORTED_MODULE_0___default()(exp,null))return null;types[exp.expected]=exp.expected}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator.return||_iterator.return()}finally{if(_didIteratorError)throw _iteratorError}}var expected=Object.getOwnPropertyNames(types).join("|");return{message:"argument of type [".concat(expected,"]"),addons:"",expected:expected}}}])&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),TypeofArguments}();function typeofArguments(){return _construct(TypeofArguments,Array.prototype.slice.call(arguments))()}},function(module,exports){var g;g=function(){return this}();try{g=g||new Function("return this")()}catch(e){"object"==typeof window&&(g=window)}module.exports=g}]).default; |
@@ -1,1 +0,1 @@ | ||
module.exports=function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){__webpack_require__.o(exports,name)||Object.defineProperty(exports,name,{enumerable:!0,get:getter})},__webpack_require__.r=function(exports){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(exports,"__esModule",{value:!0})},__webpack_require__.t=function(value,mode){if(1&mode&&(value=__webpack_require__(value)),8&mode)return value;if(4&mode&&"object"==typeof value&&value&&value.__esModule)return value;var ns=Object.create(null);if(__webpack_require__.r(ns),Object.defineProperty(ns,"default",{enumerable:!0,value:value}),2&mode&&"string"!=typeof value)for(var key in value)__webpack_require__.d(ns,key,function(key){return value[key]}.bind(null,key));return ns},__webpack_require__.n=function(module){var getter=module&&module.__esModule?function(){return module.default}:function(){return module};return __webpack_require__.d(getter,"a",getter),getter},__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=1)}([function(module,exports){module.exports=require("of-type")},function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,"default",function(){return typeofArguments});var of_type__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),of_type__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(of_type__WEBPACK_IMPORTED_MODULE_0__);function _construct(Parent,args,Class){return(_construct=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(Parent,args,Class){var a=[null];a.push.apply(a,args);var instance=new(Function.bind.apply(Parent,a));return Class&&_setPrototypeOf(instance,Class.prototype),instance}).apply(null,arguments)}function _setPrototypeOf(o,p){return(_setPrototypeOf=Object.setPrototypeOf||function(o,p){return o.__proto__=p,o})(o,p)}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}var TypeofArguments=function(){function TypeofArguments(getArgumentsObject,getExpectedArray,callbackFunction){!function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}(this,TypeofArguments),this.validateArguments(getArgumentsObject,getExpectedArray);for(var i=0;i<getExpectedArray.length;i++)if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(getArgumentsObject[i],getExpectedArray[i])){var actual=this.getActualType(getArgumentsObject[i]),types=this.getExpectedTypes(getExpectedArray[i]),message="Invalid argument [".concat(i,"]. The [").concat(actual,"] ").concat(types.truthness,"argument has been passed, while the ").concat(types.message," is expected.");if(of_type__WEBPACK_IMPORTED_MODULE_0___default()(callbackFunction,"function"))return callbackFunction({actual:actual,expected:types.expected,message:message,index:Number(i)}),function(){return!1};throw new TypeError(message)}return function(){return!0}}var Constructor,protoProps,staticProps;return Constructor=TypeofArguments,(protoProps=[{key:"validateArguments",value:function(actual,expected){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(actual,"arguments"))throw new TypeError("typeof-arguments: Invalid module argument. The first argument must be [arguments] Object.");if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(expected,Array))throw new TypeError("typeof-arguments: Invalid module argument. The second argument must be of type [Array].")}},{key:"getActualType",value:function(actualValue){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,null)?"null":of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,void 0)?"undefined":of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,"arguments")?"arguments":actualValue.constructor.name}},{key:"getExpectedTypes",value:function(expectedType){for(var types=["whenString","whenRegExp","whenObject","whenArray"],_i=0;_i<types.length;_i++){var check=this[types[_i]](expectedType);if(check)return check}throw new TypeError("typeof-arguments: The expected type is not callable.")}},{key:"whenString",value:function(stringType){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(stringType,String))return null;var msg='argument of type matching string expression "'.concat(stringType,'"'),truthness="";return stringType.split("|").forEach(function(i){"truthy"===i.toLowerCase()&&(truthness="<<falsy>> "),"falsy"===i.toLowerCase()&&(truthness="<<truthy>> ")}),{message:msg,truthness:truthness,expected:stringType}}},{key:"whenRegExp",value:function(regType){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(regType,RegExp)?{message:"argument of type matching regular expression ".concat(regType),truthness:function(regType){var isCaseInsensitive=regType.flags.match(/i/),str=regType.toString();return(str=isCaseInsensitive?str.toLowerCase():str).match(/truthy/)?"<<falsy>> ":str.match(/falsy/)?"<<truthy>> ":""}(regType),expected:regType.toString()}:null}},{key:"whenObject",value:function(objectType){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,null)?{message:"argument of type [null]",truthness:"",expected:"null"}:of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,void 0)?{message:"argument of type [undefined]",truthness:"",expected:"undefined"}:of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,Function)?{message:"argument of type [".concat(objectType.name,"]"),truthness:"",expected:objectType.name}:null}},{key:"whenArray",value:function(arrayTypes){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(arrayTypes,Array))return null;var types={},_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=arrayTypes[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var type=_step.value,exp=this.whenObject(type);if(of_type__WEBPACK_IMPORTED_MODULE_0___default()(exp,null))return null;types[exp.expected]=exp.expected}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator.return||_iterator.return()}finally{if(_didIteratorError)throw _iteratorError}}var expected=Object.getOwnPropertyNames(types).join("|");return{message:"argument of type [".concat(expected,"]"),truthness:"",expected:expected}}}])&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),TypeofArguments}();function typeofArguments(){return _construct(TypeofArguments,Array.prototype.slice.call(arguments))()}}]).default; | ||
module.exports=function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={i:moduleId,l:!1,exports:{}};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.l=!0,module.exports}return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.d=function(exports,name,getter){__webpack_require__.o(exports,name)||Object.defineProperty(exports,name,{enumerable:!0,get:getter})},__webpack_require__.r=function(exports){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(exports,"__esModule",{value:!0})},__webpack_require__.t=function(value,mode){if(1&mode&&(value=__webpack_require__(value)),8&mode)return value;if(4&mode&&"object"==typeof value&&value&&value.__esModule)return value;var ns=Object.create(null);if(__webpack_require__.r(ns),Object.defineProperty(ns,"default",{enumerable:!0,value:value}),2&mode&&"string"!=typeof value)for(var key in value)__webpack_require__.d(ns,key,function(key){return value[key]}.bind(null,key));return ns},__webpack_require__.n=function(module){var getter=module&&module.__esModule?function(){return module.default}:function(){return module};return __webpack_require__.d(getter,"a",getter),getter},__webpack_require__.o=function(object,property){return Object.prototype.hasOwnProperty.call(object,property)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=1)}([function(module,exports){module.exports=require("of-type")},function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,"default",function(){return typeofArguments});var of_type__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(0),of_type__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(of_type__WEBPACK_IMPORTED_MODULE_0__);function _construct(Parent,args,Class){return(_construct=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(Parent,args,Class){var a=[null];a.push.apply(a,args);var instance=new(Function.bind.apply(Parent,a));return Class&&_setPrototypeOf(instance,Class.prototype),instance}).apply(null,arguments)}function _setPrototypeOf(o,p){return(_setPrototypeOf=Object.setPrototypeOf||function(o,p){return o.__proto__=p,o})(o,p)}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}var TypeofArguments=function(){function TypeofArguments(getArgumentsObject,getExpectedArray,callbackFunction){if(function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}(this,TypeofArguments),!of_type__WEBPACK_IMPORTED_MODULE_0___default()(getArgumentsObject,"arguments"))throw new TypeError("typeof-arguments: The [0] argument must be the [arguments] Object.");if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(getExpectedArray,Array))throw new TypeError("typeof-arguments: The [1] argument must be of type [Array].");for(var index=0;index<getExpectedArray.length;index++)if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(getArgumentsObject[index],getExpectedArray[index])){var actual=this.getActualType(getArgumentsObject[index]),types=this.getExpectedTypes(getExpectedArray[index]),textActual="[".concat(actual,"] ").concat(types.addons,"argument"),textExpected=types.message,message="Invalid argument [".concat(index,"]. The ").concat(textActual," has been passed, while the ").concat(textExpected," is expected.");if(of_type__WEBPACK_IMPORTED_MODULE_0___default()(callbackFunction,"function"))return callbackFunction({index:index,actual:actual,expected:types.expected,message:message,textActual:textActual,textExpected:textExpected}),function(){return!1};throw new TypeError(message)}return function(){return!0}}var Constructor,protoProps,staticProps;return Constructor=TypeofArguments,(protoProps=[{key:"getActualType",value:function(actualValue){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,null)?"null":of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,void 0)?"undefined":of_type__WEBPACK_IMPORTED_MODULE_0___default()(actualValue,"arguments")?"arguments":actualValue.constructor.name}},{key:"getExpectedTypes",value:function(expectedType){for(var types=["whenString","whenRegExp","whenObject","whenArray"],_i=0;_i<types.length;_i++){var check=this[types[_i]](expectedType);if(check)return check}throw new TypeError("typeof-arguments: The expected type is not callable.")}},{key:"whenString",value:function(stringType){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(stringType,String))return null;var msg='argument of type matching string expression "'.concat(stringType,'"'),truthness="",objectable="";return stringType.split("|").forEach(function(i){"truthy"===i.toLowerCase()&&(truthness="<<falsy>> "),"falsy"===i.toLowerCase()&&(truthness="<<truthy>> "),"objectable"===i.toLowerCase()&&(objectable="<<non-objectable>> ")}),{message:msg,addons:truthness+objectable,expected:stringType}}},{key:"whenRegExp",value:function(regType){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(regType,RegExp)?{message:"argument of type matching regular expression ".concat(regType),addons:function(regType){var isCaseInsensitive=regType.flags.match(/i/),str=regType.toString();str=isCaseInsensitive?str.toLowerCase():str;var truthness="",objectable="";str.match(/truthy/)&&(truthness="<<falsy>> ");str.match(/falsy/)&&(truthness="<<truthy>> ");str.match(/objectable/)&&(objectable="<<non-objectable>> ");return truthness+objectable}(regType),expected:regType.toString()}:null}},{key:"whenObject",value:function(objectType){return of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,null)?{message:"argument of type [null]",addons:"",expected:"null"}:of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,void 0)?{message:"argument of type [undefined]",addons:"",expected:"undefined"}:of_type__WEBPACK_IMPORTED_MODULE_0___default()(objectType,Function)?{message:"argument of type [".concat(objectType.name,"]"),addons:"",expected:objectType.name}:null}},{key:"whenArray",value:function(arrayTypes){if(!of_type__WEBPACK_IMPORTED_MODULE_0___default()(arrayTypes,Array))return null;var types={},_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=arrayTypes[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var _type=_step.value,exp=this.whenObject(_type);if(of_type__WEBPACK_IMPORTED_MODULE_0___default()(exp,null))return null;types[exp.expected]=exp.expected}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{_iteratorNormalCompletion||null==_iterator.return||_iterator.return()}finally{if(_didIteratorError)throw _iteratorError}}var expected=Object.getOwnPropertyNames(types).join("|");return{message:"argument of type [".concat(expected,"]"),addons:"",expected:expected}}}])&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),TypeofArguments}();function typeofArguments(){return _construct(TypeofArguments,Array.prototype.slice.call(arguments))()}}]).default; |
{ | ||
"name": "typeof-arguments", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "Validate the type of arguments passed through the function.", | ||
@@ -40,3 +40,3 @@ "main": "dist/typeof-arguments.node.js", | ||
"jasmine-spec-reporter": "^4.2.1", | ||
"uglifyjs-webpack-plugin": "^1.3.0", | ||
"uglifyjs-webpack-plugin": "^2.1.1", | ||
"webpack": "^4.19.1", | ||
@@ -43,0 +43,0 @@ "webpack-cli": "^3.1.1", |
@@ -6,2 +6,3 @@ # Description | ||
* Also see [`typeof-properties`](https://www.npmjs.com/package/typeof-properties) to validate the object's properties' type. | ||
* Also see [`typeof-items`](https://www.npmjs.com/package/typeof-items) to validate the array's items' type | ||
@@ -181,2 +182,6 @@ # Implementation | ||
is the default error [String] message, that you can use eg. to log in the console | ||
* **`textActual`** | ||
indicates the [String] textual actual type, eg. `"[undefined] <<falsy>> argument"` | ||
* **`textExpected`** | ||
indicates the [String] textual expected type, eg. `"argument of type matching regular expression /String|null/"` | ||
@@ -183,0 +188,0 @@ ```javascript |
@@ -1,13 +0,16 @@ | ||
import ofType from 'of-type'; | ||
import type from 'of-type'; | ||
class TypeofArguments { | ||
constructor(getArgumentsObject, getExpectedArray, callbackFunction) { | ||
this.validateArguments(getArgumentsObject, getExpectedArray); | ||
for (let i = 0; i < getExpectedArray.length; i++) { | ||
if (!ofType(getArgumentsObject[i], getExpectedArray[i])) { | ||
let actual = this.getActualType(getArgumentsObject[i]); | ||
let types = this.getExpectedTypes(getExpectedArray[i]); | ||
let message = `Invalid argument [${i}]. The [${actual}] ${types.truthness}argument has been passed, while the ${types.message} is expected.`; | ||
if (ofType(callbackFunction, 'function')) { | ||
callbackFunction({ actual: actual, expected: types.expected, message: message, index: Number(i) }); | ||
if (!type(getArgumentsObject, 'arguments')) throw new TypeError('typeof-arguments: The [0] argument must be the [arguments] Object.'); | ||
if (!type(getExpectedArray, Array)) throw new TypeError('typeof-arguments: The [1] argument must be of type [Array].'); | ||
for (let index = 0; index < getExpectedArray.length; index++) { | ||
if (!type(getArgumentsObject[index], getExpectedArray[index])) { | ||
let actual = this.getActualType(getArgumentsObject[index]); | ||
let types = this.getExpectedTypes(getExpectedArray[index]); | ||
let textActual = `[${actual}] ${types.addons}argument`; | ||
let textExpected = types.message; | ||
let message = `Invalid argument [${index}]. The ${textActual} has been passed, while the ${textExpected} is expected.`; | ||
if (type(callbackFunction, 'function')) { | ||
callbackFunction({ index, actual, expected: types.expected, message, textActual, textExpected }); | ||
return () => false; | ||
@@ -22,11 +25,6 @@ } else { | ||
validateArguments(actual, expected) { | ||
if (!ofType(actual, 'arguments')) throw new TypeError('typeof-arguments: Invalid module argument. The first argument must be [arguments] Object.'); | ||
if (!ofType(expected, Array)) throw new TypeError('typeof-arguments: Invalid module argument. The second argument must be of type [Array].'); | ||
} | ||
getActualType(actualValue) { | ||
if (ofType(actualValue, null)) return 'null'; | ||
if (ofType(actualValue, undefined)) return 'undefined'; | ||
if (ofType(actualValue, 'arguments')) return 'arguments'; | ||
if (type(actualValue, null)) return 'null'; | ||
if (type(actualValue, undefined)) return 'undefined'; | ||
if (type(actualValue, 'arguments')) return 'arguments'; | ||
return actualValue.constructor.name; | ||
@@ -37,4 +35,4 @@ } | ||
const types = ['whenString', 'whenRegExp', 'whenObject', 'whenArray']; | ||
for (let type of types) { | ||
let check = this[type](expectedType); | ||
for (let _type of types) { | ||
let check = this[_type](expectedType); | ||
if (check) return check; | ||
@@ -46,24 +44,27 @@ } | ||
whenString(stringType) { | ||
if (!ofType(stringType, String)) return null; | ||
if (!type(stringType, String)) return null; | ||
const msg = `argument of type matching string expression "${stringType}"`; | ||
let truthness = ''; | ||
let truthness = '', objectable = ''; | ||
stringType.split('|').forEach((i) => { | ||
if (i.toLowerCase() === 'truthy') truthness = '<<falsy>> '; | ||
if (i.toLowerCase() === 'falsy') truthness = '<<truthy>> '; | ||
if (i.toLowerCase() === 'objectable') objectable = '<<non-objectable>> '; | ||
}); | ||
return { message: msg, truthness: truthness, expected: stringType }; | ||
return { message: msg, addons: truthness + objectable, expected: stringType }; | ||
} | ||
whenRegExp(regType) { | ||
if (!ofType(regType, RegExp)) return null; | ||
if (!type(regType, RegExp)) return null; | ||
const msg = `argument of type matching regular expression ${regType}`; | ||
return { message: msg, truthness: truthness(regType), expected: regType.toString() }; | ||
return { message: msg, addons: addons(regType), expected: regType.toString() }; | ||
function truthness(regType) { | ||
function addons(regType) { | ||
const isCaseInsensitive = regType.flags.match(/i/); | ||
let str = regType.toString(); | ||
str = isCaseInsensitive ? str.toLowerCase() : str; | ||
if (str.match(/truthy/)) return '<<falsy>> '; | ||
if (str.match(/falsy/)) return '<<truthy>> '; | ||
return ''; | ||
let truthness = '', objectable = ''; | ||
if (str.match(/truthy/)) truthness = '<<falsy>> '; | ||
if (str.match(/falsy/)) truthness = '<<truthy>> '; | ||
if (str.match(/objectable/)) objectable = '<<non-objectable>> '; | ||
return truthness + objectable; | ||
} | ||
@@ -73,5 +74,5 @@ } | ||
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 }; | ||
if (type(objectType, null)) return { message: 'argument of type [null]', addons: '', expected: 'null' }; | ||
if (type(objectType, undefined)) return { message: 'argument of type [undefined]', addons: '', expected: 'undefined' }; | ||
if (type(objectType, Function)) return { message: `argument of type [${objectType.name}]`, addons: '', expected: objectType.name }; | ||
return null; | ||
@@ -81,11 +82,11 @@ } | ||
whenArray(arrayTypes) { | ||
if (!ofType(arrayTypes, Array)) return null; | ||
if (!type(arrayTypes, Array)) return null; | ||
const types = {}; | ||
for (let type of arrayTypes) { | ||
let exp = this.whenObject(type); | ||
if (ofType(exp, null)) return null; | ||
for (let _type of arrayTypes) { | ||
let exp = this.whenObject(_type); | ||
if (type(exp, null)) return null; | ||
types[exp.expected] = exp.expected; | ||
} | ||
const expected = Object.getOwnPropertyNames(types).join('|'); | ||
return { message: `argument of type [${expected}]`, truthness: '', expected }; | ||
return { message: `argument of type [${expected}]`, addons: '', expected }; | ||
} | ||
@@ -92,0 +93,0 @@ } |
@@ -7,3 +7,3 @@ export default [ | ||
oExpected:'{name:10}', | ||
message:/Invalid module argument. The first argument must be \[arguments\] Object./ | ||
message:/The \[0\] argument must be the \[arguments\] Object./ | ||
}, | ||
@@ -15,3 +15,3 @@ { | ||
oExpected:'undefined', | ||
message:/Invalid module argument. The first argument must be \[arguments\] Object./ | ||
message:/The \[0\] argument must be the \[arguments\] Object./ | ||
}, | ||
@@ -23,3 +23,3 @@ { | ||
oExpected:'undefined', | ||
message:/Invalid module argument. The first argument must be \[arguments\] Object./ | ||
message:/The \[0\] argument must be the \[arguments\] Object./ | ||
}, | ||
@@ -31,3 +31,3 @@ { | ||
oExpected:'null', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
message:/The \[1\] argument must be of type \[Array\]./ | ||
}, | ||
@@ -39,3 +39,3 @@ { | ||
oExpected:'null', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
message:/The \[1\] argument must be of type \[Array\]./ | ||
}, | ||
@@ -47,3 +47,3 @@ { | ||
oExpected:'Number', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
message:/The \[1\] argument must be of type \[Array\]./ | ||
}, | ||
@@ -55,3 +55,3 @@ { | ||
oExpected:'null', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
message:/The \[1\] argument must be of type \[Array\]./ | ||
}, | ||
@@ -63,3 +63,3 @@ { | ||
oExpected:'(function(){return arguments;})()', | ||
message:/Invalid module argument. The second argument must be of type \[Array\]./ | ||
message:/The \[1\] argument must be of type \[Array\]./ | ||
}, | ||
@@ -66,0 +66,0 @@ { |
export default [ | ||
{ | ||
actual:[null], | ||
expected:[String], | ||
oActual:'null', | ||
oExpected:'String', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type [String] is expected.' | ||
actual: [null], | ||
expected: [String], | ||
oActual: 'null', | ||
oExpected: 'String', | ||
oIndex: 0, | ||
oTextActual: '[null] argument', | ||
oTextExpected: 'argument of type [String]', | ||
oMessage: 'Invalid argument [0]. The [null] argument has been passed, while the argument of type [String] is expected.' | ||
}, | ||
{ | ||
actual:[20,'Paul'], | ||
expected:[Number,null], | ||
oActual:'String', | ||
oExpected:'null', | ||
oIndex:1, | ||
oMessage:'Invalid argument [1]. The [String] argument has been passed, while the argument of type [null] is expected.' | ||
actual: [20, 'Paul'], | ||
expected: [Number, null], | ||
oActual: 'String', | ||
oExpected: 'null', | ||
oIndex: 1, | ||
oTextActual: '[String] argument', | ||
oTextExpected: 'argument of type [null]', | ||
oMessage: 'Invalid argument [1]. The [String] argument has been passed, while the argument of type [null] is expected.' | ||
}, | ||
{ | ||
actual:[], | ||
expected:[String], | ||
oActual:'undefined', | ||
oExpected:'String', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [undefined] argument has been passed, while the argument of type [String] is expected.' | ||
actual: [], | ||
expected: [String], | ||
oActual: 'undefined', | ||
oExpected: 'String', | ||
oIndex: 0, | ||
oTextActual: '[undefined] argument', | ||
oTextExpected: 'argument of type [String]', | ||
oMessage: 'Invalid argument [0]. The [undefined] argument has been passed, while the argument of type [String] is expected.' | ||
}, | ||
{ | ||
actual:[null], | ||
expected:['string'], | ||
oActual:'null', | ||
oExpected:'string', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "string" is expected.' | ||
actual: [null], | ||
expected: ['string'], | ||
oActual: 'null', | ||
oExpected: 'string', | ||
oIndex: 0, | ||
oTextActual: '[null] argument', | ||
oTextExpected: 'argument of type matching string expression "string"', | ||
oMessage: 'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "string" is expected.' | ||
}, | ||
{ | ||
actual:[null], | ||
expected:['STRING'], | ||
oActual:'null', | ||
oExpected:'STRING', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "STRING" is expected.' | ||
actual: [null], | ||
expected: ['STRING'], | ||
oActual: 'null', | ||
oExpected: 'STRING', | ||
oIndex: 0, | ||
oTextActual: '[null] argument', | ||
oTextExpected: 'argument of type matching string expression "STRING"', | ||
oMessage: 'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "STRING" is expected.' | ||
}, | ||
{ | ||
actual:[null], | ||
expected:['number|string|undefined'], | ||
oActual:'null', | ||
oExpected:'number|string|undefined', | ||
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.' | ||
actual: [null], | ||
expected: ['number|string|undefined'], | ||
oActual: 'null', | ||
oExpected: 'number|string|undefined', | ||
oIndex: 0, | ||
oTextActual: '[null] argument', | ||
oTextExpected: 'argument of type matching string expression "number|string|undefined"', | ||
oMessage: 'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching string expression "number|string|undefined" is expected.' | ||
}, | ||
{ | ||
actual:[null], | ||
expected:['truthy|undefined'], | ||
oActual:'null', | ||
oExpected:'truthy|undefined', | ||
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.' | ||
actual: [null], | ||
expected: ['truthy|undefined'], | ||
oActual: 'null', | ||
oExpected: 'truthy|undefined', | ||
oIndex: 0, | ||
oTextActual: '[null] <<falsy>> argument', | ||
oTextExpected: 'argument of type matching string expression "truthy|undefined"', | ||
oMessage: 'Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching string expression "truthy|undefined" is expected.' | ||
}, | ||
{ | ||
actual:[10,10,'Paul'], | ||
expected:['any','ANY','falsy|number'], | ||
oActual:'String', | ||
oExpected:'falsy|number', | ||
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.' | ||
actual: [10, 10, 'Paul'], | ||
expected: ['any', 'ANY', 'falsy|number'], | ||
oActual: 'String', | ||
oExpected: 'falsy|number', | ||
oIndex: 2, | ||
oTextActual: '[String] <<truthy>> argument', | ||
oTextExpected: 'argument of type matching string expression "falsy|number"', | ||
oMessage: 'Invalid argument [2]. The [String] <<truthy>> argument has been passed, while the argument of type matching string expression "falsy|number" is expected.' | ||
}, | ||
{ | ||
actual:[null,false], | ||
expected:[/string/i,String], | ||
oActual:'null', | ||
oExpected:'/string/i', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching regular expression /string/i is expected.' | ||
actual: [null, false], | ||
expected: [/string/i, String], | ||
oActual: 'null', | ||
oExpected: '/string/i', | ||
oIndex: 0, | ||
oTextActual: '[null] argument', | ||
oTextExpected: 'argument of type matching regular expression /string/i', | ||
oMessage: 'Invalid argument [0]. The [null] argument has been passed, while the argument of type matching regular expression /string/i is expected.' | ||
}, | ||
{ | ||
actual:[null], | ||
expected:[/truthy/], | ||
oActual:'null', | ||
oExpected:'/truthy/', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching regular expression /truthy/ is expected.' | ||
actual: [null], | ||
expected: [/truthy/], | ||
oActual: 'null', | ||
oExpected: '/truthy/', | ||
oIndex: 0, | ||
oTextActual: '[null] <<falsy>> argument', | ||
oTextExpected: 'argument of type matching regular expression /truthy/', | ||
oMessage: 'Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching regular expression /truthy/ is expected.' | ||
}, | ||
{ | ||
actual:[null], | ||
expected:[/truthy|undefined|String/], | ||
oActual:'null', | ||
oExpected:'/truthy|undefined|String/', | ||
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.' | ||
actual: [null], | ||
expected: [/truthy|undefined|String/], | ||
oActual: 'null', | ||
oExpected: '/truthy|undefined|String/', | ||
oIndex: 0, | ||
oTextActual: '[null] <<falsy>> argument', | ||
oTextExpected: 'argument of type matching regular expression /truthy|undefined|String/', | ||
oMessage: 'Invalid argument [0]. The [null] <<falsy>> argument has been passed, while the argument of type matching regular expression /truthy|undefined|String/ is expected.' | ||
}, | ||
{ | ||
actual:['Paul'], | ||
expected:[/falsy/], | ||
oActual:'String', | ||
oExpected:'/falsy/', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [String] <<truthy>> argument has been passed, while the argument of type matching regular expression /falsy/ is expected.' | ||
actual: ['Paul'], | ||
expected: [/falsy/], | ||
oActual: 'String', | ||
oExpected: '/falsy/', | ||
oIndex: 0, | ||
oTextActual: '[String] <<truthy>> argument', | ||
oTextExpected: 'argument of type matching regular expression /falsy/', | ||
oMessage: 'Invalid argument [0]. The [String] <<truthy>> argument has been passed, while the argument of type matching regular expression /falsy/ is expected.' | ||
}, | ||
{ | ||
actual:[new Date()], | ||
expected:[/falsy|Array/], | ||
oActual:'Date', | ||
oExpected:'/falsy|Array/', | ||
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.' | ||
actual: [new Date()], | ||
expected: [/falsy|Array/], | ||
oActual: 'Date', | ||
oExpected: '/falsy|Array/', | ||
oIndex: 0, | ||
oTextActual: '[Date] <<truthy>> argument', | ||
oTextExpected: 'argument of type matching regular expression /falsy|Array/', | ||
oMessage: 'Invalid argument [0]. The [Date] <<truthy>> argument has been passed, while the argument of type matching regular expression /falsy|Array/ is expected.' | ||
}, | ||
{ | ||
actual:['Warsaw',22,false], | ||
expected:[String,/num/i,/TrUtHy/], | ||
oActual:'Boolean', | ||
oExpected:'/TrUtHy/', | ||
oIndex:2, | ||
oMessage:'Invalid argument [2]. The [Boolean] argument has been passed, while the argument of type matching regular expression /TrUtHy/ is expected.' | ||
actual: ['Warsaw', 22, false], | ||
expected: [String, /num/i, /TrUtHy/], | ||
oActual: 'Boolean', | ||
oExpected: '/TrUtHy/', | ||
oIndex: 2, | ||
oTextActual: '[Boolean] argument', | ||
oTextExpected: 'argument of type matching regular expression /TrUtHy/', | ||
oMessage: 'Invalid argument [2]. The [Boolean] argument has been passed, while the argument of type matching regular expression /TrUtHy/ is expected.' | ||
}, | ||
{ | ||
actual:['Paul'], | ||
expected:[/FaLsY/], | ||
oActual:'String', | ||
oExpected:'/FaLsY/', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [String] argument has been passed, while the argument of type matching regular expression /FaLsY/ is expected.' | ||
actual: ['Paul'], | ||
expected: [/FaLsY/], | ||
oActual: 'String', | ||
oExpected: '/FaLsY/', | ||
oIndex: 0, | ||
oTextActual: '[String] argument', | ||
oTextExpected: 'argument of type matching regular expression /FaLsY/', | ||
oMessage: 'Invalid argument [0]. The [String] argument has been passed, while the argument of type matching regular expression /FaLsY/ is expected.' | ||
}, | ||
{ | ||
actual:['Paul'], | ||
expected:[/FaLsY/i], | ||
oActual:'String', | ||
oExpected:'/FaLsY/i', | ||
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.' | ||
actual: ['Paul'], | ||
expected: [/FaLsY/i], | ||
oActual: 'String', | ||
oExpected: '/FaLsY/i', | ||
oIndex: 0, | ||
oTextActual: '[String] <<truthy>> argument', | ||
oTextExpected: 'argument of type matching regular expression /FaLsY/i', | ||
oMessage: 'Invalid argument [0]. The [String] <<truthy>> argument has been passed, while the argument of type matching regular expression /FaLsY/i is expected.' | ||
}, | ||
{ | ||
actual:['Warsaw',null], | ||
expected:[[Array,Array,Array,null,undefined,String],[String,Array,undefined,Boolean]], | ||
oActual:'null', | ||
oExpected:'String|Array|undefined|Boolean', | ||
oIndex:1, | ||
oMessage:'Invalid argument [1]. The [null] argument has been passed, while the argument of type [String|Array|undefined|Boolean] is expected.' | ||
actual: ['Warsaw', null], | ||
expected: [[Array, Array, Array, null, undefined, String], [String, Array, undefined, Boolean]], | ||
oActual: 'null', | ||
oExpected: 'String|Array|undefined|Boolean', | ||
oIndex: 1, | ||
oTextActual: '[null] argument', | ||
oTextExpected: 'argument of type [String|Array|undefined|Boolean]', | ||
oMessage: 'Invalid argument [1]. The [null] argument has been passed, while the argument of type [String|Array|undefined|Boolean] is expected.' | ||
}, | ||
{ | ||
actual:[new Date()], | ||
expected:[[Array,undefined,undefined,Array]], | ||
oActual:'Date', | ||
oExpected:'Array|undefined', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [Date] argument has been passed, while the argument of type [Array|undefined] is expected.' | ||
actual: [new Date()], | ||
expected: [[Array, undefined, undefined, Array]], | ||
oActual: 'Date', | ||
oExpected: 'Array|undefined', | ||
oIndex: 0, | ||
oTextActual: '[Date] argument', | ||
oTextExpected: 'argument of type [Array|undefined]', | ||
oMessage: 'Invalid argument [0]. The [Date] argument has been passed, while the argument of type [Array|undefined] is expected.' | ||
}, | ||
{ | ||
actual:[Infinity], | ||
expected:[[Array,undefined,undefined,Array]], | ||
oActual:'Number', | ||
oExpected:'Array|undefined', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [Number] argument has been passed, while the argument of type [Array|undefined] is expected.' | ||
actual: [Infinity], | ||
expected: [[Array, undefined, undefined, Array]], | ||
oActual: 'Number', | ||
oExpected: 'Array|undefined', | ||
oIndex: 0, | ||
oTextActual: '[Number] argument', | ||
oTextExpected: 'argument of type [Array|undefined]', | ||
oMessage: 'Invalid argument [0]. The [Number] argument has been passed, while the argument of type [Array|undefined] is expected.' | ||
}, | ||
{ | ||
actual:['Paul'], | ||
expected:[null], | ||
oActual:'String', | ||
oExpected:'null', | ||
oIndex:0, | ||
oMessage:'Invalid argument [0]. The [String] argument has been passed, while the argument of type [null] is expected.' | ||
actual: ['Paul'], | ||
expected: [null], | ||
oActual: 'String', | ||
oExpected: 'null', | ||
oIndex: 0, | ||
oTextActual: '[String] argument', | ||
oTextExpected: 'argument of type [null]', | ||
oMessage: 'Invalid argument [0]. The [String] argument has been passed, while the argument of type [null] is expected.' | ||
}, | ||
{ | ||
actual:['Paul',22], | ||
expected:[[String],'number',/string/i], | ||
oActual:'undefined', | ||
oExpected:'/string/i', | ||
oIndex:2, | ||
oMessage:'Invalid argument [2]. The [undefined] argument has been passed, while the argument of type matching regular expression /string/i is expected.' | ||
actual: ['Paul', 22], | ||
expected: [[String], 'number', /string/i], | ||
oActual: 'undefined', | ||
oExpected: '/string/i', | ||
oIndex: 2, | ||
oTextActual: '[undefined] argument', | ||
oTextExpected: 'argument of type matching regular expression /string/i', | ||
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: [/name/], | ||
oActual: 'Name', | ||
oExpected: '/name/', | ||
oIndex: 0, | ||
oTextActual: '[Name] argument', | ||
oTextExpected: 'argument of type matching regular expression /name/', | ||
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: [Object], | ||
oActual: 'Name', | ||
oExpected: 'Object', | ||
oIndex: 0, | ||
oTextActual: '[Name] argument', | ||
oTextExpected: 'argument of type [Object]', | ||
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: [(() => new (class Name { }))()], | ||
expected: ['Age'], | ||
oActual: 'Name', | ||
oExpected: 'Age', | ||
oIndex: 0, | ||
oTextActual: '[Name] argument', | ||
oTextExpected: 'argument of type matching string expression "Age"', | ||
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: ['Name'], | ||
oActual: 'Object', | ||
oExpected: 'Name', | ||
oIndex: 0, | ||
oTextActual: '[Object] argument', | ||
oTextExpected: 'argument of type matching string expression "Name"', | ||
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, | ||
oTextActual: '[Object] argument', | ||
oTextExpected: 'argument of type matching string expression "instance"', | ||
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.' | ||
} | ||
actual: [{}], | ||
expected: [/instance/], | ||
oActual: 'Object', | ||
oExpected: '/instance/', | ||
oIndex: 0, | ||
oTextActual: '[Object] argument', | ||
oTextExpected: 'argument of type matching regular expression /instance/', | ||
oMessage: 'Invalid argument [0]. The [Object] argument has been passed, while the argument of type matching regular expression /instance/ is expected.' | ||
}, | ||
{ | ||
actual: [(function () { return arguments; })()], | ||
expected: [/instance/], | ||
oActual: 'arguments', | ||
oExpected: '/instance/', | ||
oIndex: 0, | ||
oTextActual: '[arguments] argument', | ||
oTextExpected: 'argument of type matching regular expression /instance/', | ||
oMessage: 'Invalid argument [0]. The [arguments] argument has been passed, while the argument of type matching regular expression /instance/ is expected.' | ||
}, | ||
{ | ||
actual: [[1, 2, 3]], | ||
expected: [/arguments/], | ||
oActual: 'Array', | ||
oExpected: '/arguments/', | ||
oIndex: 0, | ||
oTextActual: '[Array] argument', | ||
oTextExpected: 'argument of type matching regular expression /arguments/', | ||
oMessage: 'Invalid argument [0]. The [Array] argument has been passed, while the argument of type matching regular expression /arguments/ is expected.' | ||
}, | ||
{ | ||
actual: [function () { }], | ||
expected: ['arguments|instance'], | ||
oActual: 'Function', | ||
oExpected: 'arguments|instance', | ||
oIndex: 0, | ||
oTextActual: '[Function] argument', | ||
oTextExpected: 'argument of type matching string expression "arguments|instance"', | ||
oMessage: 'Invalid argument [0]. The [Function] argument has been passed, while the argument of type matching string expression "arguments|instance" is expected.' | ||
}, | ||
{ | ||
actual: [10, new String('hello world'), true], | ||
expected: [Number, 'falsy|objectable', 'falsy|objectable'], | ||
oActual: 'Boolean', | ||
oExpected: 'falsy|objectable', | ||
oIndex: 2, | ||
oTextActual: '[Boolean] <<truthy>> <<non-objectable>> argument', | ||
oTextExpected: 'argument of type matching string expression "falsy|objectable"', | ||
oMessage: 'Invalid argument [2]. The [Boolean] <<truthy>> <<non-objectable>> argument has been passed, while the argument of type matching string expression "falsy|objectable" is expected.' | ||
}, | ||
{ | ||
actual: [null, new String('hello world'), ''], | ||
expected: [[Number, null], 'falsy|objectable', 'truthy|objectable'], | ||
oActual: 'String', | ||
oExpected: 'truthy|objectable', | ||
oIndex: 2, | ||
oTextActual: '[String] <<falsy>> <<non-objectable>> argument', | ||
oTextExpected: 'argument of type matching string expression "truthy|objectable"', | ||
oMessage: 'Invalid argument [2]. The [String] <<falsy>> <<non-objectable>> argument has been passed, while the argument of type matching string expression "truthy|objectable" is expected.' | ||
}, | ||
{ | ||
actual: [[1, 2, 3], undefined], | ||
expected: [/arr/i, /truthy|objectable/], | ||
oActual: 'undefined', | ||
oExpected: '/truthy|objectable/', | ||
oIndex: 1, | ||
oTextActual: '[undefined] <<falsy>> <<non-objectable>> argument', | ||
oTextExpected: 'argument of type matching regular expression /truthy|objectable/', | ||
oMessage: 'Invalid argument [1]. The [undefined] <<falsy>> <<non-objectable>> argument has been passed, while the argument of type matching regular expression /truthy|objectable/ is expected.' | ||
}, | ||
{ | ||
actual: [{}, 492], | ||
expected: [/objectable/, /falsy|objectable/], | ||
oActual: 'Number', | ||
oExpected: '/falsy|objectable/', | ||
oIndex: 1, | ||
oTextActual: '[Number] <<truthy>> <<non-objectable>> argument', | ||
oTextExpected: 'argument of type matching regular expression /falsy|objectable/', | ||
oMessage: 'Invalid argument [1]. The [Number] <<truthy>> <<non-objectable>> argument has been passed, while the argument of type matching regular expression /falsy|objectable/ is expected.' | ||
}, | ||
{ | ||
actual: ['hello world', 0, new Number(0), null], | ||
expected: ['truthy|objectable', 'falsy|objectable', 'truthy|objectable', /objectable/], | ||
oActual: 'null', | ||
oExpected: '/objectable/', | ||
oIndex: 3, | ||
oTextActual: '[null] <<non-objectable>> argument', | ||
oTextExpected: 'argument of type matching regular expression /objectable/', | ||
oMessage: 'Invalid argument [3]. The [null] <<non-objectable>> argument has been passed, while the argument of type matching regular expression /objectable/ is expected.' | ||
}, | ||
]; |
export default [ | ||
{ | ||
actual: ['Paul',26,'Warsaw',['js','mongodb','nodejs']], | ||
expected: [String,'any',/string|null/i,[Array,null]] | ||
actual: ['Paul', 26, 'Warsaw', ['js', 'mongodb', 'nodejs']], | ||
expected: [String, 'any', /string|null/i, [Array, null]] | ||
}, | ||
{ | ||
actual: [null,26,'Warsaw',null], | ||
expected: ['truthy|null',/TRUTHY/i,[String,String,String,Array,null,undefined],[Array,null]] | ||
actual: [null, 26, 'Warsaw', null], | ||
expected: ['truthy|null', /TRUTHY/i, [String, String, String, Array, null, undefined], [Array, null]] | ||
}, | ||
{ | ||
actual: ['Warsaw',52.229676,21.012229,new Date('2017-08-22'),{day:24,night:18},.71,{kph:18,mph:11.3}], | ||
expected: ['string','number',Number,[Date,String],/object|number/i,'number|falsy',/truthy|null/] | ||
actual: ['Warsaw', 52.229676, 21.012229, new Date('2017-08-22'), { day: 24, night: 18 }, .71, { kph: 18, mph: 11.3 }], | ||
expected: ['string', 'number', Number, [Date, String], /object|number/i, 'number|falsy', /truthy|null/] | ||
}, | ||
{ | ||
actual: ['Warsaw',52.229676,21.012229,new Date('2017-08-22'),{day:24,night:18},.71,{kph:18,mph:11.3}], | ||
expected: ['truthy'] | ||
actual: [new String('Warsaw'), new Number(52.229676), 21.012229, new Date('2017-08-22'), { day: 24, night: 18 }, .71, { kph: 18, mph: 11.3 }], | ||
expected: ['objectable', /Objectable/i, Number, [Date, String], /object|number/i, 'number|falsy', /truthy|null/] | ||
}, | ||
{ | ||
actual: ['Warsaw',52.229676,21.012229,new Date('2017-08-22'),{day:24,night:18},.71,{kph:18,mph:11.3}], | ||
expected: ['truthy','any',/any/,Date,/obj/i] | ||
actual: ['Warsaw', 52.229676, 21.012229, new Date('2017-08-22'), { day: 24, night: 18 }, .71, { kph: 18, mph: 11.3 }], | ||
expected: ['truthy', '', []] | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))(),(()=>new (class Age{}))(), {}], | ||
expected:['instance', /instance/, Object] | ||
actual: ['Warsaw', 52.229676, 21.012229, new Date('2017-08-22'), { day: 24, night: 18 }, .71, { kph: 18, mph: 11.3 }], | ||
expected: ['truthy', 'any', /any/, Date, /obj/i] | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))(),(()=>new (class Age{}))(), {}], | ||
expected:['name', /Age/, Object] | ||
actual: [(() => new (class Name { }))(), (() => new (class Age { }))(), {}], | ||
expected: ['instance', /instance/, Object] | ||
}, | ||
{ | ||
actual:[(()=>new (class Name{}))(),(()=>new (class Age{}))(), {}], | ||
expected:['any', /truthy/, Object] | ||
} | ||
actual: [(() => new (class Name { }))(), (() => new (class Age { }))(), {}], | ||
expected: ['name', /Age/, Object] | ||
}, | ||
{ | ||
actual: [(() => new (class Name { }))(), (() => new (class Age { }))(), {}], | ||
expected: ['any', /truthy/, Object] | ||
}, | ||
{ | ||
actual: [(function () { return arguments; })(), (function () { return arguments; })(), (function () { return arguments; })()], | ||
expected: ['arguments|objectable', /Arguments/i, /arguments|array/i] | ||
}, | ||
]; |
/* global describe, expect, it */ | ||
import scenario from './data/scenarios-arguments.js'; | ||
describe('When the module function type() is called',function(){ | ||
describe('with callback defined and the arguments',function(){ | ||
for(let i in scenario){ | ||
it(`type(${scenario[i].oActual},${scenario[i].oExpected}), it should throw TypeError with message "${scenario[i].message}"`,function(){ | ||
let binded = this.type.bind(this,scenario[i].actual,scenario[i].expected,()=>{}); | ||
expect(binded).toThrowError(TypeError,scenario[i].message); | ||
describe('When the module function type() is called', function () { | ||
describe('with callback defined and the arguments', function () { | ||
for (let i in scenario) { | ||
it(`type(${scenario[i].oActual}, ${scenario[i].oExpected}), it should throw TypeError with message "${scenario[i].message}"`, function () { | ||
let binded = this.type.bind(this, scenario[i].actual, scenario[i].expected, () => { }); | ||
expect(binded).toThrowError(TypeError, scenario[i].message); | ||
}); | ||
} | ||
}); | ||
describe('without callback defined and the arguments',function(){ | ||
for(let i in scenario){ | ||
it(`type(${scenario[i].oActual},${scenario[i].oExpected}), it should throw TypeError with message "${scenario[i].message}"`,function(){ | ||
let binded = this.type.bind(this,scenario[i].actual,scenario[i].expected,()=>{}); | ||
expect(binded).toThrowError(TypeError,scenario[i].message); | ||
describe('without callback defined and the arguments', function () { | ||
for (let i in scenario) { | ||
it(`type(${scenario[i].oActual}, ${scenario[i].oExpected}), it should throw TypeError with message "${scenario[i].message}"`, function () { | ||
let binded = this.type.bind(this, scenario[i].actual, scenario[i].expected); | ||
expect(binded).toThrowError(TypeError, scenario[i].message); | ||
}); | ||
@@ -19,0 +19,0 @@ } |
/* global jasmine, describe, expect, it */ | ||
import scenario from './data/scenarios-invalid.js'; | ||
describe('When the argument is of invalid type, the module function',function(){ | ||
describe('when callback is not defined, should throw TypeError with message',function(){ | ||
for(let i in scenario){ | ||
let {actual,expected,oMessage} = scenario[i]; | ||
it(`"${oMessage}"`,function(){ | ||
let binded = test.apply.bind(test,this,actual); | ||
expect(binded).toThrowError(TypeError,oMessage); | ||
function test(){ | ||
this.type(arguments,expected); | ||
describe('When the argument is of invalid type, the module function', function () { | ||
describe('when callback is not defined, should throw TypeError with message', function () { | ||
for (let i in scenario) { | ||
let { actual, expected, oMessage } = scenario[i]; | ||
it(`"${oMessage}"`, function () { | ||
let binded = test.apply.bind(test, this, actual); | ||
expect(binded).toThrowError(TypeError, oMessage); | ||
function test() { | ||
this.type(arguments, expected); | ||
} | ||
@@ -17,8 +17,8 @@ }); | ||
}); | ||
describe('when callback is defined, should return false and run callback with object',function(){ | ||
for(let i in scenario){ | ||
let {actual,expected,oActual,oExpected,oIndex,oMessage} = scenario[i]; | ||
it(`{actual:${oActual},expected:${oExpected},index:${oIndex},message:${oMessage}}`,function(){ | ||
describe('when callback is defined, should return false and run callback with object', function () { | ||
for (let i in scenario) { | ||
let { actual, expected, oActual, oExpected, oIndex, oMessage, oTextActual, oTextExpected } = scenario[i]; | ||
it(`{ actual: ${oActual}, expected: ${oExpected}, index: ${oIndex}, message: ${oMessage}, textActual: ${oTextActual}, textExpected: ${oTextExpected} }`, function () { | ||
let clb = jasmine.createSpy('clb'); | ||
let binded = test.apply.bind(test,this,actual); | ||
let binded = test.apply.bind(test, this, actual); | ||
expect(binded()).toBe(false); | ||
@@ -28,9 +28,11 @@ expect(binded).not.toThrowError(); | ||
expect(clb).toHaveBeenCalledWith(jasmine.objectContaining({ | ||
actual:oActual, | ||
expected:oExpected, | ||
index:oIndex, | ||
message:oMessage | ||
actual: oActual, | ||
expected: oExpected, | ||
index: oIndex, | ||
message: oMessage, | ||
textActual: oTextActual, | ||
textExpected: oTextExpected | ||
})); | ||
function test(){ | ||
return this.type(arguments,expected,clb); | ||
function test() { | ||
return this.type(arguments, expected, clb); | ||
} | ||
@@ -37,0 +39,0 @@ }); |
/* global jasmine, describe, expect, it */ | ||
import scenario from './data/scenarios-valid.js'; | ||
describe('The module function should not throw error and run callback function',function(){ | ||
it('when the expected array is empty',function(){ | ||
describe('The module function should not throw error and run callback function', function () { | ||
it('when the expected array is empty', function () { | ||
let clb = jasmine.createSpy('clb'); | ||
let binded = test.bind(this,'Paul',22); | ||
let binded = test.bind(this, 'Paul', 22); | ||
expect(binded()).toBe(true); | ||
expect(binded).not.toThrowError(); | ||
expect(clb).not.toHaveBeenCalled(); | ||
function test(){ | ||
return this.type(arguments,[],clb); | ||
function test() { | ||
return this.type(arguments, [], clb); | ||
} | ||
@@ -17,13 +17,13 @@ }); | ||
describe('The module function should not throw error and run callback function',function(){ | ||
for(let i in scenario){ | ||
it(`when the arguments passed through function are correct and the validation has passed [Nb. ${i}]`,function(){ | ||
let {actual,expected} = scenario[i]; | ||
describe('The module function should not throw error and run callback function', function () { | ||
for (let i in scenario) { | ||
it(`when the arguments passed through function are correct and the validation has passed [Nb. ${i}]`, function () { | ||
let { actual, expected } = scenario[i]; | ||
let clb = jasmine.createSpy('clb'); | ||
let binded = test.apply.bind(test,this,actual); | ||
let binded = test.apply.bind(test, this, actual); | ||
expect(binded()).toBe(true); | ||
expect(binded).not.toThrowError(); | ||
expect(clb).not.toHaveBeenCalled(); | ||
function test(){ | ||
return this.type(arguments,expected,clb); | ||
function test() { | ||
return this.type(arguments, expected, clb); | ||
} | ||
@@ -30,0 +30,0 @@ }); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
70475
847
331