!function(a,b,c){"undefined"!=typeof module&&module.exports?module.exports=c():"function"==typeof define&&define.amd?define(c):b[a]=c()}("Args",this,function(){"use strict";var a=function(a){var b={};b.defValue=void 0,b.typeValue=void 0,b.customCheck=void 0;for(var c in a)a.hasOwnProperty(c)&&("_default"===c?b.defValue=a[c]:"_type"===c?b.typeValue=a[c]:"_check"===c?b.customCheck=a[c]:b.sname=c);if(b.sarg=a[b.sname],"object"==typeof b.customCheck&&b.customCheck instanceof RegExp){var d=b.customCheck;b.customCheck=function(a){return!!a.toString().match(d)}}return b},b=function(a,b){var c=!1;return 0!==(b.sarg&j.ANY)?c=!0:0!==(b.sarg&j.STRING)&&"string"==typeof a?c=!0:0!==(b.sarg&j.FUNCTION)&&"function"==typeof a?c=!0:0!==(b.sarg&j.INT)&&"number"==typeof a&&Math.floor(a)===a?c=!0:0!==(b.sarg&j.FLOAT)&&"number"==typeof a?c=!0:0!==(b.sarg&j.ARRAY)&&a instanceof Array?c=!0:0===(b.sarg&j.OBJECT)&&void 0===b.typeValue||"object"!=typeof a||!(void 0===b.typeValue||a instanceof b.typeValue)?0!==(b.sarg&j.ARRAY_BUFFER)&&a.toString().match(/ArrayBuffer/)?c=!0:0!==(b.sarg&j.DATE)&&a instanceof Date?c=!0:0!==(b.sarg&j.BOOL)&&"boolean"==typeof a?c=!0:0!==(b.sarg&j.DOM_EL)&&(a instanceof HTMLElement||void 0!==window.$&&a instanceof window.$)&&(c=!0):c=!0,void 0!==b.customCheck&&"function"==typeof b.customCheck&&(c=b.customCheck(a)?!0:!1),c},c=function(a){return 0!=(a.sarg&(j.ANY|j.STRING|j.FUNCTION|j.INT|j.FLOAT|j.OBJECT|j.ARRAY_BUFFER|j.DATE|j.BOOL|j.DOM_EL|j.ARRAY))||void 0!==a.typeValue},d=function(a){var b=a.sarg,c=a.typeValue,d=a.customCheck;return 0!==(b&j.STRING)?"String":0!==(b&j.FUNCTION)?"Function":0!==(b&j.INT)?"Int":0!==(b&j.FLOAT)?"Float":0!==(b&j.ARRAY)?"Array":0!==(b&j.OBJECT)?void 0!==c?"Object ("+c.toString()+")":"Object":0!==(b&j.ARRAY_BUFFER)?"Arry Buffer":0!==(b&j.DATE)?"Date":0!==(b&j.BOOL)?"Bool":0!==(b&j.DOM_EL)?"DOM Element":void 0!==d?"[Custom checker]":"unknown"},e=function(c,d,e){for(var f=!1,g=0;g<d.length;g++){var h=function(a){var d=!1;for(var f in c){var g=c[f];if(f===a.sname&&b(g,a)){e[f]=g,d=!0;break}}return d}(a(d[g]));h&&d.splice(g--,1),f|=h}return f},f=function(a,b){return a&&b?(a.sarg&~(j.Optional|j.Required))===(b.sarg&~(j.Optional|j.Required))&&a.typeValue===b.typeValue:!1},g=function(a){return!h(a)},h=function(a){return 0!==(a&j.Optional)},i=function(a,b,e){var f="";if(c(a))f="Argument "+b+" ("+a.sname+") should be type "+d(a)+", but it was type "+typeof e+" with value "+e+".";else if(void 0!==a.customCheck){var g=a.customCheck.toString();g.length>50&&(g=g.substr(0,40)+"..."+g.substr(g.length-10)),f="Argument "+b+" ("+a.sname+") does not pass the custom check ("+g+")."}else f="Argument "+b+" ("+a.sname+") has no valid type specified.";return f},j=function(k,l){if(void 0===k)throw new Error("The scheme has not been passed.");if(void 0===l)throw new Error("The arguments have not been passed.");l=Array.prototype.slice.call(l,0);var m,n,o={},p=void 0,q=void 0,r=[],s=function(a){(!q||!f(q,a)||g(q.sarg)&&h(a.sarg))&&(r=[]),(r.length>0||h(a.sarg))&&(q=a,r.push(a))},t=function(a,c,d){if(void 0===d&&(d=r.length-1),!(0>d)){var e=r[d],f=o[e.sname];return b(f,a)?(o[a.sname]=f,o[e.sname]=e.defValue||void 0,0===(e.sarg&j.Optional)&&t(e,c,d-1),void 0):i(a,c,f)}};for("object"==typeof l[l.length-1]&&e(l[l.length-1],k,o)&&l.splice(l.length-1,1),m=0,n=0;n<k.length&&(m=function(e,g){var h=l[e];if(k[g]instanceof Array){if(null===h||void 0===h)return p="Argument "+e+" is null or undefined but it must be not null.",e;for(var m=k[g],n=void 0,r=0;r<m.length;r++){var u=a(m[r]);b(h,u)&&(n=u.sname)}if(void 0===n){p="Argument "+e+" should be one of: ";for(var r=0;r<m.length;r++){var u=a(m[r]);p+=d(u)+", "}return p+="but it was type "+typeof h+" with value "+h+".",e}return o[n]=h,e+1}var u=a(k[g]);if(0===(u.sarg&j.Optional)){if(null===h||void 0===h)return c(u)&&f(u,q)?(p=t(u,e),""===p&&s(u),e):(p="Argument "+e+" ("+u.sname+") is null or undefined but it must be not null.",e);if(b(h,u))return o[u.sname]=h,s(u),e+1;if(c(u)&&f(u,q)){if(p=t(u,e),""===p)return s(u),e+1}else p=i(u,e,h);return e}return null===h||void 0===h?(void 0!==u.defValue?o[u.sname]=u.defValue:o[u.sname]=h,e+1):b(h,u)?(o[u.sname]=h,s(u),e+1):void 0!==u.defValue?(o[u.sname]=u.defValue,e):e}(m,n),!p);n++);if(p)throw new Error(p);return o};return j.ANY=1,j.STRING=2,j.FUNCTION=4,j.INT=8,j.FLOAT=16,j.ARRAY_BUFFER=32,j.OBJECT=64,j.DATE=128,j.BOOL=256,j.DOM_EL=512,j.ARRAY=1024,j.Optional=2048,j.NotNull=j.Required=4096,j});
//# sourceMappingURL=Args.min.map