@andrewcaires/utils.js 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * @andrewcaires/utils.js v0.2.5
3
+ * JavaScript utility library for web and nodejs development
4
+ * (c) 2022 Andrew Caires
5
+ * @license: MIT
6
+ */
7
+ "use strict";var t={},n=function(t){return"array"==s(t)},r=function(t){return"boolean"==s(t)},e=function(t){return"null"!=s(t)},u=function(t){return"number"==s(t)},i=function(t){return"object"==s(t)},o=function(t){return"string"==s(t)},a=function(t){return void 0===t},s=function(n){return null==n?"null":t[t.toString.call(n)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(n){return t["[object "+n+"]"]=n.toLowerCase()}));var c=function(t,n,r){return Math.max(n,Math.min(r,t))},l=function(t,n){return(r=parseInt(t,16)+n,c(r,0,255)).toString(16);var r},p=function(t){return Math.random().toString(16).slice(t)},f=function(){return p(-3)},h=function(){return p(-4)},v=function(){return h()+h()},y=function(){return v()+v()},m=function(){function t(){this.events=new Map}return t.prototype.on=function(t,n){var r=this,e=this.events.get(t);return e?e.push(n):this.events.set(t,[n]),{dispose:function(){return r.off(t,n)}}},t.prototype.once=function(t,n){var r=this,e=function(u){n(u),r.off(t,e)};return this.on(t,e),{dispose:function(){return r.off(t,e)}}},t.prototype.off=function(t,n){var r=this.events.get(t);if(n){if(r){var e=r.indexOf(n);e>=0&&r.splice(e,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,n){var r=this.events.get(t);r&&r.forEach((function(t){return t(n)}))},t}(),d=function(t,n,r){for(var e=0;e<t.length&&!1!==n.call(r,t[e],e,t);e++);return t},x=function(t,n,r){for(var e="",u=Object.keys(t),i=0;i<u.length&&(e=u[i],!1!==n.call(r,t[e],e,t));i++);return t},g=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},_=function(t){return g(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},b=_,w=function(t){return g(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,r){return n.toUpperCase()+r}))}))},k=function(t){return t.split("").reverse().join("")},C=function(t){return/^[A-Za-z]$/.test(t)},j=function(t,n,r){r.mask++,r.text++;var e=t[r.mask],u=n[r.text];return a(e)||a(u)?"":function(t,n,r){switch(t.toUpperCase()){case"#":return n;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(n)?n:(r.mask--,"");case"A":case"Z":return C(n)?n:(r.mask--,"");case"L":return C(n)?n.toLowerCase():(r.mask--,"");case"U":return C(n)?n.toUpperCase():(r.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(n)?n:(r.mask--,"");default:return t!=n&&r.text--,t}}(e,u,r)+j(t,n,r)},O=function(t,n){return j(t,n,{mask:-1,text:-1})},S=O,A=function(t,n){return k(S(k(t),k(n)))},E=function(t,n){return E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])},E(t,n)};function M(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}E(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var F=function(){return F=Object.assign||function(t){for(var n,r=1,e=arguments.length;r<e;r++)for(var u in n=arguments[r])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t},F.apply(this,arguments)};function I(t,n,r,e){return new(r||(r=Promise))((function(u,i){function o(t){try{s(e.next(t))}catch(t){i(t)}}function a(t){try{s(e.throw(t))}catch(t){i(t)}}function s(t){var n;t.done?u(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(o,a)}s((e=e.apply(t,n||[])).next())}))}function U(t,n){var r,e,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(o=0)),o;)try{if(r=1,e&&(u=2&a[0]?e.return:a[0]?e.throw||((u=e.return)&&u.call(e),0):e.next)&&!(u=u.call(e,a[1])).done)return u;switch(e=0,u&&(a=[2&a[0],u.value]),a[0]){case 0:case 1:u=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,e=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(u=o.trys,(u=u.length>0&&u[u.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!u||a[1]>u[0]&&a[1]<u[3])){o.label=a[1];break}if(6===a[0]&&o.label<u[1]){o.label=u[1],u=a;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(a);break}u[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(t,o)}catch(t){a=[6,t],e=0}finally{r=u=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function P(t,n,r){if(r||2===arguments.length)for(var e,u=0,i=n.length;u<i;u++)!e&&u in n||(e||(e=Array.prototype.slice.call(n,0,u)),e[u]=n[u]);return t.concat(e||Array.prototype.slice.call(n))}var T=function(t,n){return t.reduce((function(t,r){var e;return F(F({},t),((e={})[r]=n[r],e))}),{})},q=function(){function t(){this.name="",this._error="",this._type="any",this.rules=[],this.custom=[]}return t.prototype.empty=function(t){var n=this;return this.value=t,this.unshift((function(t){var r=e(t);return{break:!r,value:r?t:n.value}}))},t.prototype.error=function(t){return this._error=t,this},t.prototype.invalid=function(t){return{error:this._error?this._error:this.name?this.name+":"+t:t}},t.prototype.parse=function(){return this.unshift((function(t){return{value:t}}))},t.prototype.push=function(t){return this.rules.push(t),this},t.prototype.required=function(){var t=this;return this.unshift((function(n){return e(n)?{value:n}:t.invalid("["+t._type+"].required")}))},t.prototype.test=function(t){return!o(this.validate(t).error)},t.prototype.testAsync=function(t){return I(this,void 0,void 0,(function(){var n;return U(this,(function(r){switch(r.label){case 0:return n=o,[4,this.validateAsync(t)];case 1:return[2,!n.apply(void 0,[r.sent().error])]}}))}))},t.prototype.unshift=function(t){return this.rules.unshift(t),this},t.prototype.validate=function(t){if(this.custom.length)return this.invalid("[async]");for(var n={value:t},r=0;r<this.rules.length;r++){if((n=this.rules[r](n.value)).error)return{error:n.error};if(n.break)return{value:n.value}}return{value:n.value}},t.prototype.validateAsync=function(t){return I(this,void 0,void 0,(function(){var n,r;return U(this,(function(e){switch(e.label){case 0:if((n=this.validate(t)).error)return[2,{error:n.error}];r=0,e.label=1;case 1:return r<this.custom.length?[4,this.custom[r](n.value)]:[3,4];case 2:if((n=e.sent()).error)return[2,{error:n.error}];e.label=3;case 3:return r++,[3,1];case 4:return[2,{value:n.value}]}}))}))},t}(),L=function(t){function r(){var r=t.call(this)||this;return r._length=0,r._max=0,r._min=0,r._type="array",r.push((function(t){if(n(t)){if(r._items){r._items.name="";for(var e=0;e<t.length;e++){var u=r._items.validate(t[e]),i=u.error,o=u.value;if(i)return r.invalid("["+r._type+"]< "+i+"["+e+"] >");t[e]=o}}return{value:t}}return r.invalid("["+r._type+"]")})),r}return M(r,t),r.prototype.between=function(t,n){return this.min(t),this.max(n)},r.prototype.items=function(t){return this._items=t,this},r.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},r.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},r.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},r}(q),B=function(t){function n(){var n=t.call(this)||this;return n._type="boolean",n.push((function(t){return r(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return M(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:e(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(q),D=function(t){function n(){var n=t.call(this)||this;return n._max=0,n._min=0,n._type="number",n.push((function(t){return u(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return M(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:e(t)?parseFloat(t):t}}))},n}(q),N=function(t){function n(){var n=t.call(this)||this;return n._type="object",n.push((function(t){if(i(t)){if(n._keys){var r=[];return Object.keys(n._keys).forEach((function(u){if(n._keys){var i=n._keys[u];i.name=u;var o=i.validate(t[u]),a=o.error,s=o.value;a&&r.push(a),e(s)&&(t[u]=s)}})),r.length?n.invalid("["+n._type+"]{ "+r.join(", ")+" }"):{value:t}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return M(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(q),Y=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="string",n.push((function(t){return o(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return M(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.email=function(){var t=this;return this.push((function(n){return/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(n)?{value:n}:t.invalid("["+t._type+"].email")}))},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.lowerCase=function(){return this.push((function(t){return{value:t.toLowerCase()}}))},n.prototype.lowerCamelCase=function(){return this.push((function(t){return{value:_(t)}}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.mask=function(t){return this.push((function(n){return{value:O(t,n)}}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:i(t)?JSON.stringify(t):e(t)?t.toString():t}}))},n.prototype.required=function(){var t=this;return this.push((function(n){return n.length?{value:n}:t.invalid("["+t._type+"].required")}))},n.prototype.trim=function(){return this.push((function(t){return{value:t.trim()}}))},n.prototype.upperCase=function(){return this.push((function(t){return{value:t.toUpperCase()}}))},n.prototype.upperCamelCase=function(){return this.push((function(t){return{value:w(t)}}))},n}(q),$=function(){function t(){}return t.array=function(t){return(new L).items(t)},t.boolean=function(){return new B},t.number=function(){return new D},t.object=function(t){return(new N).keys(t)},t.string=function(){return new Y},t.prototype.test=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return!o(t.validate.apply(t,P([n],r,!1)).error)},t.prototype.testAsync=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return I(this,void 0,void 0,(function(){var e;return U(this,(function(u){switch(u.label){case 0:return e=o,[4,t.validateAsync.apply(t,P([n],r,!1))];case 1:return[2,!e.apply(void 0,[u.sent().error])]}}))}))},t.validate=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];for(var e={value:t},u=0;u<n.length;u++)if((e=n[u].validate(e.value)).error)return{error:e.error};return e},t.validateAsync=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return I(this,void 0,void 0,(function(){var r,e;return U(this,(function(u){switch(u.label){case 0:r={value:t},e=0,u.label=1;case 1:return e<n.length?[4,n[e].validateAsync(r.value)]:[3,4];case 2:if((r=u.sent()).error)return[2,{error:r.error}];u.label=3;case 3:return e++,[3,1];case 4:return[2,r]}}))}))},t}();exports.EventEmitter=m,exports.Validation=$,exports.ValidationBase=q,exports.allowedObject=T,exports.camelCase=b,exports.chunkArray=function(t,n){for(var r=[],e=0;e<t.length;e+=n)r.push(t.slice(e,e+n));return r},exports.clamp=c,exports.cutText=function(t,n){if(t.length>n){var r=t.substring(0,n).split(" ");return r.pop(),r.join(" ")+"..."}return t},exports.dateFormat=function(t,n){return n.replace(/%[yYmdHMS]/g,(function(n){var r;switch(n){case"%y":r=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":r=t.getMonth()+1;break;case"%d":r=t.getDate();break;case"%H":r=t.getHours();break;case"%M":r=t.getMinutes();break;case"%S":r=t.getSeconds();break;default:return n.slice(1)}return("0"+r.toString()).slice(-2)}))},exports.debounce=function(t,n){var r;return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];r&&clearTimeout(r),r=setTimeout((function(){return t.apply(void 0,e)}),n)}},exports.deniedObject=function(t,n){return T(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},exports.each=function(t,r,e){return n(t)?d(t,r,e):i(t)?x(t,r,e):null},exports.forEachAsync=function(t,n,r){return I(void 0,void 0,void 0,(function(){return U(this,(function(e){switch(e.label){case 0:return[4,Promise.all(t.map((function(e,u){return n.call(r,e,u,t)})))];case 1:return e.sent(),[2]}}))}))},exports.forEachIndex=d,exports.forEachKey=x,exports.forEachSeries=function(t,n,r){return I(void 0,void 0,void 0,(function(){var e;return U(this,(function(u){switch(u.label){case 0:e=0,u.label=1;case 1:return e<t.length?[4,n.call(r,t[e],e,t)]:[3,4];case 2:u.sent(),u.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},exports.isArray=n,exports.isBoolean=r,exports.isDef=e,exports.isFloat=function(t){return u(t)&&!!(t%1)},exports.isFunction=function(t){return"function"==s(t)},exports.isInteger=function(t){return u(t)&&!(t%1)},exports.isNull=function(t){return null===t},exports.isNumber=u,exports.isObject=i,exports.isString=o,exports.isUndefined=a,exports.loop=function(t,n,r){for(var e=1;e<=t&&!1!==n.call(r,e,t);e++);return t},exports.lowerCamelCase=_,exports.map=function(t,n,r){for(var e="",u=Object.keys(t),i=0;i<u.length;i++)t[e=u[i]]=n.call(r,t[e],e,t);return t},exports.mask=O,exports.maskMoney=function(t,n,r){return r++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),A(t,n.length<r?("0".repeat(r)+n).slice(-1*r):n)},exports.maskReverse=A,exports.noop=function(){},exports.parseSize=function(t){if(u(t))return t+"px";var n=function(t){return/(\d+)\.*(\d*)(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(t)}(t)||["","0","",""],r=n[1],e=n[2],i=n[3];return(e.length?parseFloat(r+"."+e):parseInt(r))+(i||"px")},exports.shadeColor=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+l(t,n)).slice(-2)}))},exports.simpleID=function(){return f()+h()},exports.sleep=function(t){return new Promise((function(n){return setTimeout(n,t)}))},exports.stringReverse=k,exports.toArray=function(t){return n(t)?t:e(t)?[t]:[]},exports.toBool=function(t){return"true"===t||"1"===t},exports.type=s,exports.uniqueID=function(){return y()+y()+y()+y()},exports.upperCamelCase=w,exports.uuidv4=function(){return v()+"-"+h()+"-4"+f()+"-"+h()+"-"+(v()+h())};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.3
2
+ * @andrewcaires/utils.js v0.2.5
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2022 Andrew Caires
5
5
  * @license: MIT
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.3
2
+ * @andrewcaires/utils.js v0.2.5
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2022 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- var t={},n=function(t){return"array"==p(t)},r=function(t){return"boolean"==p(t)},e=function(t){return"null"!=p(t)},u=function(t){return"function"==p(t)},i=function(t){return"number"==p(t)},o=function(t){return"object"==p(t)},a=function(t){return"string"==p(t)},c=function(t){return i(t)&&!!(t%1)},s=function(t){return i(t)&&!(t%1)},l=function(t){return null===t},f=function(t){return void 0===t},p=function(n){return null==n?"null":t[t.toString.call(n)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(n){return t["[object "+n+"]"]=n.toLowerCase()}));var h=function(t,n){for(var r=[],e=0;e<t.length;e+=n)r.push(t.slice(e,e+n));return r},v=function(t){return n(t)?t:e(t)?[t]:[]},y=function(t){return"true"===t||"1"===t},m=function(t,n,r){return Math.max(n,Math.min(r,t))},g=function(t,n){return(r=parseInt(t,16)+n,m(r,0,255)).toString(16);var r},d=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+g(t,n)).slice(-2)}))},_=function(t){return Math.random().toString(16).slice(t)},b=function(){return _(-3)},w=function(){return _(-4)},x=function(){return w()+w()},k=function(){return x()+x()},j=function(){return b()+w()},O=function(){return k()+k()+k()+k()},C=function(){return x()+"-"+w()+"-4"+b()+"-"+w()+"-"+(x()+w())},S=function(t,n){return n.replace(/%[yYmdHMS]/g,(function(n){var r;switch(n){case"%y":r=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":r=t.getMonth()+1;break;case"%d":r=t.getDate();break;case"%H":r=t.getHours();break;case"%M":r=t.getMinutes();break;case"%S":r=t.getSeconds();break;default:return n.slice(1)}return("0"+r.toString()).slice(-2)}))},A=function(t,n){var r;return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];r&&clearTimeout(r),r=setTimeout((function(){return t.apply(void 0,e)}),n)}},M=function(){function t(){this.events=new Map}return t.prototype.on=function(t,n){var r=this,e=this.events.get(t);return e?e.push(n):this.events.set(t,[n]),{dispose:function(){return r.off(t,n)}}},t.prototype.once=function(t,n){var r=this,e=function(u){n(u),r.off(t,e)};return this.on(t,e),{dispose:function(){return r.off(t,e)}}},t.prototype.off=function(t,n){var r=this.events.get(t);if(n){if(r){var e=r.indexOf(n);e>=0&&r.splice(e,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,n){var r=this.events.get(t);r&&r.forEach((function(t){return t(n)}))},t}(),P=function(t,n,r){for(var e=0;e<t.length&&!1!==n.call(r,t[e],e,t);e++);return t},U=function(t,n,r){for(var e="",u=Object.keys(t),i=0;i<u.length&&(e=u[i],!1!==n.call(r,t[e],e,t));i++);return t},E=function(t,r,e){return n(t)?P(t,r,e):o(t)?U(t,r,e):null},F=function(t,n,r){for(var e=1;e<=t&&!1!==n.call(r,e,t);e++);return t},L=function(t,n,r){for(var e="",u=Object.keys(t),i=0;i<u.length;i++)t[e=u[i]]=n.call(r,t[e],e,t);return t},T=function(){},q=function(t,n){if(t.length>n){var r=t.substring(0,n).split(" ");return r.pop(),r.join(" ")+"..."}return t},Y=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},$=function(t){return Y(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},H=$,I=function(t){return Y(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,r){return n.toUpperCase()+r}))}))},Z=function(t){return t.split("").reverse().join("")},z=function(t){return/^[A-Za-z]$/.test(t)},N=function(t,n,r){r.mask++,r.text++;var e=t[r.mask],u=n[r.text];return f(e)||f(u)?"":function(t,n,r){switch(t.toUpperCase()){case"#":return n;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(n)?n:(r.mask--,"");case"A":case"Z":return z(n)?n:(r.mask--,"");case"L":return z(n)?n.toLowerCase():(r.mask--,"");case"U":return z(n)?n.toUpperCase():(r.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(n)?n:(r.mask--,"");default:return t!=n&&r.text--,t}}(e,u,r)+N(t,n,r)},W=function(t,n){return N(t,n,{mask:-1,text:-1})},B=function(t,n,r){return r++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),G(t,n.length<r?("0".repeat(r)+n).slice(-1*r):n)},D=W,G=function(t,n){return Z(D(Z(t),Z(n)))},J=function(t,n){return J=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])},J(t,n)};function K(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}J(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var Q=function(){return Q=Object.assign||function(t){for(var n,r=1,e=arguments.length;r<e;r++)for(var u in n=arguments[r])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t},Q.apply(this,arguments)};function R(t,n,r,e){return new(r||(r=Promise))((function(u,i){function o(t){try{c(e.next(t))}catch(t){i(t)}}function a(t){try{c(e.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?u(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(o,a)}c((e=e.apply(t,n||[])).next())}))}function V(t,n){var r,e,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,e&&(u=2&i[0]?e.return:i[0]?e.throw||((u=e.return)&&u.call(e),0):e.next)&&!(u=u.call(e,i[1])).done)return u;switch(e=0,u&&(i=[2&i[0],u.value]),i[0]){case 0:case 1:u=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,e=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(u=o.trys,(u=u.length>0&&u[u.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!u||i[1]>u[0]&&i[1]<u[3])){o.label=i[1];break}if(6===i[0]&&o.label<u[1]){o.label=u[1],u=i;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(i);break}u[2]&&o.ops.pop(),o.trys.pop();continue}i=n.call(t,o)}catch(t){i=[6,t],e=0}finally{r=u=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function X(t,n,r){if(r||2===arguments.length)for(var e,u=0,i=n.length;u<i;u++)!e&&u in n||(e||(e=Array.prototype.slice.call(n,0,u)),e[u]=n[u]);return t.concat(e||Array.prototype.slice.call(n))}var tt=function(t,n){return t.reduce((function(t,r){var e;return Q(Q({},t),((e={})[r]=n[r],e))}),{})},nt=function(t,n){return tt(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},rt=function(t,n,r){return R(void 0,void 0,void 0,(function(){return V(this,(function(e){switch(e.label){case 0:return[4,Promise.all(t.map((function(e,u){return n.call(r,e,u,t)})))];case 1:return e.sent(),[2]}}))}))},et=function(t,n,r){return R(void 0,void 0,void 0,(function(){var e;return V(this,(function(u){switch(u.label){case 0:e=0,u.label=1;case 1:return e<t.length?[4,n.call(r,t[e],e,t)]:[3,4];case 2:u.sent(),u.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},ut=function(t){return new Promise((function(n){return setTimeout(n,t)}))},it=function(t){if(i(t))return t+"px";var n=function(t){return/(\d+)\.*(\d*)(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(t)}(t)||["","0","",""],r=n[1],e=n[2],u=n[3];return(e.length?parseFloat(r+"."+e):parseInt(r))+(u||"px")},ot=function(){function t(){this.name="",this._error="",this._type="any",this.rules=[],this.custom=[]}return t.prototype.empty=function(t){var n=this;return this.value=t,this.unshift((function(t){var r=e(t);return{break:!r,value:r?t:n.value}}))},t.prototype.error=function(t){return this._error=t,this},t.prototype.invalid=function(t){return{error:this._error?this._error:this.name?this.name+":"+t:t}},t.prototype.parse=function(){return this.unshift((function(t){return{value:t}}))},t.prototype.push=function(t){return this.rules.push(t),this},t.prototype.required=function(){var t=this;return this.unshift((function(n){return e(n)?{value:n}:t.invalid("["+t._type+"].required")}))},t.prototype.test=function(t){return!a(this.validate(t).error)},t.prototype.testAsync=function(t){return R(this,void 0,void 0,(function(){var n;return V(this,(function(r){switch(r.label){case 0:return n=a,[4,this.validateAsync(t)];case 1:return[2,!n.apply(void 0,[r.sent().error])]}}))}))},t.prototype.unshift=function(t){return this.rules.unshift(t),this},t.prototype.validate=function(t){if(this.custom.length)return this.invalid("[async]");for(var n={value:t},r=0;r<this.rules.length;r++){if((n=this.rules[r](n.value)).error)return{error:n.error};if(n.break)return{value:n.value}}return{value:n.value}},t.prototype.validateAsync=function(t){return R(this,void 0,void 0,(function(){var n,r;return V(this,(function(e){switch(e.label){case 0:if((n=this.validate(t)).error)return[2,{error:n.error}];r=0,e.label=1;case 1:return r<this.custom.length?[4,this.custom[r](n.value)]:[3,4];case 2:if((n=e.sent()).error)return[2,{error:n.error}];e.label=3;case 3:return r++,[3,1];case 4:return[2,{value:n.value}]}}))}))},t}(),at=function(t){function r(){var r=t.call(this)||this;return r._length=0,r._max=0,r._min=0,r._type="array",r.push((function(t){if(n(t)){if(r._items){r._items.name="";for(var e=0;e<t.length;e++){var u=r._items.validate(t[e]),i=u.error,o=u.value;if(i)return r.invalid("["+r._type+"]< "+i+"["+e+"] >");t[e]=o}}return{value:t}}return r.invalid("["+r._type+"]")})),r}return K(r,t),r.prototype.between=function(t,n){return this.min(t),this.max(n)},r.prototype.items=function(t){return this._items=t,this},r.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},r.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},r.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},r}(ot),ct=function(t){function n(){var n=t.call(this)||this;return n._type="boolean",n.push((function(t){return r(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return K(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:e(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(ot),st=function(t){function n(){var n=t.call(this)||this;return n._max=0,n._min=0,n._type="number",n.push((function(t){return i(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return K(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:e(t)?parseFloat(t):t}}))},n}(ot),lt=function(t){function n(){var n=t.call(this)||this;return n._type="object",n.push((function(t){if(o(t)){if(n._keys){var r=[];return Object.keys(n._keys).forEach((function(u){if(n._keys){var i=n._keys[u];i.name=u;var o=i.validate(t[u]),a=o.error,c=o.value;a&&r.push(a),e(c)&&(t[u]=c)}})),r.length?n.invalid("["+n._type+"]{ "+r.join(", ")+" }"):{value:t}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return K(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(ot),ft=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="string",n.push((function(t){return a(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return K(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.email=function(){var t=this;return this.push((function(n){return/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(n)?{value:n}:t.invalid("["+t._type+"].email")}))},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.lowerCase=function(){return this.push((function(t){return{value:t.toLowerCase()}}))},n.prototype.lowerCamelCase=function(){return this.push((function(t){return{value:$(t)}}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.mask=function(t){return this.push((function(n){return{value:W(t,n)}}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:o(t)?JSON.stringify(t):e(t)?t.toString():t}}))},n.prototype.required=function(){var t=this;return this.push((function(n){return n.length?{value:n}:t.invalid("["+t._type+"].required")}))},n.prototype.trim=function(){return this.push((function(t){return{value:t.trim()}}))},n.prototype.upperCase=function(){return this.push((function(t){return{value:t.toUpperCase()}}))},n.prototype.upperCamelCase=function(){return this.push((function(t){return{value:I(t)}}))},n}(ot),pt=function(){function t(){}return t.array=function(t){return(new at).items(t)},t.boolean=function(){return new ct},t.number=function(){return new st},t.object=function(t){return(new lt).keys(t)},t.string=function(){return new ft},t.prototype.test=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return!a(t.validate.apply(t,X([n],r,!1)).error)},t.prototype.testAsync=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return R(this,void 0,void 0,(function(){var e;return V(this,(function(u){switch(u.label){case 0:return e=a,[4,t.validateAsync.apply(t,X([n],r,!1))];case 1:return[2,!e.apply(void 0,[u.sent().error])]}}))}))},t.validate=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];for(var e={value:t},u=0;u<n.length;u++)if((e=n[u].validate(e.value)).error)return{error:e.error};return e},t.validateAsync=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return R(this,void 0,void 0,(function(){var r,e;return V(this,(function(u){switch(u.label){case 0:r={value:t},e=0,u.label=1;case 1:return e<n.length?[4,n[e].validateAsync(r.value)]:[3,4];case 2:if((r=u.sent()).error)return[2,{error:r.error}];u.label=3;case 3:return e++,[3,1];case 4:return[2,r]}}))}))},t}();export{M as EventEmitter,pt as Validation,ot as ValidationBase,tt as allowedObject,H as camelCase,h as chunkArray,m as clamp,q as cutText,S as dateFormat,A as debounce,nt as deniedObject,E as each,rt as forEachAsync,P as forEachIndex,U as forEachKey,et as forEachSeries,n as isArray,r as isBoolean,e as isDef,c as isFloat,u as isFunction,s as isInteger,l as isNull,i as isNumber,o as isObject,a as isString,f as isUndefined,F as loop,$ as lowerCamelCase,L as map,W as mask,B as maskMoney,G as maskReverse,T as noop,it as parseSize,d as shadeColor,j as simpleID,ut as sleep,Z as stringReverse,v as toArray,y as toBool,p as type,O as uniqueID,I as upperCamelCase,C as uuidv4};
7
+ var t={},n=function(t){return"array"==p(t)},r=function(t){return"boolean"==p(t)},e=function(t){return"null"!=p(t)},u=function(t){return"function"==p(t)},i=function(t){return"number"==p(t)},o=function(t){return"object"==p(t)},a=function(t){return"string"==p(t)},c=function(t){return i(t)&&!!(t%1)},s=function(t){return i(t)&&!(t%1)},l=function(t){return null===t},f=function(t){return void 0===t},p=function(n){return null==n?"null":t[t.toString.call(n)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(n){return t["[object "+n+"]"]=n.toLowerCase()}));var h=function(t,n){for(var r=[],e=0;e<t.length;e+=n)r.push(t.slice(e,e+n));return r},v=function(t){return n(t)?t:e(t)?[t]:[]},y=function(t){return"true"===t||"1"===t},m=function(t,n,r){return Math.max(n,Math.min(r,t))},g=function(t,n){return(r=parseInt(t,16)+n,m(r,0,255)).toString(16);var r},d=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+g(t,n)).slice(-2)}))},_=function(t){return Math.random().toString(16).slice(t)},b=function(){return _(-3)},w=function(){return _(-4)},x=function(){return w()+w()},k=function(){return x()+x()},j=function(){return b()+w()},O=function(){return k()+k()+k()+k()},C=function(){return x()+"-"+w()+"-4"+b()+"-"+w()+"-"+(x()+w())},S=function(t,n){return n.replace(/%[yYmdHMS]/g,(function(n){var r;switch(n){case"%y":r=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":r=t.getMonth()+1;break;case"%d":r=t.getDate();break;case"%H":r=t.getHours();break;case"%M":r=t.getMinutes();break;case"%S":r=t.getSeconds();break;default:return n.slice(1)}return("0"+r.toString()).slice(-2)}))},A=function(t,n){var r;return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];r&&clearTimeout(r),r=setTimeout((function(){return t.apply(void 0,e)}),n)}},M=function(){function t(){this.events=new Map}return t.prototype.on=function(t,n){var r=this,e=this.events.get(t);return e?e.push(n):this.events.set(t,[n]),{dispose:function(){return r.off(t,n)}}},t.prototype.once=function(t,n){var r=this,e=function(u){n(u),r.off(t,e)};return this.on(t,e),{dispose:function(){return r.off(t,e)}}},t.prototype.off=function(t,n){var r=this.events.get(t);if(n){if(r){var e=r.indexOf(n);e>=0&&r.splice(e,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,n){var r=this.events.get(t);r&&r.forEach((function(t){return t(n)}))},t}(),P=function(t,n,r){for(var e=0;e<t.length&&!1!==n.call(r,t[e],e,t);e++);return t},U=function(t,n,r){for(var e="",u=Object.keys(t),i=0;i<u.length&&(e=u[i],!1!==n.call(r,t[e],e,t));i++);return t},E=function(t,r,e){return n(t)?P(t,r,e):o(t)?U(t,r,e):null},F=function(t,n,r){for(var e=1;e<=t&&!1!==n.call(r,e,t);e++);return t},L=function(t,n,r){for(var e="",u=Object.keys(t),i=0;i<u.length;i++)t[e=u[i]]=n.call(r,t[e],e,t);return t},T=function(){},q=function(t,n){if(t.length>n){var r=t.substring(0,n).split(" ");return r.pop(),r.join(" ")+"..."}return t},Y=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},$=function(t){return Y(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},H=$,I=function(t){return Y(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,r){return n.toUpperCase()+r}))}))},Z=function(t){return t.split("").reverse().join("")},z=function(t){return/^[A-Za-z]$/.test(t)},N=function(t,n,r){r.mask++,r.text++;var e=t[r.mask],u=n[r.text];return f(e)||f(u)?"":function(t,n,r){switch(t.toUpperCase()){case"#":return n;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(n)?n:(r.mask--,"");case"A":case"Z":return z(n)?n:(r.mask--,"");case"L":return z(n)?n.toLowerCase():(r.mask--,"");case"U":return z(n)?n.toUpperCase():(r.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(n)?n:(r.mask--,"");default:return t!=n&&r.text--,t}}(e,u,r)+N(t,n,r)},W=function(t,n){return N(t,n,{mask:-1,text:-1})},B=function(t,n,r){return r++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),G(t,n.length<r?("0".repeat(r)+n).slice(-1*r):n)},D=W,G=function(t,n){return Z(D(Z(t),Z(n)))},J=function(t,n){return J=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])},J(t,n)};function K(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}J(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var Q=function(){return Q=Object.assign||function(t){for(var n,r=1,e=arguments.length;r<e;r++)for(var u in n=arguments[r])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t},Q.apply(this,arguments)};function R(t,n,r,e){return new(r||(r=Promise))((function(u,i){function o(t){try{c(e.next(t))}catch(t){i(t)}}function a(t){try{c(e.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?u(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(o,a)}c((e=e.apply(t,n||[])).next())}))}function V(t,n){var r,e,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(o=0)),o;)try{if(r=1,e&&(u=2&a[0]?e.return:a[0]?e.throw||((u=e.return)&&u.call(e),0):e.next)&&!(u=u.call(e,a[1])).done)return u;switch(e=0,u&&(a=[2&a[0],u.value]),a[0]){case 0:case 1:u=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,e=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(u=o.trys,(u=u.length>0&&u[u.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!u||a[1]>u[0]&&a[1]<u[3])){o.label=a[1];break}if(6===a[0]&&o.label<u[1]){o.label=u[1],u=a;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(a);break}u[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(t,o)}catch(t){a=[6,t],e=0}finally{r=u=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function X(t,n,r){if(r||2===arguments.length)for(var e,u=0,i=n.length;u<i;u++)!e&&u in n||(e||(e=Array.prototype.slice.call(n,0,u)),e[u]=n[u]);return t.concat(e||Array.prototype.slice.call(n))}var tt=function(t,n){return t.reduce((function(t,r){var e;return Q(Q({},t),((e={})[r]=n[r],e))}),{})},nt=function(t,n){return tt(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},rt=function(t,n,r){return R(void 0,void 0,void 0,(function(){return V(this,(function(e){switch(e.label){case 0:return[4,Promise.all(t.map((function(e,u){return n.call(r,e,u,t)})))];case 1:return e.sent(),[2]}}))}))},et=function(t,n,r){return R(void 0,void 0,void 0,(function(){var e;return V(this,(function(u){switch(u.label){case 0:e=0,u.label=1;case 1:return e<t.length?[4,n.call(r,t[e],e,t)]:[3,4];case 2:u.sent(),u.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},ut=function(t){return new Promise((function(n){return setTimeout(n,t)}))},it=function(t){if(i(t))return t+"px";var n=function(t){return/(\d+)\.*(\d*)(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(t)}(t)||["","0","",""],r=n[1],e=n[2],u=n[3];return(e.length?parseFloat(r+"."+e):parseInt(r))+(u||"px")},ot=function(){function t(){this.name="",this._error="",this._type="any",this.rules=[],this.custom=[]}return t.prototype.empty=function(t){var n=this;return this.value=t,this.unshift((function(t){var r=e(t);return{break:!r,value:r?t:n.value}}))},t.prototype.error=function(t){return this._error=t,this},t.prototype.invalid=function(t){return{error:this._error?this._error:this.name?this.name+":"+t:t}},t.prototype.parse=function(){return this.unshift((function(t){return{value:t}}))},t.prototype.push=function(t){return this.rules.push(t),this},t.prototype.required=function(){var t=this;return this.unshift((function(n){return e(n)?{value:n}:t.invalid("["+t._type+"].required")}))},t.prototype.test=function(t){return!a(this.validate(t).error)},t.prototype.testAsync=function(t){return R(this,void 0,void 0,(function(){var n;return V(this,(function(r){switch(r.label){case 0:return n=a,[4,this.validateAsync(t)];case 1:return[2,!n.apply(void 0,[r.sent().error])]}}))}))},t.prototype.unshift=function(t){return this.rules.unshift(t),this},t.prototype.validate=function(t){if(this.custom.length)return this.invalid("[async]");for(var n={value:t},r=0;r<this.rules.length;r++){if((n=this.rules[r](n.value)).error)return{error:n.error};if(n.break)return{value:n.value}}return{value:n.value}},t.prototype.validateAsync=function(t){return R(this,void 0,void 0,(function(){var n,r;return V(this,(function(e){switch(e.label){case 0:if((n=this.validate(t)).error)return[2,{error:n.error}];r=0,e.label=1;case 1:return r<this.custom.length?[4,this.custom[r](n.value)]:[3,4];case 2:if((n=e.sent()).error)return[2,{error:n.error}];e.label=3;case 3:return r++,[3,1];case 4:return[2,{value:n.value}]}}))}))},t}(),at=function(t){function r(){var r=t.call(this)||this;return r._length=0,r._max=0,r._min=0,r._type="array",r.push((function(t){if(n(t)){if(r._items){r._items.name="";for(var e=0;e<t.length;e++){var u=r._items.validate(t[e]),i=u.error,o=u.value;if(i)return r.invalid("["+r._type+"]< "+i+"["+e+"] >");t[e]=o}}return{value:t}}return r.invalid("["+r._type+"]")})),r}return K(r,t),r.prototype.between=function(t,n){return this.min(t),this.max(n)},r.prototype.items=function(t){return this._items=t,this},r.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},r.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},r.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},r}(ot),ct=function(t){function n(){var n=t.call(this)||this;return n._type="boolean",n.push((function(t){return r(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return K(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:e(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(ot),st=function(t){function n(){var n=t.call(this)||this;return n._max=0,n._min=0,n._type="number",n.push((function(t){return i(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return K(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:e(t)?parseFloat(t):t}}))},n}(ot),lt=function(t){function n(){var n=t.call(this)||this;return n._type="object",n.push((function(t){if(o(t)){if(n._keys){var r=[];return Object.keys(n._keys).forEach((function(u){if(n._keys){var i=n._keys[u];i.name=u;var o=i.validate(t[u]),a=o.error,c=o.value;a&&r.push(a),e(c)&&(t[u]=c)}})),r.length?n.invalid("["+n._type+"]{ "+r.join(", ")+" }"):{value:t}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return K(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(ot),ft=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="string",n.push((function(t){return a(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return K(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.email=function(){var t=this;return this.push((function(n){return/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(n)?{value:n}:t.invalid("["+t._type+"].email")}))},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.lowerCase=function(){return this.push((function(t){return{value:t.toLowerCase()}}))},n.prototype.lowerCamelCase=function(){return this.push((function(t){return{value:$(t)}}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.mask=function(t){return this.push((function(n){return{value:W(t,n)}}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:o(t)?JSON.stringify(t):e(t)?t.toString():t}}))},n.prototype.required=function(){var t=this;return this.push((function(n){return n.length?{value:n}:t.invalid("["+t._type+"].required")}))},n.prototype.trim=function(){return this.push((function(t){return{value:t.trim()}}))},n.prototype.upperCase=function(){return this.push((function(t){return{value:t.toUpperCase()}}))},n.prototype.upperCamelCase=function(){return this.push((function(t){return{value:I(t)}}))},n}(ot),pt=function(){function t(){}return t.array=function(t){return(new at).items(t)},t.boolean=function(){return new ct},t.number=function(){return new st},t.object=function(t){return(new lt).keys(t)},t.string=function(){return new ft},t.prototype.test=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return!a(t.validate.apply(t,X([n],r,!1)).error)},t.prototype.testAsync=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return R(this,void 0,void 0,(function(){var e;return V(this,(function(u){switch(u.label){case 0:return e=a,[4,t.validateAsync.apply(t,X([n],r,!1))];case 1:return[2,!e.apply(void 0,[u.sent().error])]}}))}))},t.validate=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];for(var e={value:t},u=0;u<n.length;u++)if((e=n[u].validate(e.value)).error)return{error:e.error};return e},t.validateAsync=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return R(this,void 0,void 0,(function(){var r,e;return V(this,(function(u){switch(u.label){case 0:r={value:t},e=0,u.label=1;case 1:return e<n.length?[4,n[e].validateAsync(r.value)]:[3,4];case 2:if((r=u.sent()).error)return[2,{error:r.error}];u.label=3;case 3:return e++,[3,1];case 4:return[2,r]}}))}))},t}();export{M as EventEmitter,pt as Validation,ot as ValidationBase,tt as allowedObject,H as camelCase,h as chunkArray,m as clamp,q as cutText,S as dateFormat,A as debounce,nt as deniedObject,E as each,rt as forEachAsync,P as forEachIndex,U as forEachKey,et as forEachSeries,n as isArray,r as isBoolean,e as isDef,c as isFloat,u as isFunction,s as isInteger,l as isNull,i as isNumber,o as isObject,a as isString,f as isUndefined,F as loop,$ as lowerCamelCase,L as map,W as mask,B as maskMoney,G as maskReverse,T as noop,it as parseSize,d as shadeColor,j as simpleID,ut as sleep,Z as stringReverse,v as toArray,y as toBool,p as type,O as uniqueID,I as upperCamelCase,C as uuidv4};
package/dist/index.min.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.3
2
+ * @andrewcaires/utils.js v0.2.5
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2022 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- var UtilsJS=function(t){"use strict";var n={},e=function(t){return"array"==c(t)},r=function(t){return"boolean"==c(t)},u=function(t){return"null"!=c(t)},i=function(t){return"number"==c(t)},o=function(t){return"object"==c(t)},a=function(t){return"string"==c(t)},s=function(t){return void 0===t},c=function(t){return null==t?"null":n[n.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return n["[object "+t+"]"]=t.toLowerCase()}));var l=function(t,n,e){return Math.max(n,Math.min(e,t))},f=function(t,n){return(e=parseInt(t,16)+n,l(e,0,255)).toString(16);var e},p=function(t){return Math.random().toString(16).slice(t)},h=function(){return p(-3)},v=function(){return p(-4)},y=function(){return v()+v()},m=function(){return y()+y()},d=function(){function t(){this.events=new Map}return t.prototype.on=function(t,n){var e=this,r=this.events.get(t);return r?r.push(n):this.events.set(t,[n]),{dispose:function(){return e.off(t,n)}}},t.prototype.once=function(t,n){var e=this,r=function(u){n(u),e.off(t,r)};return this.on(t,r),{dispose:function(){return e.off(t,r)}}},t.prototype.off=function(t,n){var e=this.events.get(t);if(n){if(e){var r=e.indexOf(n);r>=0&&e.splice(r,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,n){var e=this.events.get(t);e&&e.forEach((function(t){return t(n)}))},t}(),g=function(t,n,e){for(var r=0;r<t.length&&!1!==n.call(e,t[r],r,t);r++);return t},_=function(t,n,e){for(var r="",u=Object.keys(t),i=0;i<u.length&&(r=u[i],!1!==n.call(e,t[r],r,t));i++);return t},b=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},w=function(t){return b(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},x=w,k=function(t){return b(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,e){return n.toUpperCase()+e}))}))},j=function(t){return t.split("").reverse().join("")},C=function(t){return/^[A-Za-z]$/.test(t)},O=function(t,n,e){e.mask++,e.text++;var r=t[e.mask],u=n[e.text];return s(r)||s(u)?"":function(t,n,e){switch(t.toUpperCase()){case"#":return n;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(n)?n:(e.mask--,"");case"A":case"Z":return C(n)?n:(e.mask--,"");case"L":return C(n)?n.toLowerCase():(e.mask--,"");case"U":return C(n)?n.toUpperCase():(e.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(n)?n:(e.mask--,"");default:return t!=n&&e.text--,t}}(r,u,e)+O(t,n,e)},S=function(t,n){return O(t,n,{mask:-1,text:-1})},A=S,E=function(t,n){return j(A(j(t),j(n)))},M=function(t,n){return M=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])},M(t,n)};function F(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=t}M(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}var U=function(){return U=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t},U.apply(this,arguments)};function I(t,n,e,r){return new(e||(e=Promise))((function(u,i){function o(t){try{s(r.next(t))}catch(t){i(t)}}function a(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var n;t.done?u(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(o,a)}s((r=r.apply(t,n||[])).next())}))}function P(t,n){var e,r,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;o;)try{if(e=1,r&&(u=2&i[0]?r.return:i[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,i[1])).done)return u;switch(r=0,u&&(i=[2&i[0],u.value]),i[0]){case 0:case 1:u=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(u=o.trys,(u=u.length>0&&u[u.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!u||i[1]>u[0]&&i[1]<u[3])){o.label=i[1];break}if(6===i[0]&&o.label<u[1]){o.label=u[1],u=i;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(i);break}u[2]&&o.ops.pop(),o.trys.pop();continue}i=n.call(t,o)}catch(t){i=[6,t],r=0}finally{e=u=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function T(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||Array.prototype.slice.call(n))}var q=function(t,n){return t.reduce((function(t,e){var r;return U(U({},t),((r={})[e]=n[e],r))}),{})},L=function(){function t(){this.name="",this._error="",this._type="any",this.rules=[],this.custom=[]}return t.prototype.empty=function(t){var n=this;return this.value=t,this.unshift((function(t){var e=u(t);return{break:!e,value:e?t:n.value}}))},t.prototype.error=function(t){return this._error=t,this},t.prototype.invalid=function(t){return{error:this._error?this._error:this.name?this.name+":"+t:t}},t.prototype.parse=function(){return this.unshift((function(t){return{value:t}}))},t.prototype.push=function(t){return this.rules.push(t),this},t.prototype.required=function(){var t=this;return this.unshift((function(n){return u(n)?{value:n}:t.invalid("["+t._type+"].required")}))},t.prototype.test=function(t){return!a(this.validate(t).error)},t.prototype.testAsync=function(t){return I(this,void 0,void 0,(function(){var n;return P(this,(function(e){switch(e.label){case 0:return n=a,[4,this.validateAsync(t)];case 1:return[2,!n.apply(void 0,[e.sent().error])]}}))}))},t.prototype.unshift=function(t){return this.rules.unshift(t),this},t.prototype.validate=function(t){if(this.custom.length)return this.invalid("[async]");for(var n={value:t},e=0;e<this.rules.length;e++){if((n=this.rules[e](n.value)).error)return{error:n.error};if(n.break)return{value:n.value}}return{value:n.value}},t.prototype.validateAsync=function(t){return I(this,void 0,void 0,(function(){var n,e;return P(this,(function(r){switch(r.label){case 0:if((n=this.validate(t)).error)return[2,{error:n.error}];e=0,r.label=1;case 1:return e<this.custom.length?[4,this.custom[e](n.value)]:[3,4];case 2:if((n=r.sent()).error)return[2,{error:n.error}];r.label=3;case 3:return e++,[3,1];case 4:return[2,{value:n.value}]}}))}))},t}(),B=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="array",n.push((function(t){if(e(t)){if(n._items){n._items.name="";for(var r=0;r<t.length;r++){var u=n._items.validate(t[r]),i=u.error,o=u.value;if(i)return n.invalid("["+n._type+"]< "+i+"["+r+"] >");t[r]=o}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.items=function(t){return this._items=t,this},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n}(L),D=function(t){function n(){var n=t.call(this)||this;return n._type="boolean",n.push((function(t){return r(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:u(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(L),N=function(t){function n(){var n=t.call(this)||this;return n._max=0,n._min=0,n._type="number",n.push((function(t){return i(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:u(t)?parseFloat(t):t}}))},n}(L),Y=function(t){function n(){var n=t.call(this)||this;return n._type="object",n.push((function(t){if(o(t)){if(n._keys){var e=[];return Object.keys(n._keys).forEach((function(r){if(n._keys){var i=n._keys[r];i.name=r;var o=i.validate(t[r]),a=o.error,s=o.value;a&&e.push(a),u(s)&&(t[r]=s)}})),e.length?n.invalid("["+n._type+"]{ "+e.join(", ")+" }"):{value:t}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(L),$=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="string",n.push((function(t){return a(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.email=function(){var t=this;return this.push((function(n){return/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(n)?{value:n}:t.invalid("["+t._type+"].email")}))},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.lowerCase=function(){return this.push((function(t){return{value:t.toLowerCase()}}))},n.prototype.lowerCamelCase=function(){return this.push((function(t){return{value:w(t)}}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.mask=function(t){return this.push((function(n){return{value:S(t,n)}}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:o(t)?JSON.stringify(t):u(t)?t.toString():t}}))},n.prototype.required=function(){var t=this;return this.push((function(n){return n.length?{value:n}:t.invalid("["+t._type+"].required")}))},n.prototype.trim=function(){return this.push((function(t){return{value:t.trim()}}))},n.prototype.upperCase=function(){return this.push((function(t){return{value:t.toUpperCase()}}))},n.prototype.upperCamelCase=function(){return this.push((function(t){return{value:k(t)}}))},n}(L),z=function(){function t(){}return t.array=function(t){return(new B).items(t)},t.boolean=function(){return new D},t.number=function(){return new N},t.object=function(t){return(new Y).keys(t)},t.string=function(){return new $},t.prototype.test=function(n){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return!a(t.validate.apply(t,T([n],e,!1)).error)},t.prototype.testAsync=function(n){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return I(this,void 0,void 0,(function(){var r;return P(this,(function(u){switch(u.label){case 0:return r=a,[4,t.validateAsync.apply(t,T([n],e,!1))];case 1:return[2,!r.apply(void 0,[u.sent().error])]}}))}))},t.validate=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];for(var r={value:t},u=0;u<n.length;u++)if((r=n[u].validate(r.value)).error)return{error:r.error};return r},t.validateAsync=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return I(this,void 0,void 0,(function(){var e,r;return P(this,(function(u){switch(u.label){case 0:e={value:t},r=0,u.label=1;case 1:return r<n.length?[4,n[r].validateAsync(e.value)]:[3,4];case 2:if((e=u.sent()).error)return[2,{error:e.error}];u.label=3;case 3:return r++,[3,1];case 4:return[2,e]}}))}))},t}();return t.EventEmitter=d,t.Validation=z,t.ValidationBase=L,t.allowedObject=q,t.camelCase=x,t.chunkArray=function(t,n){for(var e=[],r=0;r<t.length;r+=n)e.push(t.slice(r,r+n));return e},t.clamp=l,t.cutText=function(t,n){if(t.length>n){var e=t.substring(0,n).split(" ");return e.pop(),e.join(" ")+"..."}return t},t.dateFormat=function(t,n){return n.replace(/%[yYmdHMS]/g,(function(n){var e;switch(n){case"%y":e=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":e=t.getMonth()+1;break;case"%d":e=t.getDate();break;case"%H":e=t.getHours();break;case"%M":e=t.getMinutes();break;case"%S":e=t.getSeconds();break;default:return n.slice(1)}return("0"+e.toString()).slice(-2)}))},t.debounce=function(t,n){var e;return function(){for(var r=[],u=0;u<arguments.length;u++)r[u]=arguments[u];e&&clearTimeout(e),e=setTimeout((function(){return t.apply(void 0,r)}),n)}},t.deniedObject=function(t,n){return q(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},t.each=function(t,n,r){return e(t)?g(t,n,r):o(t)?_(t,n,r):null},t.forEachAsync=function(t,n,e){return I(void 0,void 0,void 0,(function(){return P(this,(function(r){switch(r.label){case 0:return[4,Promise.all(t.map((function(r,u){return n.call(e,r,u,t)})))];case 1:return r.sent(),[2]}}))}))},t.forEachIndex=g,t.forEachKey=_,t.forEachSeries=function(t,n,e){return I(void 0,void 0,void 0,(function(){var r;return P(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<t.length?[4,n.call(e,t[r],r,t)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},t.isArray=e,t.isBoolean=r,t.isDef=u,t.isFloat=function(t){return i(t)&&!!(t%1)},t.isFunction=function(t){return"function"==c(t)},t.isInteger=function(t){return i(t)&&!(t%1)},t.isNull=function(t){return null===t},t.isNumber=i,t.isObject=o,t.isString=a,t.isUndefined=s,t.loop=function(t,n,e){for(var r=1;r<=t&&!1!==n.call(e,r,t);r++);return t},t.lowerCamelCase=w,t.map=function(t,n,e){for(var r="",u=Object.keys(t),i=0;i<u.length;i++)t[r=u[i]]=n.call(e,t[r],r,t);return t},t.mask=S,t.maskMoney=function(t,n,e){return e++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),E(t,n.length<e?("0".repeat(e)+n).slice(-1*e):n)},t.maskReverse=E,t.noop=function(){},t.parseSize=function(t){if(i(t))return t+"px";var n=function(t){return/(\d+)\.*(\d*)(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(t)}(t)||["","0","",""],e=n[1],r=n[2],u=n[3];return(r.length?parseFloat(e+"."+r):parseInt(e))+(u||"px")},t.shadeColor=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+f(t,n)).slice(-2)}))},t.simpleID=function(){return h()+v()},t.sleep=function(t){return new Promise((function(n){return setTimeout(n,t)}))},t.stringReverse=j,t.toArray=function(t){return e(t)?t:u(t)?[t]:[]},t.toBool=function(t){return"true"===t||"1"===t},t.type=c,t.uniqueID=function(){return m()+m()+m()+m()},t.upperCamelCase=k,t.uuidv4=function(){return y()+"-"+v()+"-4"+h()+"-"+v()+"-"+(y()+v())},Object.defineProperty(t,"__esModule",{value:!0}),t}({});
7
+ var UtilsJS=function(t){"use strict";var n={},r=function(t){return"array"==c(t)},e=function(t){return"boolean"==c(t)},u=function(t){return"null"!=c(t)},i=function(t){return"number"==c(t)},o=function(t){return"object"==c(t)},a=function(t){return"string"==c(t)},s=function(t){return void 0===t},c=function(t){return null==t?"null":n[n.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return n["[object "+t+"]"]=t.toLowerCase()}));var l=function(t,n,r){return Math.max(n,Math.min(r,t))},f=function(t,n){return(r=parseInt(t,16)+n,l(r,0,255)).toString(16);var r},p=function(t){return Math.random().toString(16).slice(t)},h=function(){return p(-3)},v=function(){return p(-4)},y=function(){return v()+v()},m=function(){return y()+y()},d=function(){function t(){this.events=new Map}return t.prototype.on=function(t,n){var r=this,e=this.events.get(t);return e?e.push(n):this.events.set(t,[n]),{dispose:function(){return r.off(t,n)}}},t.prototype.once=function(t,n){var r=this,e=function(u){n(u),r.off(t,e)};return this.on(t,e),{dispose:function(){return r.off(t,e)}}},t.prototype.off=function(t,n){var r=this.events.get(t);if(n){if(r){var e=r.indexOf(n);e>=0&&r.splice(e,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,n){var r=this.events.get(t);r&&r.forEach((function(t){return t(n)}))},t}(),g=function(t,n,r){for(var e=0;e<t.length&&!1!==n.call(r,t[e],e,t);e++);return t},_=function(t,n,r){for(var e="",u=Object.keys(t),i=0;i<u.length&&(e=u[i],!1!==n.call(r,t[e],e,t));i++);return t},b=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},w=function(t){return b(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},x=w,k=function(t){return b(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,r){return n.toUpperCase()+r}))}))},C=function(t){return t.split("").reverse().join("")},j=function(t){return/^[A-Za-z]$/.test(t)},O=function(t,n,r){r.mask++,r.text++;var e=t[r.mask],u=n[r.text];return s(e)||s(u)?"":function(t,n,r){switch(t.toUpperCase()){case"#":return n;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(n)?n:(r.mask--,"");case"A":case"Z":return j(n)?n:(r.mask--,"");case"L":return j(n)?n.toLowerCase():(r.mask--,"");case"U":return j(n)?n.toUpperCase():(r.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(n)?n:(r.mask--,"");default:return t!=n&&r.text--,t}}(e,u,r)+O(t,n,r)},S=function(t,n){return O(t,n,{mask:-1,text:-1})},A=S,E=function(t,n){return C(A(C(t),C(n)))},M=function(t,n){return M=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])},M(t,n)};function F(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}M(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var U=function(){return U=Object.assign||function(t){for(var n,r=1,e=arguments.length;r<e;r++)for(var u in n=arguments[r])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t},U.apply(this,arguments)};function I(t,n,r,e){return new(r||(r=Promise))((function(u,i){function o(t){try{s(e.next(t))}catch(t){i(t)}}function a(t){try{s(e.throw(t))}catch(t){i(t)}}function s(t){var n;t.done?u(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(o,a)}s((e=e.apply(t,n||[])).next())}))}function P(t,n){var r,e,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(o=0)),o;)try{if(r=1,e&&(u=2&a[0]?e.return:a[0]?e.throw||((u=e.return)&&u.call(e),0):e.next)&&!(u=u.call(e,a[1])).done)return u;switch(e=0,u&&(a=[2&a[0],u.value]),a[0]){case 0:case 1:u=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,e=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(u=o.trys,(u=u.length>0&&u[u.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!u||a[1]>u[0]&&a[1]<u[3])){o.label=a[1];break}if(6===a[0]&&o.label<u[1]){o.label=u[1],u=a;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(a);break}u[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(t,o)}catch(t){a=[6,t],e=0}finally{r=u=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function T(t,n,r){if(r||2===arguments.length)for(var e,u=0,i=n.length;u<i;u++)!e&&u in n||(e||(e=Array.prototype.slice.call(n,0,u)),e[u]=n[u]);return t.concat(e||Array.prototype.slice.call(n))}var q=function(t,n){return t.reduce((function(t,r){var e;return U(U({},t),((e={})[r]=n[r],e))}),{})},L=function(){function t(){this.name="",this._error="",this._type="any",this.rules=[],this.custom=[]}return t.prototype.empty=function(t){var n=this;return this.value=t,this.unshift((function(t){var r=u(t);return{break:!r,value:r?t:n.value}}))},t.prototype.error=function(t){return this._error=t,this},t.prototype.invalid=function(t){return{error:this._error?this._error:this.name?this.name+":"+t:t}},t.prototype.parse=function(){return this.unshift((function(t){return{value:t}}))},t.prototype.push=function(t){return this.rules.push(t),this},t.prototype.required=function(){var t=this;return this.unshift((function(n){return u(n)?{value:n}:t.invalid("["+t._type+"].required")}))},t.prototype.test=function(t){return!a(this.validate(t).error)},t.prototype.testAsync=function(t){return I(this,void 0,void 0,(function(){var n;return P(this,(function(r){switch(r.label){case 0:return n=a,[4,this.validateAsync(t)];case 1:return[2,!n.apply(void 0,[r.sent().error])]}}))}))},t.prototype.unshift=function(t){return this.rules.unshift(t),this},t.prototype.validate=function(t){if(this.custom.length)return this.invalid("[async]");for(var n={value:t},r=0;r<this.rules.length;r++){if((n=this.rules[r](n.value)).error)return{error:n.error};if(n.break)return{value:n.value}}return{value:n.value}},t.prototype.validateAsync=function(t){return I(this,void 0,void 0,(function(){var n,r;return P(this,(function(e){switch(e.label){case 0:if((n=this.validate(t)).error)return[2,{error:n.error}];r=0,e.label=1;case 1:return r<this.custom.length?[4,this.custom[r](n.value)]:[3,4];case 2:if((n=e.sent()).error)return[2,{error:n.error}];e.label=3;case 3:return r++,[3,1];case 4:return[2,{value:n.value}]}}))}))},t}(),B=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="array",n.push((function(t){if(r(t)){if(n._items){n._items.name="";for(var e=0;e<t.length;e++){var u=n._items.validate(t[e]),i=u.error,o=u.value;if(i)return n.invalid("["+n._type+"]< "+i+"["+e+"] >");t[e]=o}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.items=function(t){return this._items=t,this},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n}(L),D=function(t){function n(){var n=t.call(this)||this;return n._type="boolean",n.push((function(t){return e(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:u(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(L),N=function(t){function n(){var n=t.call(this)||this;return n._max=0,n._min=0,n._type="number",n.push((function(t){return i(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:u(t)?parseFloat(t):t}}))},n}(L),Y=function(t){function n(){var n=t.call(this)||this;return n._type="object",n.push((function(t){if(o(t)){if(n._keys){var r=[];return Object.keys(n._keys).forEach((function(e){if(n._keys){var i=n._keys[e];i.name=e;var o=i.validate(t[e]),a=o.error,s=o.value;a&&r.push(a),u(s)&&(t[e]=s)}})),r.length?n.invalid("["+n._type+"]{ "+r.join(", ")+" }"):{value:t}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(L),$=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="string",n.push((function(t){return a(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.email=function(){var t=this;return this.push((function(n){return/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(n)?{value:n}:t.invalid("["+t._type+"].email")}))},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.lowerCase=function(){return this.push((function(t){return{value:t.toLowerCase()}}))},n.prototype.lowerCamelCase=function(){return this.push((function(t){return{value:w(t)}}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.mask=function(t){return this.push((function(n){return{value:S(t,n)}}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:o(t)?JSON.stringify(t):u(t)?t.toString():t}}))},n.prototype.required=function(){var t=this;return this.push((function(n){return n.length?{value:n}:t.invalid("["+t._type+"].required")}))},n.prototype.trim=function(){return this.push((function(t){return{value:t.trim()}}))},n.prototype.upperCase=function(){return this.push((function(t){return{value:t.toUpperCase()}}))},n.prototype.upperCamelCase=function(){return this.push((function(t){return{value:k(t)}}))},n}(L),z=function(){function t(){}return t.array=function(t){return(new B).items(t)},t.boolean=function(){return new D},t.number=function(){return new N},t.object=function(t){return(new Y).keys(t)},t.string=function(){return new $},t.prototype.test=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return!a(t.validate.apply(t,T([n],r,!1)).error)},t.prototype.testAsync=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return I(this,void 0,void 0,(function(){var e;return P(this,(function(u){switch(u.label){case 0:return e=a,[4,t.validateAsync.apply(t,T([n],r,!1))];case 1:return[2,!e.apply(void 0,[u.sent().error])]}}))}))},t.validate=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];for(var e={value:t},u=0;u<n.length;u++)if((e=n[u].validate(e.value)).error)return{error:e.error};return e},t.validateAsync=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return I(this,void 0,void 0,(function(){var r,e;return P(this,(function(u){switch(u.label){case 0:r={value:t},e=0,u.label=1;case 1:return e<n.length?[4,n[e].validateAsync(r.value)]:[3,4];case 2:if((r=u.sent()).error)return[2,{error:r.error}];u.label=3;case 3:return e++,[3,1];case 4:return[2,r]}}))}))},t}();return t.EventEmitter=d,t.Validation=z,t.ValidationBase=L,t.allowedObject=q,t.camelCase=x,t.chunkArray=function(t,n){for(var r=[],e=0;e<t.length;e+=n)r.push(t.slice(e,e+n));return r},t.clamp=l,t.cutText=function(t,n){if(t.length>n){var r=t.substring(0,n).split(" ");return r.pop(),r.join(" ")+"..."}return t},t.dateFormat=function(t,n){return n.replace(/%[yYmdHMS]/g,(function(n){var r;switch(n){case"%y":r=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":r=t.getMonth()+1;break;case"%d":r=t.getDate();break;case"%H":r=t.getHours();break;case"%M":r=t.getMinutes();break;case"%S":r=t.getSeconds();break;default:return n.slice(1)}return("0"+r.toString()).slice(-2)}))},t.debounce=function(t,n){var r;return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];r&&clearTimeout(r),r=setTimeout((function(){return t.apply(void 0,e)}),n)}},t.deniedObject=function(t,n){return q(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},t.each=function(t,n,e){return r(t)?g(t,n,e):o(t)?_(t,n,e):null},t.forEachAsync=function(t,n,r){return I(void 0,void 0,void 0,(function(){return P(this,(function(e){switch(e.label){case 0:return[4,Promise.all(t.map((function(e,u){return n.call(r,e,u,t)})))];case 1:return e.sent(),[2]}}))}))},t.forEachIndex=g,t.forEachKey=_,t.forEachSeries=function(t,n,r){return I(void 0,void 0,void 0,(function(){var e;return P(this,(function(u){switch(u.label){case 0:e=0,u.label=1;case 1:return e<t.length?[4,n.call(r,t[e],e,t)]:[3,4];case 2:u.sent(),u.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},t.isArray=r,t.isBoolean=e,t.isDef=u,t.isFloat=function(t){return i(t)&&!!(t%1)},t.isFunction=function(t){return"function"==c(t)},t.isInteger=function(t){return i(t)&&!(t%1)},t.isNull=function(t){return null===t},t.isNumber=i,t.isObject=o,t.isString=a,t.isUndefined=s,t.loop=function(t,n,r){for(var e=1;e<=t&&!1!==n.call(r,e,t);e++);return t},t.lowerCamelCase=w,t.map=function(t,n,r){for(var e="",u=Object.keys(t),i=0;i<u.length;i++)t[e=u[i]]=n.call(r,t[e],e,t);return t},t.mask=S,t.maskMoney=function(t,n,r){return r++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),E(t,n.length<r?("0".repeat(r)+n).slice(-1*r):n)},t.maskReverse=E,t.noop=function(){},t.parseSize=function(t){if(i(t))return t+"px";var n=function(t){return/(\d+)\.*(\d*)(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(t)}(t)||["","0","",""],r=n[1],e=n[2],u=n[3];return(e.length?parseFloat(r+"."+e):parseInt(r))+(u||"px")},t.shadeColor=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+f(t,n)).slice(-2)}))},t.simpleID=function(){return h()+v()},t.sleep=function(t){return new Promise((function(n){return setTimeout(n,t)}))},t.stringReverse=C,t.toArray=function(t){return r(t)?t:u(t)?[t]:[]},t.toBool=function(t){return"true"===t||"1"===t},t.type=c,t.uniqueID=function(){return m()+m()+m()+m()},t.upperCamelCase=k,t.uuidv4=function(){return y()+"-"+v()+"-4"+h()+"-"+v()+"-"+(y()+v())},t}({});
package/package.json CHANGED
@@ -1,15 +1,27 @@
1
1
  {
2
2
  "name": "@andrewcaires/utils.js",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "JavaScript utility library for web and nodejs development",
5
- "main": "dist/index.umd.js",
6
- "module": "dist/index.esm.js",
7
- "unpkg": "dist/index.min.js",
8
- "types": "dist/index.d.ts",
5
+ "main": "./dist/index.cjs.js",
6
+ "unpkg": "./dist/index.min.js",
7
+ "types": "./dist/index.d.ts",
8
+ "module": "./dist/index.esm.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.esm.js",
13
+ "browser": "./dist/index.min.js",
14
+ "require": "./dist/index.cjs.js",
15
+ "default": "./dist/index.cjs.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
9
22
  "scripts": {
10
- "build": "rollup -c build/rollup.config.js",
11
- "dev": "ts-node-dev --respawn --transpile-only ./src/index.ts",
12
- "lint": "eslint --ext .ts --fix src"
23
+ "build": "rollup --bundleConfigAsCjs -c rollup.config.js",
24
+ "dev": "ts-node-dev --respawn --transpile-only ./src/index.ts"
13
25
  },
14
26
  "repository": {
15
27
  "type": "git",
@@ -31,15 +43,16 @@
31
43
  },
32
44
  "homepage": "https://github.com/andrewcaires/npm/tree/main/utils.js#readme",
33
45
  "devDependencies": {
34
- "@rollup/plugin-commonjs": "^23.0.0",
35
- "@rollup/plugin-typescript": "^9.0.1",
36
- "@typescript-eslint/eslint-plugin": "^5.40.0",
37
- "@typescript-eslint/parser": "^5.40.0",
38
- "eslint": "^8.25.0",
39
- "rollup": "^2.79.1",
40
- "rollup-plugin-dts": "^4.2.3",
41
- "rollup-plugin-terser": "^7.0.2",
46
+ "@rollup/plugin-commonjs": "^23.0.2",
47
+ "@rollup/plugin-terser": "^0.1.0",
48
+ "@rollup/plugin-typescript": "^9.0.2",
49
+ "@types/node": "^18.11.9",
50
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
51
+ "@typescript-eslint/parser": "^5.42.0",
52
+ "eslint": "^8.26.0",
53
+ "rollup": "^3.2.5",
54
+ "rollup-plugin-dts": "^5.0.0",
42
55
  "ts-node-dev": "^2.0.0",
43
- "tslib": "^2.4.0"
56
+ "tslib": "^2.4.1"
44
57
  }
45
58
  }
package/dist/index.umd.js DELETED
@@ -1,7 +0,0 @@
1
- /*!
2
- * @andrewcaires/utils.js v0.2.3
3
- * JavaScript utility library for web and nodejs development
4
- * (c) 2022 Andrew Caires
5
- * @license: MIT
6
- */
7
- !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).UtilsJS={})}(this,(function(t){"use strict";var n={},e=function(t){return"array"==c(t)},r=function(t){return"boolean"==c(t)},u=function(t){return"null"!=c(t)},i=function(t){return"number"==c(t)},o=function(t){return"object"==c(t)},a=function(t){return"string"==c(t)},s=function(t){return void 0===t},c=function(t){return null==t?"null":n[n.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return n["[object "+t+"]"]=t.toLowerCase()}));var l=function(t,n,e){return Math.max(n,Math.min(e,t))},f=function(t,n){return(e=parseInt(t,16)+n,l(e,0,255)).toString(16);var e},p=function(t){return Math.random().toString(16).slice(t)},h=function(){return p(-3)},v=function(){return p(-4)},y=function(){return v()+v()},m=function(){return y()+y()},d=function(){function t(){this.events=new Map}return t.prototype.on=function(t,n){var e=this,r=this.events.get(t);return r?r.push(n):this.events.set(t,[n]),{dispose:function(){return e.off(t,n)}}},t.prototype.once=function(t,n){var e=this,r=function(u){n(u),e.off(t,r)};return this.on(t,r),{dispose:function(){return e.off(t,r)}}},t.prototype.off=function(t,n){var e=this.events.get(t);if(n){if(e){var r=e.indexOf(n);r>=0&&e.splice(r,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,n){var e=this.events.get(t);e&&e.forEach((function(t){return t(n)}))},t}(),g=function(t,n,e){for(var r=0;r<t.length&&!1!==n.call(e,t[r],r,t);r++);return t},_=function(t,n,e){for(var r="",u=Object.keys(t),i=0;i<u.length&&(r=u[i],!1!==n.call(e,t[r],r,t));i++);return t},b=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},w=function(t){return b(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},x=w,k=function(t){return b(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,e){return n.toUpperCase()+e}))}))},j=function(t){return t.split("").reverse().join("")},C=function(t){return/^[A-Za-z]$/.test(t)},O=function(t,n,e){e.mask++,e.text++;var r=t[e.mask],u=n[e.text];return s(r)||s(u)?"":function(t,n,e){switch(t.toUpperCase()){case"#":return n;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(n)?n:(e.mask--,"");case"A":case"Z":return C(n)?n:(e.mask--,"");case"L":return C(n)?n.toLowerCase():(e.mask--,"");case"U":return C(n)?n.toUpperCase():(e.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(n)?n:(e.mask--,"");default:return t!=n&&e.text--,t}}(r,u,e)+O(t,n,e)},S=function(t,n){return O(t,n,{mask:-1,text:-1})},A=S,E=function(t,n){return j(A(j(t),j(n)))},M=function(t,n){return M=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])},M(t,n)};function F(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=t}M(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}var T=function(){return T=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t},T.apply(this,arguments)};function U(t,n,e,r){return new(e||(e=Promise))((function(u,i){function o(t){try{s(r.next(t))}catch(t){i(t)}}function a(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var n;t.done?u(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(o,a)}s((r=r.apply(t,n||[])).next())}))}function I(t,n){var e,r,u,i,o={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;o;)try{if(e=1,r&&(u=2&i[0]?r.return:i[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,i[1])).done)return u;switch(r=0,u&&(i=[2&i[0],u.value]),i[0]){case 0:case 1:u=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(u=o.trys,(u=u.length>0&&u[u.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!u||i[1]>u[0]&&i[1]<u[3])){o.label=i[1];break}if(6===i[0]&&o.label<u[1]){o.label=u[1],u=i;break}if(u&&o.label<u[2]){o.label=u[2],o.ops.push(i);break}u[2]&&o.ops.pop(),o.trys.pop();continue}i=n.call(t,o)}catch(t){i=[6,t],r=0}finally{e=u=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function P(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||Array.prototype.slice.call(n))}var q=function(t,n){return t.reduce((function(t,e){var r;return T(T({},t),((r={})[e]=n[e],r))}),{})},L=function(){function t(){this.name="",this._error="",this._type="any",this.rules=[],this.custom=[]}return t.prototype.empty=function(t){var n=this;return this.value=t,this.unshift((function(t){var e=u(t);return{break:!e,value:e?t:n.value}}))},t.prototype.error=function(t){return this._error=t,this},t.prototype.invalid=function(t){return{error:this._error?this._error:this.name?this.name+":"+t:t}},t.prototype.parse=function(){return this.unshift((function(t){return{value:t}}))},t.prototype.push=function(t){return this.rules.push(t),this},t.prototype.required=function(){var t=this;return this.unshift((function(n){return u(n)?{value:n}:t.invalid("["+t._type+"].required")}))},t.prototype.test=function(t){return!a(this.validate(t).error)},t.prototype.testAsync=function(t){return U(this,void 0,void 0,(function(){var n;return I(this,(function(e){switch(e.label){case 0:return n=a,[4,this.validateAsync(t)];case 1:return[2,!n.apply(void 0,[e.sent().error])]}}))}))},t.prototype.unshift=function(t){return this.rules.unshift(t),this},t.prototype.validate=function(t){if(this.custom.length)return this.invalid("[async]");for(var n={value:t},e=0;e<this.rules.length;e++){if((n=this.rules[e](n.value)).error)return{error:n.error};if(n.break)return{value:n.value}}return{value:n.value}},t.prototype.validateAsync=function(t){return U(this,void 0,void 0,(function(){var n,e;return I(this,(function(r){switch(r.label){case 0:if((n=this.validate(t)).error)return[2,{error:n.error}];e=0,r.label=1;case 1:return e<this.custom.length?[4,this.custom[e](n.value)]:[3,4];case 2:if((n=r.sent()).error)return[2,{error:n.error}];r.label=3;case 3:return e++,[3,1];case 4:return[2,{value:n.value}]}}))}))},t}(),B=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="array",n.push((function(t){if(e(t)){if(n._items){n._items.name="";for(var r=0;r<t.length;r++){var u=n._items.validate(t[r]),i=u.error,o=u.value;if(i)return n.invalid("["+n._type+"]< "+i+"["+r+"] >");t[r]=o}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.items=function(t){return this._items=t,this},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n}(L),D=function(t){function n(){var n=t.call(this)||this;return n._type="boolean",n.push((function(t){return r(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:u(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(L),N=function(t){function n(){var n=t.call(this)||this;return n._max=0,n._min=0,n._type="number",n.push((function(t){return i(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:u(t)?parseFloat(t):t}}))},n}(L),Y=function(t){function n(){var n=t.call(this)||this;return n._type="object",n.push((function(t){if(o(t)){if(n._keys){var e=[];return Object.keys(n._keys).forEach((function(r){if(n._keys){var i=n._keys[r];i.name=r;var o=i.validate(t[r]),a=o.error,s=o.value;a&&e.push(a),u(s)&&(t[r]=s)}})),e.length?n.invalid("["+n._type+"]{ "+e.join(", ")+" }"):{value:t}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(L),$=function(t){function n(){var n=t.call(this)||this;return n._length=0,n._max=0,n._min=0,n._type="string",n.push((function(t){return a(t)?{value:t}:n.invalid("["+n._type+"]")})),n}return F(n,t),n.prototype.between=function(t,n){return this.min(t),this.max(n)},n.prototype.email=function(){var t=this;return this.push((function(n){return/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(n)?{value:n}:t.invalid("["+t._type+"].email")}))},n.prototype.length=function(t){var n=this;return this._length=t,this.push((function(t){return t.length==n._length?{value:t}:n.invalid("["+n._type+"].length("+n._length+")")}))},n.prototype.lowerCase=function(){return this.push((function(t){return{value:t.toLowerCase()}}))},n.prototype.lowerCamelCase=function(){return this.push((function(t){return{value:w(t)}}))},n.prototype.max=function(t){var n=this;return this._max=t,this.push((function(t){return t.length<=n._max?{value:t}:n.invalid("["+n._type+"].max("+n._max+")")}))},n.prototype.mask=function(t){return this.push((function(n){return{value:S(t,n)}}))},n.prototype.min=function(t){var n=this;return this._min=t,this.push((function(t){return t.length>=n._min?{value:t}:n.invalid("["+n._type+"].min("+n._min+")")}))},n.prototype.parse=function(){return this.unshift((function(t){return{value:o(t)?JSON.stringify(t):u(t)?t.toString():t}}))},n.prototype.required=function(){var t=this;return this.push((function(n){return n.length?{value:n}:t.invalid("["+t._type+"].required")}))},n.prototype.trim=function(){return this.push((function(t){return{value:t.trim()}}))},n.prototype.upperCase=function(){return this.push((function(t){return{value:t.toUpperCase()}}))},n.prototype.upperCamelCase=function(){return this.push((function(t){return{value:k(t)}}))},n}(L),z=function(){function t(){}return t.array=function(t){return(new B).items(t)},t.boolean=function(){return new D},t.number=function(){return new N},t.object=function(t){return(new Y).keys(t)},t.string=function(){return new $},t.prototype.test=function(n){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return!a(t.validate.apply(t,P([n],e,!1)).error)},t.prototype.testAsync=function(n){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return U(this,void 0,void 0,(function(){var r;return I(this,(function(u){switch(u.label){case 0:return r=a,[4,t.validateAsync.apply(t,P([n],e,!1))];case 1:return[2,!r.apply(void 0,[u.sent().error])]}}))}))},t.validate=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];for(var r={value:t},u=0;u<n.length;u++)if((r=n[u].validate(r.value)).error)return{error:r.error};return r},t.validateAsync=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return U(this,void 0,void 0,(function(){var e,r;return I(this,(function(u){switch(u.label){case 0:e={value:t},r=0,u.label=1;case 1:return r<n.length?[4,n[r].validateAsync(e.value)]:[3,4];case 2:if((e=u.sent()).error)return[2,{error:e.error}];u.label=3;case 3:return r++,[3,1];case 4:return[2,e]}}))}))},t}();t.EventEmitter=d,t.Validation=z,t.ValidationBase=L,t.allowedObject=q,t.camelCase=x,t.chunkArray=function(t,n){for(var e=[],r=0;r<t.length;r+=n)e.push(t.slice(r,r+n));return e},t.clamp=l,t.cutText=function(t,n){if(t.length>n){var e=t.substring(0,n).split(" ");return e.pop(),e.join(" ")+"..."}return t},t.dateFormat=function(t,n){return n.replace(/%[yYmdHMS]/g,(function(n){var e;switch(n){case"%y":e=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":e=t.getMonth()+1;break;case"%d":e=t.getDate();break;case"%H":e=t.getHours();break;case"%M":e=t.getMinutes();break;case"%S":e=t.getSeconds();break;default:return n.slice(1)}return("0"+e.toString()).slice(-2)}))},t.debounce=function(t,n){var e;return function(){for(var r=[],u=0;u<arguments.length;u++)r[u]=arguments[u];e&&clearTimeout(e),e=setTimeout((function(){return t.apply(void 0,r)}),n)}},t.deniedObject=function(t,n){return q(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},t.each=function(t,n,r){return e(t)?g(t,n,r):o(t)?_(t,n,r):null},t.forEachAsync=function(t,n,e){return U(void 0,void 0,void 0,(function(){return I(this,(function(r){switch(r.label){case 0:return[4,Promise.all(t.map((function(r,u){return n.call(e,r,u,t)})))];case 1:return r.sent(),[2]}}))}))},t.forEachIndex=g,t.forEachKey=_,t.forEachSeries=function(t,n,e){return U(void 0,void 0,void 0,(function(){var r;return I(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<t.length?[4,n.call(e,t[r],r,t)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},t.isArray=e,t.isBoolean=r,t.isDef=u,t.isFloat=function(t){return i(t)&&!!(t%1)},t.isFunction=function(t){return"function"==c(t)},t.isInteger=function(t){return i(t)&&!(t%1)},t.isNull=function(t){return null===t},t.isNumber=i,t.isObject=o,t.isString=a,t.isUndefined=s,t.loop=function(t,n,e){for(var r=1;r<=t&&!1!==n.call(e,r,t);r++);return t},t.lowerCamelCase=w,t.map=function(t,n,e){for(var r="",u=Object.keys(t),i=0;i<u.length;i++)t[r=u[i]]=n.call(e,t[r],r,t);return t},t.mask=S,t.maskMoney=function(t,n,e){return e++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),E(t,n.length<e?("0".repeat(e)+n).slice(-1*e):n)},t.maskReverse=E,t.noop=function(){},t.parseSize=function(t){if(i(t))return t+"px";var n=function(t){return/(\d+)\.*(\d*)(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(t)}(t)||["","0","",""],e=n[1],r=n[2],u=n[3];return(r.length?parseFloat(e+"."+r):parseInt(e))+(u||"px")},t.shadeColor=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+f(t,n)).slice(-2)}))},t.simpleID=function(){return h()+v()},t.sleep=function(t){return new Promise((function(n){return setTimeout(n,t)}))},t.stringReverse=j,t.toArray=function(t){return e(t)?t:u(t)?[t]:[]},t.toBool=function(t){return"true"===t||"1"===t},t.type=c,t.uniqueID=function(){return m()+m()+m()+m()},t.upperCamelCase=k,t.uuidv4=function(){return y()+"-"+v()+"-4"+h()+"-"+v()+"-"+(y()+v())},Object.defineProperty(t,"__esModule",{value:!0})}));