typed-function
Advanced tools
Comparing version 1.1.0 to 1.1.1
# History | ||
## 2019-08-22, version 1.1.1 | ||
- Fix #15: passing `null` to an `Object` parameter throws wrong error. | ||
## 2018-07-28, version 1.1.0 | ||
@@ -5,0 +10,0 @@ |
{ | ||
"name": "typed-function", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Type checking for JavaScript functions", | ||
@@ -5,0 +5,0 @@ "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)", |
@@ -134,2 +134,34 @@ // test parse | ||
it('should correctly handle null', function () { | ||
var fn = typed({ | ||
'Object': function (a) { | ||
return 'Object'; | ||
}, | ||
'null': function (a) { | ||
return 'null'; | ||
}, | ||
'undefined': function (a) { | ||
return 'undefined'; | ||
} | ||
}); | ||
assert.equal(fn(new Object(null)), 'Object'); | ||
assert.equal(fn(null), 'null'); | ||
assert.equal(fn(undefined), 'undefined'); | ||
}); | ||
it('should throw correct error message when passing null from an Object', function() { | ||
var signatures = { | ||
'Object': function (value) { | ||
assert(value instanceof Object); | ||
return 'Object'; | ||
} | ||
}; | ||
var fn = typed(signatures); | ||
assert.equal(fn({}), 'Object'); | ||
assert.throws(function () { fn(null) }, | ||
/TypeError: Unexpected type of argument in function unnamed \(expected: Object, actual: null, index: 0\)/); | ||
}); | ||
it('should create a new, isolated instance of typed-function', function() { | ||
@@ -136,0 +168,0 @@ var typed1 = typed.create(); |
@@ -80,3 +80,3 @@ /** | ||
{ name: 'Object', test: function (x) { | ||
return typeof x === 'object' && x.constructor === Object | ||
return typeof x === 'object' && x !== null && x.constructor === Object | ||
}}, | ||
@@ -83,0 +83,0 @@ { name: 'null', test: function (x) { return x === null } }, |
@@ -1,1 +0,1 @@ | ||
"use strict";!function(n,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?module.exports=r():n.typed=r()}(this,function(){function v(){return!0}function pn(){return!1}function cn(){}return function n(){var r=[{name:"number",test:function(n){return"number"==typeof n}},{name:"string",test:function(n){return"string"==typeof n}},{name:"boolean",test:function(n){return"boolean"==typeof n}},{name:"Function",test:function(n){return"function"==typeof n}},{name:"Array",test:Array.isArray},{name:"Date",test:function(n){return n instanceof Date}},{name:"RegExp",test:function(n){return n instanceof RegExp}},{name:"Object",test:function(n){return"object"==typeof n&&n.constructor===Object}},{name:"null",test:function(n){return null===n}},{name:"undefined",test:function(n){return void 0===n}}],e={name:"any",test:v},t=[],a=[],B={types:r,conversions:a,ignore:t};function f(r){var n=sn(B.types,function(n){return n.name===r});if(n)return n;if("any"===r)return e;var t=sn(B.types,function(n){return n.name.toLowerCase()===r.toLowerCase()});throw new TypeError('Unknown type "'+r+'"'+(t?'. Did you mean "'+t.name+'"?':""))}function p(n){return n===e?999:B.types.indexOf(n)}function G(r){var n=sn(B.types,function(n){return n.test(r)});if(n)return n.name;throw new TypeError("Value has unknown type. Value: "+r)}function H(n){return n.map(function(n){var r=n.types.map(o);return(n.restParam?"...":"")+r.join("|")}).join(",")}function J(n,t){var r,e,a=0===n.indexOf("..."),o=(a?3<n.length?n.slice(3):"any":n).split("|").map(tn).filter(g).filter(m),u=(r=o,e={},t.forEach(function(n){-1!==r.indexOf(n.from)||-1===r.indexOf(n.to)||e[n.from]||(e[n.from]=n)}),Object.keys(e).map(function(n){return e[n]})),i=o.map(function(n){var r=f(n);return{name:n,typeIndex:p(r),test:r.test,conversion:null,conversionIndex:-1}}),s=u.map(function(n){var r=f(n.from);return{name:n.from,typeIndex:p(r),test:r.test,conversion:n,conversionIndex:t.indexOf(n)}});return{types:i.concat(s),restParam:a}}function K(n){var r=i(n);return!!r&&r.restParam}function Q(n){return n.types.some(function(n){return null!=n.conversion})}function W(n){if(n&&0!==n.types.length){if(1===n.types.length)return f(n.types[0].name).test;if(2===n.types.length){var r=f(n.types[0].name).test,t=f(n.types[1].name).test;return function(n){return r(n)||t(n)}}var e=n.types.map(function(n){return f(n.name).test});return function(n){for(var r=0;r<e.length;r++)if(e[r](n))return!0;return!1}}return v}function X(n){var t,r,e,a;if(K(n)){var o=(t=(a=n,a.slice(0,a.length-1)).map(W)).length,u=W(i(n));return function(n){for(var r=0;r<t.length;r++)if(!t[r](n[r]))return!1;return function(n){for(var r=o;r<n.length;r++)if(!u(n[r]))return!1;return!0}(n)&&n.length>=o+1}}return 0===n.length?function(n){return 0===n.length}:1===n.length?(r=W(n[0]),function(n){return r(n[0])&&1===n.length}):2===n.length?(r=W(n[0]),e=W(n[1]),function(n){return r(n[0])&&e(n[1])&&2===n.length}):(t=n.map(W),function(n){for(var r=0;r<t.length;r++)if(!t[r](n[r]))return!1;return n.length===t.length})}function Y(n,r){return r<n.params.length?n.params[r]:K(n.params)?i(n.params):null}function Z(n,r,t){var e=Y(n,r);return(e?t?e.types.filter(c):e.types:[]).map(o)}function o(n){return n.name}function c(n){return null===n.conversion||void 0===n.conversion}function $(n,r){var t=function(n){for(var r={},t=0;t<n.length;t++)r[n[t]]=!0;return Object.keys(r)}(fn(n,function(n){return Z(n,r,!1)}));return-1!==t.indexOf("any")?["any"]:t}function s(n){for(var r=999,t=0;t<n.types.length;t++)c(n.types[t])&&(r=Math.min(r,n.types[t].typeIndex));return r}function l(n){for(var r=999,t=0;t<n.types.length;t++)c(n.types[t])||(r=Math.min(r,n.types[t].conversionIndex));return r}function _(n,r){var t,e,a,o,u,i=Math.min(n.params.length,r.params.length);if(0!=(e=n.params.some(Q)-r.params.some(Q)))return e;for(t=0;t<i;t++)if(0!=(e=Q(n.params[t])-Q(r.params[t])))return e;for(t=0;t<i;t++)if(a=n.params[t],o=r.params[t],u=void 0,0!==(e=0!=(u=a.restParam-o.restParam)?u:0!=(u=Q(a)-Q(o))?u:0!=(u=s(a)-s(o))?u:l(a)-l(o)))return e;return n.params.length-r.params.length}function nn(n){var r,t,e,a,o=[],u=[];switch(n.types.forEach(function(n){n.conversion&&(o.push(f(n.conversion.from).test),u.push(n.conversion.convert))}),u.length){case 0:return function(n){return n};case 1:return r=o[0],e=u[0],function(n){return r(n)?e(n):n};case 2:return r=o[0],t=o[1],e=u[0],a=u[1],function(n){return r(n)?e(n):t(n)?a(n):n};default:return function(n){for(var r=0;r<u.length;r++)if(o[r](n))return u[r](n);return n}}}function rn(n,s){return function r(t,e,a){if(e<t.length){var n,o=t[e],u=s?o.types.filter(c):o.types;if(o.restParam){var i=u.filter(c);n=i.length<u.length?[i,u]:[u]}else n=u.map(function(n){return[n]});return fn(n,function(n){return r(t,e+1,a.concat([n]))})}return[a.map(function(n,r){return{types:n,restParam:r===t.length-1&&K(t)}})]}(n,0,[])}function u(r,o){if(0===Object.keys(o).length)throw new SyntaxError("No signatures provided");var t=[];Object.keys(o).map(function(n){return t=o[r=n],a=B.conversions,e=[],""!==r.trim()&&(e=r.split(",").map(tn).map(function(n,r,t){var e=J(n,a);if(e.restParam&&r!==t.length-1)throw new SyntaxError('Unexpected rest parameter "'+n+'": only allowed for the last parameter');return e})),e.some(an)?null:{params:e,fn:t};var r,t,a,e}).filter(en).forEach(function(r){var n=sn(t,function(n){return function(n,r){for(var t=Math.max(n.params.length,r.params.length),e=0;e<t;e++)if(!un(Z(n,e,!0),Z(r,e,!0)))return!1;var a=n.params.length,o=r.params.length,u=K(n.params),i=K(r.params);return u?i?a===o:a<=o:i?o<=a:a===o}(n,r)});if(n)throw new TypeError('Conflicting signatures "'+H(n.params)+'" and "'+H(r.params)+'".');t.push(r)});var e=fn(t,function(r){return(r?rn(r.params,!1):[]).map(function(n){return{params:n,fn:r.fn}})}).filter(en);e.sort(_);var a,n=e[0]&&e[0].params.length<=2&&!K(e[0].params),u=e[1]&&e[1].params.length<=2&&!K(e[1].params),i=e[2]&&e[2].params.length<=2&&!K(e[2].params),s=e[3]&&e[3].params.length<=2&&!K(e[3].params),f=e[4]&&e[4].params.length<=2&&!K(e[4].params),p=e[5]&&e[5].params.length<=2&&!K(e[5].params),c=n&&u&&i&&s&&f&&p,l=e.map(function(n){return X(n.params)}),m=n?W(e[0].params[0]):pn,g=u?W(e[1].params[0]):pn,h=i?W(e[2].params[0]):pn,y=s?W(e[3].params[0]):pn,v=f?W(e[4].params[0]):pn,d=p?W(e[5].params[0]):pn,w=n?W(e[0].params[1]):pn,x=u?W(e[1].params[1]):pn,E=i?W(e[2].params[1]):pn,j=s?W(e[3].params[1]):pn,O=f?W(e[4].params[1]):pn,b=p?W(e[5].params[1]):pn,T=e.map(function(n){return function(n,e){var r=e;if(n.some(Q)){var a=K(n),o=n.map(nn);r=function(){for(var n=[],r=a?arguments.length-1:arguments.length,t=0;t<r;t++)n[t]=o[t](arguments[t]);return a&&(n[r]=arguments[r].map(o[r])),e.apply(null,n)}}var t=r;if(K(n)){var u=n.length-1;t=function(){return r.apply(null,on(arguments,0,u).concat([on(arguments,u)]))}}return t}(n.params,n.fn)}),P=n?T[0]:cn,A=u?T[1]:cn,F=i?T[2]:cn,M=s?T[3]:cn,k=f?T[4]:cn,I=p?T[5]:cn,C=n?e[0].params.length:-1,S=u?e[1].params.length:-1,D=i?e[2].params.length:-1,L=s?e[3].params.length:-1,U=f?e[4].params.length:-1,R=p?e[5].params.length:-1,V=c?6:0,N=e.length,q=function(){for(var n=V;n<N;n++)if(l[n](arguments))return T[n].apply(null,arguments);throw function(n,t,r){var e,a,o,u=n||"unnamed",i=r;for(o=0;o<t.length;o++){var s=i.filter(function(n){var r=W(Y(n,o));return(o<n.params.length||K(n.params))&&r(t[o])});if(0===s.length){if(0<(a=$(i,o)).length){var f=G(t[o]);return(e=new TypeError("Unexpected type of argument in function "+u+" (expected: "+a.join(" or ")+", actual: "+f+", index: "+o+")")).data={category:"wrongType",fn:u,index:o,actual:f,expected:a},e}}else i=s}var p=i.map(function(n){return K(n.params)?1/0:n.params.length});if(t.length<Math.min.apply(null,p))return a=$(i,o),(e=new TypeError("Too few arguments in function "+u+" (expected: "+a.join(" or ")+", index: "+t.length+")")).data={category:"tooFewArgs",fn:u,index:t.length,expected:a},e;var c=Math.max.apply(null,p);return t.length>c?(e=new TypeError("Too many arguments in function "+u+" (expected: "+c+", actual: "+t.length+")")).data={category:"tooManyArgs",fn:u,index:t.length,expectedLength:c}:(e=new TypeError('Arguments of type "'+t.join(", ")+'" do not match any of the defined signatures of function '+u+".")).data={category:"mismatch",actual:t.map(G)},e}(r,arguments,e)},z=function(n,r){return arguments.length===C&&m(n)&&w(r)?P.apply(null,arguments):arguments.length===S&&g(n)&&x(r)?A.apply(null,arguments):arguments.length===D&&h(n)&&E(r)?F.apply(null,arguments):arguments.length===L&&y(n)&&j(r)?M.apply(null,arguments):arguments.length===U&&v(n)&&O(r)?k.apply(null,arguments):arguments.length===R&&d(n)&&b(r)?I.apply(null,arguments):q.apply(null,arguments)};try{Object.defineProperty(z,"name",{value:r})}catch(n){}return z.signatures=(a={},e.forEach(function(r){r.params.some(Q)||rn(r.params,!0).forEach(function(n){a[H(n)]=r.fn})}),a),z}function m(n){return-1===B.ignore.indexOf(n)}function tn(n){return n.trim()}function g(n){return!!n}function en(n){return null!==n}function an(n){return 0===n.types.length}function i(n){return n[n.length-1]}function on(n,r,t){return Array.prototype.slice.call(n,r,t)}function un(n,r){for(var t=0;t<n.length;t++)if(e=r,a=n[t],-1!==e.indexOf(a))return!0;var e,a;return!1}function sn(n,r){for(var t=0;t<n.length;t++)if(r(n[t]))return n[t]}function fn(n,r){return Array.prototype.concat.apply([],n.map(r))}function h(n){for(var r="",t=0;t<n.length;t++){var e=n[t];if(("object"==typeof e.signatures||"string"==typeof e.signature)&&""!==e.name)if(""===r)r=e.name;else if(r!==e.name){var a=new Error("Function names do not match (expected: "+r+", actual: "+e.name+")");throw a.data={actual:e.name,expected:r},a}}return r}function y(n){var t,e={};function r(n,r){if(e.hasOwnProperty(n)&&r!==e[n])throw(t=new Error('Signature "'+n+'" is defined twice')).data={signature:n},t}for(var a=0;a<n.length;a++){var o=n[a];if("object"==typeof o.signatures)for(var u in o.signatures)o.signatures.hasOwnProperty(u)&&(r(u,o.signatures[u]),e[u]=o.signatures[u]);else{if("string"!=typeof o.signature)throw(t=new TypeError("Function is no typed-function (index: "+a+")")).data={index:a},t;r(o.signature,o),e[o.signature]=o}}return e}return(B=u("typed",{"string, Object":u,Object:function(n){var r=[];for(var t in n)n.hasOwnProperty(t)&&r.push(n[t]);return u(h(r),n)},"...Function":function(n){return u(h(n),y(n))},"string, ...Function":function(n,r){return u(n,y(r))}})).create=n,B.types=r,B.conversions=a,B.ignore=t,B.convert=function(n,r){var t=G(n);if(r===t)return n;for(var e=0;e<B.conversions.length;e++){var a=B.conversions[e];if(a.from===t&&a.to===r)return a.convert(n)}throw new Error("Cannot convert from "+t+" to "+r)},B.find=function(n,r){if(!n.signatures)throw new TypeError("Function is no typed-function");var t;if("string"==typeof r){t=r.split(",");for(var e=0;e<t.length;e++)t[e]=t[e].trim()}else{if(!Array.isArray(r))throw new TypeError("String array or a comma separated string expected");t=r}var a=t.join(","),o=n.signatures[a];if(o)return o;throw new TypeError("Signature not found (signature: "+(n.name||"unnamed")+"("+t.join(", ")+"))")},B.addType=function(n,r){if(!n||"string"!=typeof n.name||"function"!=typeof n.test)throw new TypeError("Object with properties {name: string, test: function} expected");if(!1!==r)for(var t=0;t<B.types.length;t++)if("Object"===B.types[t].name)return void B.types.splice(t,0,n);B.types.push(n)},B.addConversion=function(n){if(!n||"string"!=typeof n.from||"string"!=typeof n.to||"function"!=typeof n.convert)throw new TypeError("Object with properties {from: string, to: string, convert: function} expected");B.conversions.push(n)},B}()}); | ||
"use strict";!function(n,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?module.exports=r():n.typed=r()}(this,function(){function v(){return!0}function pn(){return!1}function cn(){}return function n(){var r=[{name:"number",test:function(n){return"number"==typeof n}},{name:"string",test:function(n){return"string"==typeof n}},{name:"boolean",test:function(n){return"boolean"==typeof n}},{name:"Function",test:function(n){return"function"==typeof n}},{name:"Array",test:Array.isArray},{name:"Date",test:function(n){return n instanceof Date}},{name:"RegExp",test:function(n){return n instanceof RegExp}},{name:"Object",test:function(n){return"object"==typeof n&&null!==n&&n.constructor===Object}},{name:"null",test:function(n){return null===n}},{name:"undefined",test:function(n){return void 0===n}}],e={name:"any",test:v},t=[],a=[],B={types:r,conversions:a,ignore:t};function f(r){var n=sn(B.types,function(n){return n.name===r});if(n)return n;if("any"===r)return e;var t=sn(B.types,function(n){return n.name.toLowerCase()===r.toLowerCase()});throw new TypeError('Unknown type "'+r+'"'+(t?'. Did you mean "'+t.name+'"?':""))}function p(n){return n===e?999:B.types.indexOf(n)}function G(r){var n=sn(B.types,function(n){return n.test(r)});if(n)return n.name;throw new TypeError("Value has unknown type. Value: "+r)}function H(n){return n.map(function(n){var r=n.types.map(o);return(n.restParam?"...":"")+r.join("|")}).join(",")}function J(n,t){var r,e,a=0===n.indexOf("..."),o=(a?3<n.length?n.slice(3):"any":n).split("|").map(tn).filter(g).filter(m),u=(r=o,e={},t.forEach(function(n){-1!==r.indexOf(n.from)||-1===r.indexOf(n.to)||e[n.from]||(e[n.from]=n)}),Object.keys(e).map(function(n){return e[n]})),i=o.map(function(n){var r=f(n);return{name:n,typeIndex:p(r),test:r.test,conversion:null,conversionIndex:-1}}),s=u.map(function(n){var r=f(n.from);return{name:n.from,typeIndex:p(r),test:r.test,conversion:n,conversionIndex:t.indexOf(n)}});return{types:i.concat(s),restParam:a}}function K(n){var r=i(n);return!!r&&r.restParam}function Q(n){return n.types.some(function(n){return null!=n.conversion})}function W(n){if(n&&0!==n.types.length){if(1===n.types.length)return f(n.types[0].name).test;if(2===n.types.length){var r=f(n.types[0].name).test,t=f(n.types[1].name).test;return function(n){return r(n)||t(n)}}var e=n.types.map(function(n){return f(n.name).test});return function(n){for(var r=0;r<e.length;r++)if(e[r](n))return!0;return!1}}return v}function X(n){var t,r,e,a;if(K(n)){var o=(t=(a=n,a.slice(0,a.length-1)).map(W)).length,u=W(i(n));return function(n){for(var r=0;r<t.length;r++)if(!t[r](n[r]))return!1;return function(n){for(var r=o;r<n.length;r++)if(!u(n[r]))return!1;return!0}(n)&&n.length>=o+1}}return 0===n.length?function(n){return 0===n.length}:1===n.length?(r=W(n[0]),function(n){return r(n[0])&&1===n.length}):2===n.length?(r=W(n[0]),e=W(n[1]),function(n){return r(n[0])&&e(n[1])&&2===n.length}):(t=n.map(W),function(n){for(var r=0;r<t.length;r++)if(!t[r](n[r]))return!1;return n.length===t.length})}function Y(n,r){return r<n.params.length?n.params[r]:K(n.params)?i(n.params):null}function Z(n,r,t){var e=Y(n,r);return(e?t?e.types.filter(c):e.types:[]).map(o)}function o(n){return n.name}function c(n){return null===n.conversion||void 0===n.conversion}function $(n,r){var t=function(n){for(var r={},t=0;t<n.length;t++)r[n[t]]=!0;return Object.keys(r)}(fn(n,function(n){return Z(n,r,!1)}));return-1!==t.indexOf("any")?["any"]:t}function s(n){for(var r=999,t=0;t<n.types.length;t++)c(n.types[t])&&(r=Math.min(r,n.types[t].typeIndex));return r}function l(n){for(var r=999,t=0;t<n.types.length;t++)c(n.types[t])||(r=Math.min(r,n.types[t].conversionIndex));return r}function _(n,r){var t,e,a,o,u,i=Math.min(n.params.length,r.params.length);if(0!=(e=n.params.some(Q)-r.params.some(Q)))return e;for(t=0;t<i;t++)if(0!=(e=Q(n.params[t])-Q(r.params[t])))return e;for(t=0;t<i;t++)if(a=n.params[t],o=r.params[t],u=void 0,0!==(e=0!=(u=a.restParam-o.restParam)?u:0!=(u=Q(a)-Q(o))?u:0!=(u=s(a)-s(o))?u:l(a)-l(o)))return e;return n.params.length-r.params.length}function nn(n){var r,t,e,a,o=[],u=[];switch(n.types.forEach(function(n){n.conversion&&(o.push(f(n.conversion.from).test),u.push(n.conversion.convert))}),u.length){case 0:return function(n){return n};case 1:return r=o[0],e=u[0],function(n){return r(n)?e(n):n};case 2:return r=o[0],t=o[1],e=u[0],a=u[1],function(n){return r(n)?e(n):t(n)?a(n):n};default:return function(n){for(var r=0;r<u.length;r++)if(o[r](n))return u[r](n);return n}}}function rn(n,s){return function r(t,e,a){if(e<t.length){var n,o=t[e],u=s?o.types.filter(c):o.types;if(o.restParam){var i=u.filter(c);n=i.length<u.length?[i,u]:[u]}else n=u.map(function(n){return[n]});return fn(n,function(n){return r(t,e+1,a.concat([n]))})}return[a.map(function(n,r){return{types:n,restParam:r===t.length-1&&K(t)}})]}(n,0,[])}function u(r,o){if(0===Object.keys(o).length)throw new SyntaxError("No signatures provided");var t=[];Object.keys(o).map(function(n){return t=o[r=n],a=B.conversions,e=[],""!==r.trim()&&(e=r.split(",").map(tn).map(function(n,r,t){var e=J(n,a);if(e.restParam&&r!==t.length-1)throw new SyntaxError('Unexpected rest parameter "'+n+'": only allowed for the last parameter');return e})),e.some(an)?null:{params:e,fn:t};var r,t,a,e}).filter(en).forEach(function(r){var n=sn(t,function(n){return function(n,r){for(var t=Math.max(n.params.length,r.params.length),e=0;e<t;e++)if(!un(Z(n,e,!0),Z(r,e,!0)))return!1;var a=n.params.length,o=r.params.length,u=K(n.params),i=K(r.params);return u?i?a===o:a<=o:i?o<=a:a===o}(n,r)});if(n)throw new TypeError('Conflicting signatures "'+H(n.params)+'" and "'+H(r.params)+'".');t.push(r)});var e=fn(t,function(r){return(r?rn(r.params,!1):[]).map(function(n){return{params:n,fn:r.fn}})}).filter(en);e.sort(_);var a,n=e[0]&&e[0].params.length<=2&&!K(e[0].params),u=e[1]&&e[1].params.length<=2&&!K(e[1].params),i=e[2]&&e[2].params.length<=2&&!K(e[2].params),s=e[3]&&e[3].params.length<=2&&!K(e[3].params),f=e[4]&&e[4].params.length<=2&&!K(e[4].params),p=e[5]&&e[5].params.length<=2&&!K(e[5].params),c=n&&u&&i&&s&&f&&p,l=e.map(function(n){return X(n.params)}),m=n?W(e[0].params[0]):pn,g=u?W(e[1].params[0]):pn,h=i?W(e[2].params[0]):pn,y=s?W(e[3].params[0]):pn,v=f?W(e[4].params[0]):pn,d=p?W(e[5].params[0]):pn,w=n?W(e[0].params[1]):pn,x=u?W(e[1].params[1]):pn,E=i?W(e[2].params[1]):pn,j=s?W(e[3].params[1]):pn,O=f?W(e[4].params[1]):pn,b=p?W(e[5].params[1]):pn,T=e.map(function(n){return function(n,e){var r=e;if(n.some(Q)){var a=K(n),o=n.map(nn);r=function(){for(var n=[],r=a?arguments.length-1:arguments.length,t=0;t<r;t++)n[t]=o[t](arguments[t]);return a&&(n[r]=arguments[r].map(o[r])),e.apply(null,n)}}var t=r;if(K(n)){var u=n.length-1;t=function(){return r.apply(null,on(arguments,0,u).concat([on(arguments,u)]))}}return t}(n.params,n.fn)}),P=n?T[0]:cn,A=u?T[1]:cn,F=i?T[2]:cn,M=s?T[3]:cn,k=f?T[4]:cn,I=p?T[5]:cn,C=n?e[0].params.length:-1,S=u?e[1].params.length:-1,D=i?e[2].params.length:-1,L=s?e[3].params.length:-1,U=f?e[4].params.length:-1,R=p?e[5].params.length:-1,V=c?6:0,N=e.length,q=function(){for(var n=V;n<N;n++)if(l[n](arguments))return T[n].apply(null,arguments);throw function(n,t,r){var e,a,o,u=n||"unnamed",i=r;for(o=0;o<t.length;o++){var s=i.filter(function(n){var r=W(Y(n,o));return(o<n.params.length||K(n.params))&&r(t[o])});if(0===s.length){if(0<(a=$(i,o)).length){var f=G(t[o]);return(e=new TypeError("Unexpected type of argument in function "+u+" (expected: "+a.join(" or ")+", actual: "+f+", index: "+o+")")).data={category:"wrongType",fn:u,index:o,actual:f,expected:a},e}}else i=s}var p=i.map(function(n){return K(n.params)?1/0:n.params.length});if(t.length<Math.min.apply(null,p))return a=$(i,o),(e=new TypeError("Too few arguments in function "+u+" (expected: "+a.join(" or ")+", index: "+t.length+")")).data={category:"tooFewArgs",fn:u,index:t.length,expected:a},e;var c=Math.max.apply(null,p);return t.length>c?(e=new TypeError("Too many arguments in function "+u+" (expected: "+c+", actual: "+t.length+")")).data={category:"tooManyArgs",fn:u,index:t.length,expectedLength:c}:(e=new TypeError('Arguments of type "'+t.join(", ")+'" do not match any of the defined signatures of function '+u+".")).data={category:"mismatch",actual:t.map(G)},e}(r,arguments,e)},z=function(n,r){return arguments.length===C&&m(n)&&w(r)?P.apply(null,arguments):arguments.length===S&&g(n)&&x(r)?A.apply(null,arguments):arguments.length===D&&h(n)&&E(r)?F.apply(null,arguments):arguments.length===L&&y(n)&&j(r)?M.apply(null,arguments):arguments.length===U&&v(n)&&O(r)?k.apply(null,arguments):arguments.length===R&&d(n)&&b(r)?I.apply(null,arguments):q.apply(null,arguments)};try{Object.defineProperty(z,"name",{value:r})}catch(n){}return z.signatures=(a={},e.forEach(function(r){r.params.some(Q)||rn(r.params,!0).forEach(function(n){a[H(n)]=r.fn})}),a),z}function m(n){return-1===B.ignore.indexOf(n)}function tn(n){return n.trim()}function g(n){return!!n}function en(n){return null!==n}function an(n){return 0===n.types.length}function i(n){return n[n.length-1]}function on(n,r,t){return Array.prototype.slice.call(n,r,t)}function un(n,r){for(var t=0;t<n.length;t++)if(e=r,a=n[t],-1!==e.indexOf(a))return!0;var e,a;return!1}function sn(n,r){for(var t=0;t<n.length;t++)if(r(n[t]))return n[t]}function fn(n,r){return Array.prototype.concat.apply([],n.map(r))}function h(n){for(var r="",t=0;t<n.length;t++){var e=n[t];if(("object"==typeof e.signatures||"string"==typeof e.signature)&&""!==e.name)if(""===r)r=e.name;else if(r!==e.name){var a=new Error("Function names do not match (expected: "+r+", actual: "+e.name+")");throw a.data={actual:e.name,expected:r},a}}return r}function y(n){var t,e={};function r(n,r){if(e.hasOwnProperty(n)&&r!==e[n])throw(t=new Error('Signature "'+n+'" is defined twice')).data={signature:n},t}for(var a=0;a<n.length;a++){var o=n[a];if("object"==typeof o.signatures)for(var u in o.signatures)o.signatures.hasOwnProperty(u)&&(r(u,o.signatures[u]),e[u]=o.signatures[u]);else{if("string"!=typeof o.signature)throw(t=new TypeError("Function is no typed-function (index: "+a+")")).data={index:a},t;r(o.signature,o),e[o.signature]=o}}return e}return(B=u("typed",{"string, Object":u,Object:function(n){var r=[];for(var t in n)n.hasOwnProperty(t)&&r.push(n[t]);return u(h(r),n)},"...Function":function(n){return u(h(n),y(n))},"string, ...Function":function(n,r){return u(n,y(r))}})).create=n,B.types=r,B.conversions=a,B.ignore=t,B.convert=function(n,r){var t=G(n);if(r===t)return n;for(var e=0;e<B.conversions.length;e++){var a=B.conversions[e];if(a.from===t&&a.to===r)return a.convert(n)}throw new Error("Cannot convert from "+t+" to "+r)},B.find=function(n,r){if(!n.signatures)throw new TypeError("Function is no typed-function");var t;if("string"==typeof r){t=r.split(",");for(var e=0;e<t.length;e++)t[e]=t[e].trim()}else{if(!Array.isArray(r))throw new TypeError("String array or a comma separated string expected");t=r}var a=t.join(","),o=n.signatures[a];if(o)return o;throw new TypeError("Signature not found (signature: "+(n.name||"unnamed")+"("+t.join(", ")+"))")},B.addType=function(n,r){if(!n||"string"!=typeof n.name||"function"!=typeof n.test)throw new TypeError("Object with properties {name: string, test: function} expected");if(!1!==r)for(var t=0;t<B.types.length;t++)if("Object"===B.types[t].name)return void B.types.splice(t,0,n);B.types.push(n)},B.addConversion=function(n){if(!n||"string"!=typeof n.from||"string"!=typeof n.to||"function"!=typeof n.convert)throw new TypeError("Object with properties {from: string, to: string, convert: function} expected");B.conversions.push(n)},B}()}); |
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
144612
2901