Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typed-function

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-function - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

9

HISTORY.md
# History
## 2018-03-17, version 1.0.2
- Fixed typed-function not working on browsers that don't allow
setting the `name` property of a function.
## 2018-02-21, version 1.0.1

@@ -21,3 +27,6 @@

In version 1.0.0, support for browsers like IE9, IE10 is dropped,
though typed-function can still work when using es5 and es6 polyfills.
## 2018-01-24, version 0.10.7

@@ -24,0 +33,0 @@

2

package.json
{
"name": "typed-function",
"version": "1.0.1",
"version": "1.0.2",
"description": "Type checking for JavaScript functions",

@@ -5,0 +5,0 @@ "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",

@@ -18,3 +18,3 @@ # typed-function

Supported environments: node.js, Chrome, Firefox, Safari, Opera, IE9+.
Supported environments: node.js, Chrome, Firefox, Safari, Opera, IE11+.

@@ -324,3 +324,3 @@

### Version 1
### Version 2

@@ -335,3 +335,3 @@ - Be able to turn off exception throwing.

### Version 2
### Version 3

@@ -338,0 +338,0 @@ - Extend function signatures:

@@ -1095,4 +1095,13 @@ /**

// attach name and signatures to the typed function
Object.defineProperty(fn, 'name', {value: name});
// attach name the typed function
try {
Object.defineProperty(fn, 'name', {value: name});
}
catch (err) {
// old browsers do not support Object.defineProperty and some don't support setting the name property
// the function name is not essential for the functioning, it's mostly useful for debugging,
// so it's fine to have unnamed functions.
}
// attach signatures to the function
fn.signatures = createSignaturesMap(signatures);

@@ -1099,0 +1108,0 @@

@@ -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 n(){return!0}function r(){return!1}function t(){}return function e(){var a=[{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}}],o={name:"any",test:n},u=[],i=[],f={types:a,conversions:i,ignore:u};function s(n){var r=f.types.find(function(r){return r.name===n});if(r)return r;if("any"===n)return o;var t=f.types.find(function(r){return r.name.toLowerCase()===n.toLowerCase()});throw new TypeError('Unknown type "'+n+'"'+(t?'. Did you mean "'+t.name+'"?':""))}function p(n){return n===o?999:f.types.indexOf(n)}function c(n){var r=f.types.find(function(r){return r.test(n)});if(r)return r.name;throw new TypeError("Value has unknown type. Value: "+n)}function l(n){return n.map(function(n){var r=n.types.map(x);return(n.restParam?"...":"")+r.join("|")}).join(",")}function m(n,r){var t,e,a=0===n.indexOf("..."),o=(a?n.length>3?n.slice(3):"any":n).split("|").map(F).filter(I).filter(k),u=(t=o,e={},r.forEach(function(n){-1!==t.indexOf(n.from)||-1===t.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=s(n);return{name:n,typeIndex:p(r),test:r.test,conversion:null,conversionIndex:-1}}),f=u.map(function(n){var t=s(n.from);return{name:n.from,typeIndex:p(t),test:t.test,conversion:n,conversionIndex:r.indexOf(n)}});return{types:i.concat(f),restParam:a}}function g(n){var r=D(n);return!!r&&r.restParam}function h(n){return n.types.some(function(n){return null!=n.conversion})}function y(r){if(r&&0!==r.types.length){if(1===r.types.length)return s(r.types[0].name).test;if(2===r.types.length){var t=s(r.types[0].name).test,e=s(r.types[1].name).test;return function(n){return t(n)||e(n)}}var a=r.types.map(function(n){return s(n.name).test});return function(n){for(var r=0;r<a.length;r++)if(a[r](n))return!0;return!1}}return n}function v(n){var r,t,e,a;if(g(n)){var o=(r=(a=n,a.slice(0,a.length-1)).map(y)).length,u=y(D(n));return function(n){for(var t=0;t<r.length;t++)if(!r[t](n[t]))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?(t=y(n[0]),function(n){return t(n[0])&&1===n.length}):2===n.length?(t=y(n[0]),e=y(n[1]),function(n){return t(n[0])&&e(n[1])&&2===n.length}):(r=n.map(y),function(n){for(var t=0;t<r.length;t++)if(!r[t](n[t]))return!1;return n.length===r.length})}function d(n,r){return r<n.params.length?n.params[r]:g(n.params)?D(n.params):null}function w(n,r,t){var e=d(n,r);return(e?t?e.types.filter(E):e.types:[]).map(x)}function x(n){return n.name}function E(n){return null===n.conversion||void 0===n.conversion}function O(n,r){var t=function(n){for(var r={},t=0;t<n.length;t++)r[n[t]]=!0;return Object.keys(r)}(R(n,function(n){return w(n,r,!1)}));return-1!==t.indexOf("any")?["any"]:t}function j(n){for(var r=999,t=0;t<n.types.length;t++)E(n.types[t])&&(r=Math.min(r,n.types[t].typeIndex));return r}function b(n){for(var r=999,t=0;t<n.types.length;t++)E(n.types[t])||(r=Math.min(r,n.types[t].conversionIndex));return r}function T(n,r){var t,e,a,o,u,i=Math.min(n.params.length,r.params.length);if(0!=(e=n.params.some(h)-r.params.some(h)))return e;for(t=0;t<i;t++)if(0!=(e=h(n.params[t])-h(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=h(a)-h(o))?u:0!=(u=j(a)-j(o))?u:b(a)-b(o)))return e;return n.params.length-r.params.length}function P(n){var r,t,e,a,o=[],u=[];switch(n.types.forEach(function(n){n.conversion&&(o.push(s(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 A(n,r){return function n(t,e,a){if(e<t.length){var o,u=t[e],i=r?u.types.filter(E):u.types;if(u.restParam){var f=i.filter(E);o=f.length<i.length?[f,i]:[i]}else o=i.map(function(n){return[n]});return R(o,function(r){return n(t,e+1,a.concat([r]))})}return[a.map(function(n,r){return{types:n,restParam:r===t.length-1&&g(t)}})]}(n,0,[])}function M(n,e){if(0===Object.keys(e).length)throw new SyntaxError("No signatures provided");var a=[];Object.keys(e).map(function(n){return r=n,t=e[n],a=f.conversions,o=[],""!==r.trim()&&(o=r.split(",").map(F).map(function(n,r,t){var e=m(n,a);if(e.restParam&&r!==t.length-1)throw new SyntaxError('Unexpected rest parameter "'+n+'": only allowed for the last parameter');return e})),o.some(S)?null:{params:o,fn:t};var r,t,a,o}).filter(C).forEach(function(n){var r=a.find(function(r){return function(n,r){for(var t=Math.max(n.params.length,r.params.length),e=0;e<t;e++)if(!U(w(n,e,!0),w(r,e,!0)))return!1;var a=n.params.length,o=r.params.length,u=g(n.params),i=g(r.params);return u?i?a===o:o>=a:i?a>=o:a===o}(r,n)});if(r)throw new TypeError('Conflicting signatures "'+l(r.params)+'" and "'+l(n.params)+'".');a.push(n)});var o=R(a,function(n){return(n?A(n.params,!1):[]).map(function(r){return{params:r,fn:n.fn}})}).filter(C);o.sort(T);var u,i=o[0]&&o[0].params.length<=2&&!g(o[0].params),s=o[1]&&o[1].params.length<=2&&!g(o[1].params),p=o[2]&&o[2].params.length<=2&&!g(o[2].params),x=o[3]&&o[3].params.length<=2&&!g(o[3].params),E=o[4]&&o[4].params.length<=2&&!g(o[4].params),j=o[5]&&o[5].params.length<=2&&!g(o[5].params),b=i&&s&&p&&x&&E&&j,M=o.map(function(n){return v(n.params)}),k=i?y(o[0].params[0]):r,I=s?y(o[1].params[0]):r,D=p?y(o[2].params[0]):r,V=x?y(o[3].params[0]):r,N=E?y(o[4].params[0]):r,q=j?y(o[5].params[0]):r,z=i?y(o[0].params[1]):r,B=s?y(o[1].params[1]):r,G=p?y(o[2].params[1]):r,H=x?y(o[3].params[1]):r,J=E?y(o[4].params[1]):r,K=j?y(o[5].params[1]):r,Q=o.map(function(n){return function(n,r){var t=r;if(n.some(h)){var e=g(n),a=n.map(P);t=function(){for(var n=[],t=e?arguments.length-1:arguments.length,o=0;o<t;o++)n[o]=a[o](arguments[o]);return e&&(n[t]=arguments[t].map(a[t])),r.apply(null,n)}}var o=t;if(g(n)){var u=n.length-1;o=function(){return t.apply(null,L(arguments,0,u).concat([L(arguments,u)]))}}return o}(n.params,n.fn)}),W=i?Q[0]:t,X=s?Q[1]:t,Y=p?Q[2]:t,Z=x?Q[3]:t,$=E?Q[4]:t,_=j?Q[5]:t,nn=i?o[0].params.length:-1,rn=s?o[1].params.length:-1,tn=p?o[2].params.length:-1,en=x?o[3].params.length:-1,an=E?o[4].params.length:-1,on=j?o[5].params.length:-1,un=b?6:0,fn=o.length,sn=function(){for(var r=un;r<fn;r++)if(M[r](arguments))return Q[r].apply(null,arguments);throw function(n,r,t){var e,a,o,u=n||"unnamed",i=t;for(o=0;o<r.length;o++){var f=i.filter(function(n){var t=y(d(n,o));return(o<n.params.length||g(n.params))&&t(r[o])});if(0===f.length){if((a=O(i,o)).length>0){var s=c(r[o]);return(e=new TypeError("Unexpected type of argument in function "+u+" (expected: "+a.join(" or ")+", actual: "+s+", index: "+o+")")).data={category:"wrongType",fn:u,index:o,actual:s,expected:a},e}}else i=f}var p=i.map(function(n){return g(n.params)?1/0:n.params.length});if(r.length<Math.min.apply(null,p))return a=O(i,o),(e=new TypeError("Too few arguments in function "+u+" (expected: "+a.join(" or ")+", index: "+r.length+")")).data={category:"tooFewArgs",fn:u,index:r.length,expected:a},e;var l=Math.max.apply(null,p);return r.length>l?((e=new TypeError("Too many arguments in function "+u+" (expected: "+l+", actual: "+r.length+")")).data={category:"tooManyArgs",fn:u,index:r.length,expectedLength:l},e):((e=new TypeError('Arguments of type "'+r.join(", ")+'" do not match any of the defined signatures of function '+u+".")).data={category:"mismatch",actual:r.map(c)},e)}(n,arguments,o)},pn=function(n,r){return arguments.length===nn&&k(n)&&z(r)?W.apply(null,arguments):arguments.length===rn&&I(n)&&B(r)?X.apply(null,arguments):arguments.length===tn&&D(n)&&G(r)?Y.apply(null,arguments):arguments.length===en&&V(n)&&H(r)?Z.apply(null,arguments):arguments.length===an&&N(n)&&J(r)?$.apply(null,arguments):arguments.length===on&&q(n)&&K(r)?_.apply(null,arguments):sn.apply(null,arguments)};return Object.defineProperty(pn,"name",{value:n}),pn.signatures=(u={},o.forEach(function(n){n.params.some(h)||A(n.params,!0).forEach(function(r){u[l(r)]=n.fn})}),u),pn}function k(n){return-1===f.ignore.indexOf(n)}function F(n){return n.trim()}function I(n){return!!n}function C(n){return null!==n}function S(n){return 0===n.types.length}function D(n){return n[n.length-1]}function L(n,r,t){return Array.prototype.slice.call(n,r,t)}function U(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 R(n,r){return Array.prototype.concat.apply([],n.map(r))}function V(n){for(var r="",t=0;t<n.length;t++){var e=n[t];if(e.signatures&&""!==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}return(f=M("typed",{"string, Object":M,Object:function(n){var r=[];for(var t in n)n.hasOwnProperty(t)&&r.push(n[t]);return M(V(r),n)},"...Function":function(n){for(var r,t=V(n),e={},a=0;a<n.length;a++){var o=n[a];if("object"!=typeof o.signatures)throw(r=new TypeError("Function is no typed-function (index: "+a+")")).data={index:a},r;for(var u in o.signatures)if(o.signatures.hasOwnProperty(u))if(e.hasOwnProperty(u)){if(o.signatures[u]!==e[u])throw(r=new Error('Signature "'+u+'" is defined twice')).data={signature:u},r}else e[u]=o.signatures[u]}return M(t,e)}})).create=e,f.types=a,f.conversions=i,f.ignore=u,f.convert=function(n,r){var t=c(n);if(r===t)return n;for(var e=0;e<f.conversions.length;e++){var a=f.conversions[e];if(a.from===t&&a.to===r)return a.convert(n)}throw new Error("Cannot convert from "+t+" to "+r)},f.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(", ")+"))")},f.addType=function(n){if(!n||"string"!=typeof n.name||"function"!=typeof n.test)throw new TypeError("Object with properties {name: string, test: function} expected");f.types.push(n)},f.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");f.conversions.push(n)},f}()});
"use strict";!function(n,r){"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?module.exports=r():n.typed=r()}(this,function(){function n(){return!0}function r(){return!1}function t(){}return function e(){var a=[{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}}],o={name:"any",test:n},u=[],i=[],f={types:a,conversions:i,ignore:u};function s(n){var r=f.types.find(function(r){return r.name===n});if(r)return r;if("any"===n)return o;var t=f.types.find(function(r){return r.name.toLowerCase()===n.toLowerCase()});throw new TypeError('Unknown type "'+n+'"'+(t?'. Did you mean "'+t.name+'"?':""))}function p(n){return n===o?999:f.types.indexOf(n)}function c(n){var r=f.types.find(function(r){return r.test(n)});if(r)return r.name;throw new TypeError("Value has unknown type. Value: "+n)}function l(n){return n.map(function(n){var r=n.types.map(x);return(n.restParam?"...":"")+r.join("|")}).join(",")}function m(n,r){var t,e,a=0===n.indexOf("..."),o=(a?n.length>3?n.slice(3):"any":n).split("|").map(F).filter(I).filter(k),u=(t=o,e={},r.forEach(function(n){-1!==t.indexOf(n.from)||-1===t.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=s(n);return{name:n,typeIndex:p(r),test:r.test,conversion:null,conversionIndex:-1}}),f=u.map(function(n){var t=s(n.from);return{name:n.from,typeIndex:p(t),test:t.test,conversion:n,conversionIndex:r.indexOf(n)}});return{types:i.concat(f),restParam:a}}function h(n){var r=D(n);return!!r&&r.restParam}function g(n){return n.types.some(function(n){return null!=n.conversion})}function y(r){if(r&&0!==r.types.length){if(1===r.types.length)return s(r.types[0].name).test;if(2===r.types.length){var t=s(r.types[0].name).test,e=s(r.types[1].name).test;return function(n){return t(n)||e(n)}}var a=r.types.map(function(n){return s(n.name).test});return function(n){for(var r=0;r<a.length;r++)if(a[r](n))return!0;return!1}}return n}function v(n){var r,t,e,a;if(h(n)){var o=(r=(a=n,a.slice(0,a.length-1)).map(y)).length,u=y(D(n));return function(n){for(var t=0;t<r.length;t++)if(!r[t](n[t]))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?(t=y(n[0]),function(n){return t(n[0])&&1===n.length}):2===n.length?(t=y(n[0]),e=y(n[1]),function(n){return t(n[0])&&e(n[1])&&2===n.length}):(r=n.map(y),function(n){for(var t=0;t<r.length;t++)if(!r[t](n[t]))return!1;return n.length===r.length})}function d(n,r){return r<n.params.length?n.params[r]:h(n.params)?D(n.params):null}function w(n,r,t){var e=d(n,r);return(e?t?e.types.filter(E):e.types:[]).map(x)}function x(n){return n.name}function E(n){return null===n.conversion||void 0===n.conversion}function O(n,r){var t=function(n){for(var r={},t=0;t<n.length;t++)r[n[t]]=!0;return Object.keys(r)}(R(n,function(n){return w(n,r,!1)}));return-1!==t.indexOf("any")?["any"]:t}function j(n){for(var r=999,t=0;t<n.types.length;t++)E(n.types[t])&&(r=Math.min(r,n.types[t].typeIndex));return r}function b(n){for(var r=999,t=0;t<n.types.length;t++)E(n.types[t])||(r=Math.min(r,n.types[t].conversionIndex));return r}function T(n,r){var t,e,a,o,u,i=Math.min(n.params.length,r.params.length);if(0!=(e=n.params.some(g)-r.params.some(g)))return e;for(t=0;t<i;t++)if(0!=(e=g(n.params[t])-g(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=g(a)-g(o))?u:0!=(u=j(a)-j(o))?u:b(a)-b(o)))return e;return n.params.length-r.params.length}function P(n){var r,t,e,a,o=[],u=[];switch(n.types.forEach(function(n){n.conversion&&(o.push(s(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 A(n,r){return function n(t,e,a){if(e<t.length){var o,u=t[e],i=r?u.types.filter(E):u.types;if(u.restParam){var f=i.filter(E);o=f.length<i.length?[f,i]:[i]}else o=i.map(function(n){return[n]});return R(o,function(r){return n(t,e+1,a.concat([r]))})}return[a.map(function(n,r){return{types:n,restParam:r===t.length-1&&h(t)}})]}(n,0,[])}function M(n,e){if(0===Object.keys(e).length)throw new SyntaxError("No signatures provided");var a=[];Object.keys(e).map(function(n){return r=n,t=e[n],a=f.conversions,o=[],""!==r.trim()&&(o=r.split(",").map(F).map(function(n,r,t){var e=m(n,a);if(e.restParam&&r!==t.length-1)throw new SyntaxError('Unexpected rest parameter "'+n+'": only allowed for the last parameter');return e})),o.some(S)?null:{params:o,fn:t};var r,t,a,o}).filter(C).forEach(function(n){var r=a.find(function(r){return function(n,r){for(var t=Math.max(n.params.length,r.params.length),e=0;e<t;e++)if(!U(w(n,e,!0),w(r,e,!0)))return!1;var a=n.params.length,o=r.params.length,u=h(n.params),i=h(r.params);return u?i?a===o:o>=a:i?a>=o:a===o}(r,n)});if(r)throw new TypeError('Conflicting signatures "'+l(r.params)+'" and "'+l(n.params)+'".');a.push(n)});var o=R(a,function(n){return(n?A(n.params,!1):[]).map(function(r){return{params:r,fn:n.fn}})}).filter(C);o.sort(T);var u,i=o[0]&&o[0].params.length<=2&&!h(o[0].params),s=o[1]&&o[1].params.length<=2&&!h(o[1].params),p=o[2]&&o[2].params.length<=2&&!h(o[2].params),x=o[3]&&o[3].params.length<=2&&!h(o[3].params),E=o[4]&&o[4].params.length<=2&&!h(o[4].params),j=o[5]&&o[5].params.length<=2&&!h(o[5].params),b=i&&s&&p&&x&&E&&j,M=o.map(function(n){return v(n.params)}),k=i?y(o[0].params[0]):r,I=s?y(o[1].params[0]):r,D=p?y(o[2].params[0]):r,V=x?y(o[3].params[0]):r,N=E?y(o[4].params[0]):r,q=j?y(o[5].params[0]):r,z=i?y(o[0].params[1]):r,B=s?y(o[1].params[1]):r,G=p?y(o[2].params[1]):r,H=x?y(o[3].params[1]):r,J=E?y(o[4].params[1]):r,K=j?y(o[5].params[1]):r,Q=o.map(function(n){return function(n,r){var t=r;if(n.some(g)){var e=h(n),a=n.map(P);t=function(){for(var n=[],t=e?arguments.length-1:arguments.length,o=0;o<t;o++)n[o]=a[o](arguments[o]);return e&&(n[t]=arguments[t].map(a[t])),r.apply(null,n)}}var o=t;if(h(n)){var u=n.length-1;o=function(){return t.apply(null,L(arguments,0,u).concat([L(arguments,u)]))}}return o}(n.params,n.fn)}),W=i?Q[0]:t,X=s?Q[1]:t,Y=p?Q[2]:t,Z=x?Q[3]:t,$=E?Q[4]:t,_=j?Q[5]:t,nn=i?o[0].params.length:-1,rn=s?o[1].params.length:-1,tn=p?o[2].params.length:-1,en=x?o[3].params.length:-1,an=E?o[4].params.length:-1,on=j?o[5].params.length:-1,un=b?6:0,fn=o.length,sn=function(){for(var r=un;r<fn;r++)if(M[r](arguments))return Q[r].apply(null,arguments);throw function(n,r,t){var e,a,o,u=n||"unnamed",i=t;for(o=0;o<r.length;o++){var f=i.filter(function(n){var t=y(d(n,o));return(o<n.params.length||h(n.params))&&t(r[o])});if(0===f.length){if((a=O(i,o)).length>0){var s=c(r[o]);return(e=new TypeError("Unexpected type of argument in function "+u+" (expected: "+a.join(" or ")+", actual: "+s+", index: "+o+")")).data={category:"wrongType",fn:u,index:o,actual:s,expected:a},e}}else i=f}var p=i.map(function(n){return h(n.params)?1/0:n.params.length});if(r.length<Math.min.apply(null,p))return a=O(i,o),(e=new TypeError("Too few arguments in function "+u+" (expected: "+a.join(" or ")+", index: "+r.length+")")).data={category:"tooFewArgs",fn:u,index:r.length,expected:a},e;var l=Math.max.apply(null,p);return r.length>l?((e=new TypeError("Too many arguments in function "+u+" (expected: "+l+", actual: "+r.length+")")).data={category:"tooManyArgs",fn:u,index:r.length,expectedLength:l},e):((e=new TypeError('Arguments of type "'+r.join(", ")+'" do not match any of the defined signatures of function '+u+".")).data={category:"mismatch",actual:r.map(c)},e)}(n,arguments,o)},pn=function(n,r){return arguments.length===nn&&k(n)&&z(r)?W.apply(null,arguments):arguments.length===rn&&I(n)&&B(r)?X.apply(null,arguments):arguments.length===tn&&D(n)&&G(r)?Y.apply(null,arguments):arguments.length===en&&V(n)&&H(r)?Z.apply(null,arguments):arguments.length===an&&N(n)&&J(r)?$.apply(null,arguments):arguments.length===on&&q(n)&&K(r)?_.apply(null,arguments):sn.apply(null,arguments)};try{Object.defineProperty(pn,"name",{value:n})}catch(n){}return pn.signatures=(u={},o.forEach(function(n){n.params.some(g)||A(n.params,!0).forEach(function(r){u[l(r)]=n.fn})}),u),pn}function k(n){return-1===f.ignore.indexOf(n)}function F(n){return n.trim()}function I(n){return!!n}function C(n){return null!==n}function S(n){return 0===n.types.length}function D(n){return n[n.length-1]}function L(n,r,t){return Array.prototype.slice.call(n,r,t)}function U(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 R(n,r){return Array.prototype.concat.apply([],n.map(r))}function V(n){for(var r="",t=0;t<n.length;t++){var e=n[t];if(e.signatures&&""!==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}return(f=M("typed",{"string, Object":M,Object:function(n){var r=[];for(var t in n)n.hasOwnProperty(t)&&r.push(n[t]);return M(V(r),n)},"...Function":function(n){for(var r,t=V(n),e={},a=0;a<n.length;a++){var o=n[a];if("object"!=typeof o.signatures)throw(r=new TypeError("Function is no typed-function (index: "+a+")")).data={index:a},r;for(var u in o.signatures)if(o.signatures.hasOwnProperty(u))if(e.hasOwnProperty(u)){if(o.signatures[u]!==e[u])throw(r=new Error('Signature "'+u+'" is defined twice')).data={signature:u},r}else e[u]=o.signatures[u]}return M(t,e)}})).create=e,f.types=a,f.conversions=i,f.ignore=u,f.convert=function(n,r){var t=c(n);if(r===t)return n;for(var e=0;e<f.conversions.length;e++){var a=f.conversions[e];if(a.from===t&&a.to===r)return a.convert(n)}throw new Error("Cannot convert from "+t+" to "+r)},f.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(", ")+"))")},f.addType=function(n){if(!n||"string"!=typeof n.name||"function"!=typeof n.test)throw new TypeError("Object with properties {name: string, test: function} expected");f.types.push(n)},f.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");f.conversions.push(n)},f}()});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc