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.3 to 1.0.4

8

HISTORY.md
# History
## 2018-07-04, version 1.0.4
- By default, `addType` will insert new types before the `Object` test
since the `Object` test also matches arrays and classes.
- Upgraded `devDependencies`.
## 2018-03-17, version 1.0.3

@@ -4,0 +12,0 @@

6

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

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

"istanbul": "0.4.5",
"mocha": "5.0.1",
"mocha": "5.2.0",
"pad-right": "0.2.2",
"uglify-js": "3.3.11",
"uglify-js": "3.4.3",
"brace-expansion": "1.1.11"

@@ -30,0 +30,0 @@ },

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

- `typed.addType(type: {name: string, test: function})`
- `typed.addType(type: {name: string, test: function} [, beforeObjectTest=true])`

@@ -238,2 +238,8 @@ Add a new type. A type object contains a name and a test function.

```
By default, the new type will be inserted before the `Object` test
because the `Object` test also matches arrays and classes and hence
`typed-function` would never reach the new type. When `beforeObjectTest`
is `false`, the new type will be added at the end of all tests.

@@ -240,0 +246,0 @@ - `typed.addConversion(conversion: {from: string, to: string, convert: function}`

@@ -156,3 +156,3 @@ // test parse

it('should add a type using addType', function() {
it('should add a type using addType (before object)', function() {
var typed2 = typed.create();

@@ -168,7 +168,28 @@ function Person() {}

typed.addType(newType);
var objectEntry = typed2.types.find(function (entry) {
return entry.name === 'Object';
});
var objectIndex = typed2.types.indexOf(objectEntry);
assert.strictEqual(typed.types[typed.types.length - 1], newType);
typed2.addType(newType);
assert.strictEqual(typed2.types[objectIndex], newType);
});
it('should add a type using addType at the end (after Object)', function() {
var typed2 = typed.create();
function Person() {}
var newType = {
name: 'Person',
test: function (x) {
return x instanceof Person;
}
};
typed2.addType(newType, false);
assert.strictEqual(typed2.types[typed2.types.length - 1], newType);
});
it('should throw an error when passing an invalid type to addType', function() {

@@ -175,0 +196,0 @@ var typed2 = typed.create();

@@ -1338,4 +1338,11 @@ /**

// add a type
typed.addType = function (type) {
/**
* add a type
* @param {{name: string, test: function}} type
* @param {boolean} [beforeObjectTest=true]
* If true, the new test will be inserted before
* the test with name 'Object' (if any), since
* tests for Object match Array and classes too.
*/
typed.addType = function (type, beforeObjectTest) {
if (!type || typeof type.name !== 'string' || typeof type.test !== 'function') {

@@ -1345,2 +1352,11 @@ throw new TypeError('Object with properties {name: string, test: function} expected');

if (beforeObjectTest !== false) {
for (var i = 0; i < typed.types.length; i++) {
if (typed.types[i].name === 'Object') {
typed.types.splice(i, 0, type);
return
}
}
}
typed.types.push(type);

@@ -1347,0 +1363,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=R(f.types,function(r){return r.name===n});if(r)return r;if("any"===n)return o;var t=R(f.types,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=R(f.types,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)}(V(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 V(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=R(a,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=V(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,N=x?y(o[3].params[0]):r,q=E?y(o[4].params[0]):r,z=j?y(o[5].params[0]):r,B=i?y(o[0].params[1]):r,G=s?y(o[1].params[1]):r,H=p?y(o[2].params[1]):r,J=x?y(o[3].params[1]):r,K=E?y(o[4].params[1]):r,Q=j?y(o[5].params[1]):r,W=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)}),X=i?W[0]:t,Y=s?W[1]:t,Z=p?W[2]:t,$=x?W[3]:t,_=E?W[4]:t,nn=j?W[5]:t,rn=i?o[0].params.length:-1,tn=s?o[1].params.length:-1,en=p?o[2].params.length:-1,an=x?o[3].params.length:-1,on=E?o[4].params.length:-1,un=j?o[5].params.length:-1,fn=b?6:0,sn=o.length,pn=function(){for(var r=fn;r<sn;r++)if(M[r](arguments))return W[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)},cn=function(n,r){return arguments.length===rn&&k(n)&&B(r)?X.apply(null,arguments):arguments.length===tn&&I(n)&&G(r)?Y.apply(null,arguments):arguments.length===en&&D(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):arguments.length===un&&z(n)&&Q(r)?nn.apply(null,arguments):pn.apply(null,arguments)};try{Object.defineProperty(cn,"name",{value:n})}catch(n){}return cn.signatures=(u={},o.forEach(function(n){n.params.some(g)||A(n.params,!0).forEach(function(r){u[l(r)]=n.fn})}),u),cn}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){for(var t=0;t<n.length;t++)if(r(n[t]))return n[t]}function V(n,r){return Array.prototype.concat.apply([],n.map(r))}function N(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(N(r),n)},"...Function":function(n){for(var r,t=N(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 u(){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:u},t=[],a=[],B={types:r,conversions:a,ignore:t};function s(r){var n=fn(B.types,function(n){return n.name===r});if(n)return n;if("any"===r)return e;var t=fn(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=fn(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(h).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=s(n);return{name:n,typeIndex:p(r),test:r.test,conversion:null,conversionIndex:-1}}),f=u.map(function(n){var r=s(n.from);return{name:n.from,typeIndex:p(r),test:r.test,conversion:n,conversionIndex:t.indexOf(n)}});return{types:i.concat(f),restParam:a}}function K(n){var r=g(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 s(n.types[0].name).test;if(2===n.types.length){var r=s(n.types[0].name).test,t=s(n.types[1].name).test;return function(n){return r(n)||t(n)}}var e=n.types.map(function(n){return s(n.name).test});return function(n){for(var r=0;r<e.length;r++)if(e[r](n))return!0;return!1}}return u}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(g(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)?g(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)}(sn(n,function(n){return Z(n,r,!1)}));return-1!==t.indexOf("any")?["any"]:t}function f(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=f(a)-f(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(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 rn(n,f){return function r(t,e,a){if(e<t.length){var n,o=t[e],u=f?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 sn(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 i(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=fn(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=sn(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),f=e[3]&&e[3].params.length<=2&&!K(e[3].params),s=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&&f&&s&&p,l=e.map(function(n){return X(n.params)}),m=n?W(e[0].params[0]):pn,h=u?W(e[1].params[0]):pn,g=i?W(e[2].params[0]):pn,y=f?W(e[3].params[0]):pn,v=s?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,O=f?W(e[3].params[1]):pn,j=s?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,M=i?T[2]:cn,k=f?T[3]:cn,F=s?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=f?e[3].params.length:-1,U=s?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 f=i.filter(function(n){var r=W(Y(n,o));return(o<n.params.length||K(n.params))&&r(t[o])});if(0===f.length){if(0<(a=$(i,o)).length){var s=G(t[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 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&&h(n)&&x(r)?A.apply(null,arguments):arguments.length===D&&g(n)&&E(r)?M.apply(null,arguments):arguments.length===L&&y(n)&&O(r)?k.apply(null,arguments):arguments.length===U&&v(n)&&j(r)?F.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 h(n){return!!n}function en(n){return null!==n}function an(n){return 0===n.types.length}function g(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 fn(n,r){for(var t=0;t<n.length;t++)if(r(n[t]))return n[t]}function sn(n,r){return Array.prototype.concat.apply([],n.map(r))}function y(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(B=i("typed",{"string, Object":i,Object:function(n){var r=[];for(var t in n)n.hasOwnProperty(t)&&r.push(n[t]);return i(y(r),n)},"...Function":function(n){for(var r,t=y(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 i(t,e)}})).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}()});

Sorry, the diff of this file is not supported yet

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