text: "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}()});