@andrewcaires/utils.js 0.2.1 → 0.2.3

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.1
2
+ * @andrewcaires/utils.js v0.2.3
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2022 Andrew Caires
5
5
  * @license: MIT
@@ -64,6 +64,8 @@ declare const mask: (mask: string, text: string) => string;
64
64
  declare const maskMoney: (mask: string, text: string, decimal: number) => string;
65
65
  declare const maskReverse: (mask: string, text: string) => string;
66
66
 
67
+ declare const clamp: (value: number, min: number, max: number) => number;
68
+
67
69
  declare const allowedObject: (allowed: string[], raw: TypeObjectAny) => TypeObjectAny;
68
70
  declare const deniedObject: (denied: string[], raw: TypeObjectAny) => TypeObjectAny;
69
71
 
@@ -112,11 +114,11 @@ declare class ValidationBase<T = any> {
112
114
  parse(): this;
113
115
  push(callback: ValidationCallback): this;
114
116
  required(): this;
115
- test(value: any): boolean;
116
- testAsync(value: any): Promise<boolean>;
117
+ test(value?: any): boolean;
118
+ testAsync(value?: any): Promise<boolean>;
117
119
  unshift(callback: ValidationCallback): this;
118
- validate(value: any): ValidationResult;
119
- validateAsync(value: any): Promise<ValidationResult>;
120
+ validate(value?: any): ValidationResult;
121
+ validateAsync(value?: any): Promise<ValidationResult>;
120
122
  }
121
123
  declare class ValidationArray extends ValidationBase<Array<any>> {
122
124
  private _length;
@@ -161,10 +163,16 @@ declare class ValidationString extends ValidationBase<string> {
161
163
  between(min: number, max: number): this;
162
164
  email(): this;
163
165
  length(value: number): this;
166
+ lowerCase(): this;
167
+ lowerCamelCase(): this;
164
168
  max(value: number): this;
169
+ mask(parse: string): this;
165
170
  min(value: number): this;
166
171
  parse(): this;
167
172
  required(): this;
173
+ trim(): this;
174
+ upperCase(): this;
175
+ upperCamelCase(): this;
168
176
  }
169
177
  declare class Validation {
170
178
  static array(value?: ValidationBase): ValidationArray;
@@ -172,10 +180,10 @@ declare class Validation {
172
180
  static number(): ValidationNumber;
173
181
  static object(value?: TypeObject<ValidationBase>): ValidationObject;
174
182
  static string(): ValidationString;
175
- test(value: any, ...rules: Array<ValidationBase>): boolean;
176
- testAsync(value: any, ...rules: Array<ValidationBase>): Promise<boolean>;
177
- static validate(value: any, ...rules: Array<ValidationBase>): ValidationResult;
178
- static validateAsync(value: any, ...rules: Array<ValidationBase>): Promise<ValidationResult>;
183
+ test(value?: any, ...rules: Array<ValidationBase>): boolean;
184
+ testAsync(value?: any, ...rules: Array<ValidationBase>): Promise<boolean>;
185
+ static validate(value?: any, ...rules: Array<ValidationBase>): ValidationResult;
186
+ static validateAsync(value?: any, ...rules: Array<ValidationBase>): Promise<ValidationResult>;
179
187
  }
180
188
 
181
- export { EventCallback, EventDisposable, EventEmitter, EventList, TypeArray, TypeArrayAny, TypeArrayFunction, TypeArrayNumber, TypeArrayString, TypeCallback, TypeCallbackArray, TypeCallbackFunction, TypeCallbackMap, TypeCallbackObject, TypeObject, TypeObjectAny, TypeObjectFunction, TypeObjectNumber, TypeObjectString, Validation, ValidationBase, allowedObject, camelCase, chunkArray, cutText, dateFormat, debounce, deniedObject, each, forEachAsync, forEachIndex, forEachKey, forEachSeries, isArray, isBoolean, isDef, isFloat, isFunction, isInteger, isNull, isNumber, isObject, isString, isUndefined, loop, lowerCamelCase, map, mask, maskMoney, maskReverse, noop, parseSize, shadeColor, simpleID, sleep, stringReverse, toArray, toBool, type, uniqueID, upperCamelCase, uuidv4 };
189
+ export { EventCallback, EventDisposable, EventEmitter, EventList, TypeArray, TypeArrayAny, TypeArrayFunction, TypeArrayNumber, TypeArrayString, TypeCallback, TypeCallbackArray, TypeCallbackFunction, TypeCallbackMap, TypeCallbackObject, TypeObject, TypeObjectAny, TypeObjectFunction, TypeObjectNumber, TypeObjectString, Validation, ValidationBase, allowedObject, camelCase, chunkArray, clamp, cutText, dateFormat, debounce, deniedObject, each, forEachAsync, forEachIndex, forEachKey, forEachSeries, isArray, isBoolean, isDef, isFloat, isFunction, isInteger, isNull, isNumber, isObject, isString, isUndefined, loop, lowerCamelCase, map, mask, maskMoney, maskReverse, noop, parseSize, shadeColor, simpleID, sleep, stringReverse, toArray, toBool, type, uniqueID, upperCamelCase, uuidv4 };
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.1
2
+ * @andrewcaires/utils.js v0.2.3
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"==h(t)},r=function(t){return"boolean"==h(t)},e=function(t){return"null"!=h(t)},u=function(t){return"function"==h(t)},i=function(t){return"number"==h(t)},o=function(t){return"object"==h(t)},a=function(t){return"string"==h(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},h=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 p=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){return(r=parseInt(t,16)+n,Math.min(255,Math.max(0,r))).toString(16);var r},g=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+m(t,n)).slice(-2)}))},d=function(t){return Math.random().toString(16).slice(t)},_=function(){return d(-3)},b=function(){return d(-4)},w=function(){return b()+b()},x=function(){return w()+w()},k=function(){return _()+b()},j=function(){return x()+x()+x()+x()},O=function(){return w()+"-"+b()+"-4"+_()+"-"+b()+"-"+(w()+b())},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)}},C=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}(),M=function(t,n,r){for(var e=0;e<t.length&&!1!==n.call(r,t[e],e,t);e++);return t},P=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)?M(t,r,e):o(t)?P(t,r,e):null},F=function(t,n,r){for(var e=1;e<=t&&!1!==n.call(r,e,t);e++);return t},T=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},U=function(){},q=function(t,n){if(t.length>n){var r=t.substring(0,n).split(" ");return r.pop(),r.join(" ")+"..."}return t},L=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},Y=function(t){return L(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},$=Y,H=function(t){return L(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,r){return n.toUpperCase()+r}))}))},I=function(t){return t.split("").reverse().join("")},Z=function(t){return/^[A-Za-z]$/.test(t)},z=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)+z(t,n,r)},N=function(t,n){return z(t,n,{mask:-1,text:-1})},W=function(t,n,r){return r++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),D(t,n.length<r?("0".repeat(r)+n).slice(-1*r):n)},B=N,D=function(t,n){return I(B(I(t),I(n)))},G=function(t,n){return G=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])},G(t,n)};function J(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}G(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var K=function(){return K=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},K.apply(this,arguments)};function Q(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 R(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 V(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 X=function(t,n){return t.reduce((function(t,r){var e;return K(K({},t),((e={})[r]=n[r],e))}),{})},tt=function(t,n){return X(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},nt=function(t,n,r){return Q(void 0,void 0,void 0,(function(){return R(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]}}))}))},rt=function(t,n,r){return Q(void 0,void 0,void 0,(function(){var e;return R(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]}}))}))},et=function(t){return new Promise((function(n){return setTimeout(n,t)}))},ut=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")},it=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 Q(this,void 0,void 0,(function(){var n;return R(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 Q(this,void 0,void 0,(function(){var n,r;return R(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}(),ot=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 J(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}(it),at=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 J(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:e(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(it),ct=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 J(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}(it),st=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 J(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(it),lt=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 J(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.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.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.trin().length?{value:n}:t.invalid("["+t._type+"].required")}))},n}(it),ft=function(){function t(){}return t.array=function(t){return(new ot).items(t)},t.boolean=function(){return new at},t.number=function(){return new ct},t.object=function(t){return(new st).keys(t)},t.string=function(){return new lt},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,V([n],r,!1)).error)},t.prototype.testAsync=function(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return Q(this,void 0,void 0,(function(){var e;return R(this,(function(u){switch(u.label){case 0:return e=a,[4,t.validateAsync.apply(t,V([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 Q(this,void 0,void 0,(function(){var r,e;return R(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{C as EventEmitter,ft as Validation,it as ValidationBase,X as allowedObject,$ as camelCase,p as chunkArray,q as cutText,S as dateFormat,A as debounce,tt as deniedObject,E as each,nt as forEachAsync,M as forEachIndex,P as forEachKey,rt 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,Y as lowerCamelCase,T as map,N as mask,W as maskMoney,D as maskReverse,U as noop,ut as parseSize,g as shadeColor,k as simpleID,et as sleep,I as stringReverse,v as toArray,y as toBool,h as type,j as uniqueID,H as upperCamelCase,O 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(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};
package/dist/index.min.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.1
2
+ * @andrewcaires/utils.js v0.2.3
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)},i=function(t){return"null"!=c(t)},u=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){return(e=parseInt(t,16)+n,Math.min(255,Math.max(0,e))).toString(16);var e},f=function(t){return Math.random().toString(16).slice(t)},p=function(){return f(-3)},h=function(){return f(-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 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(i){n(i),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}(),d=function(t,n,e){for(var r=0;r<t.length&&!1!==n.call(e,t[r],r,t);r++);return t},g=function(t,n,e){for(var r="",i=Object.keys(t),u=0;u<i.length&&(r=i[u],!1!==n.call(e,t[r],r,t));u++);return t},_=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},b=function(t){return _(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},w=b,x=function(t){return t.split("").reverse().join("")},k=function(t){return/^[A-Za-z]$/.test(t)},j=function(t,n,e){e.mask++,e.text++;var r=t[e.mask],i=n[e.text];return s(r)||s(i)?"":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 k(n)?n:(e.mask--,"");case"L":return k(n)?n.toLowerCase():(e.mask--,"");case"U":return k(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,i,e)+j(t,n,e)},O=function(t,n){return j(t,n,{mask:-1,text:-1})},S=O,A=function(t,n){return x(S(x(t),x(n)))},C=function(t,n){return C=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])},C(t,n)};function E(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}C(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}var M=function(){return M=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t},M.apply(this,arguments)};function F(t,n,e,r){return new(e||(e=Promise))((function(i,u){function o(t){try{s(r.next(t))}catch(t){u(t)}}function a(t){try{s(r.throw(t))}catch(t){u(t)}}function s(t){var n;t.done?i(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,i,u,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){return function(u){if(e)throw new TypeError("Generator is already executing.");for(;o;)try{if(e=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=n.call(t,o)}catch(t){u=[6,t],r=0}finally{e=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}function P(t,n,e){if(e||2===arguments.length)for(var r,i=0,u=n.length;i<u;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))}var U=function(t,n){return t.reduce((function(t,e){var r;return M(M({},t),((r={})[e]=n[e],r))}),{})},T=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=i(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 i(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 F(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 F(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}(),q=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 i=n._items.validate(t[r]),u=i.error,o=i.value;if(u)return n.invalid("["+n._type+"]< "+u+"["+r+"] >");t[r]=o}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return E(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}(T),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 E(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:i(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(T),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 E(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:i(t)?parseFloat(t):t}}))},n}(T),L=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 u=n._keys[r];u.name=r;var o=u.validate(t[r]),a=o.error,s=o.value;a&&e.push(a),i(s)&&(t[r]=s)}})),e.length?n.invalid("["+n._type+"]{ "+e.join(", ")+" }"):{value:t}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return E(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(T),N=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 E(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.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.prototype.parse=function(){return this.unshift((function(t){return{value:o(t)?JSON.stringify(t):i(t)?t.toString():t}}))},n.prototype.required=function(){var t=this;return this.push((function(n){return n.trin().length?{value:n}:t.invalid("["+t._type+"].required")}))},n}(T),Y=function(){function t(){}return t.array=function(t){return(new q).items(t)},t.boolean=function(){return new B},t.number=function(){return new D},t.object=function(t){return(new L).keys(t)},t.string=function(){return new N},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 F(this,void 0,void 0,(function(){var r;return I(this,(function(i){switch(i.label){case 0:return r=a,[4,t.validateAsync.apply(t,P([n],e,!1))];case 1:return[2,!r.apply(void 0,[i.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},i=0;i<n.length;i++)if((r=n[i].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 F(this,void 0,void 0,(function(){var e,r;return I(this,(function(i){switch(i.label){case 0:e={value:t},r=0,i.label=1;case 1:return r<n.length?[4,n[r].validateAsync(e.value)]:[3,4];case 2:if((e=i.sent()).error)return[2,{error:e.error}];i.label=3;case 3:return r++,[3,1];case 4:return[2,e]}}))}))},t}();return t.EventEmitter=m,t.Validation=Y,t.ValidationBase=T,t.allowedObject=U,t.camelCase=w,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.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=[],i=0;i<arguments.length;i++)r[i]=arguments[i];e&&clearTimeout(e),e=setTimeout((function(){return t.apply(void 0,r)}),n)}},t.deniedObject=function(t,n){return U(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},t.each=function(t,n,r){return e(t)?d(t,n,r):o(t)?g(t,n,r):null},t.forEachAsync=function(t,n,e){return F(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,i){return n.call(e,r,i,t)})))];case 1:return r.sent(),[2]}}))}))},t.forEachIndex=d,t.forEachKey=g,t.forEachSeries=function(t,n,e){return F(void 0,void 0,void 0,(function(){var r;return I(this,(function(i){switch(i.label){case 0:r=0,i.label=1;case 1:return r<t.length?[4,n.call(e,t[r],r,t)]:[3,4];case 2:i.sent(),i.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},t.isArray=e,t.isBoolean=r,t.isDef=i,t.isFloat=function(t){return u(t)&&!!(t%1)},t.isFunction=function(t){return"function"==c(t)},t.isInteger=function(t){return u(t)&&!(t%1)},t.isNull=function(t){return null===t},t.isNumber=u,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=b,t.map=function(t,n,e){for(var r="",i=Object.keys(t),u=0;u<i.length;u++)t[r=i[u]]=n.call(e,t[r],r,t);return t},t.mask=O,t.maskMoney=function(t,n,e){return e++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),A(t,n.length<e?("0".repeat(e)+n).slice(-1*e):n)},t.maskReverse=A,t.noop=function(){},t.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","",""],e=n[1],r=n[2],i=n[3];return(r.length?parseFloat(e+"."+r):parseInt(e))+(i||"px")},t.shadeColor=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+l(t,n)).slice(-2)}))},t.simpleID=function(){return p()+h()},t.sleep=function(t){return new Promise((function(n){return setTimeout(n,t)}))},t.stringReverse=x,t.toArray=function(t){return e(t)?t:i(t)?[t]:[]},t.toBool=function(t){return"true"===t||"1"===t},t.type=c,t.uniqueID=function(){return y()+y()+y()+y()},t.upperCamelCase=function(t){return _(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,e){return n.toUpperCase()+e}))}))},t.uuidv4=function(){return v()+"-"+h()+"-4"+p()+"-"+h()+"-"+(v()+h())},Object.defineProperty(t,"__esModule",{value:!0}),t}({});
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}({});
package/dist/index.umd.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.1
2
+ * @andrewcaires/utils.js v0.2.3
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2022 Andrew Caires
5
5
  * @license: MIT
6
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)},i=function(t){return"null"!=c(t)},u=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){return(e=parseInt(t,16)+n,Math.min(255,Math.max(0,e))).toString(16);var e},f=function(t){return Math.random().toString(16).slice(t)},p=function(){return f(-3)},h=function(){return f(-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 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(i){n(i),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}(),d=function(t,n,e){for(var r=0;r<t.length&&!1!==n.call(e,t[r],r,t);r++);return t},g=function(t,n,e){for(var r="",i=Object.keys(t),u=0;u<i.length&&(r=i[u],!1!==n.call(e,t[r],r,t));u++);return t},_=function(t,n){return n(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,"")},b=function(t){return _(t,(function(t){return t.replace(/\s(\w)/g,(function(t){return t.toUpperCase()}))}))},x=b,w=function(t){return t.split("").reverse().join("")},k=function(t){return/^[A-Za-z]$/.test(t)},j=function(t,n,e){e.mask++,e.text++;var r=t[e.mask],i=n[e.text];return s(r)||s(i)?"":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 k(n)?n:(e.mask--,"");case"L":return k(n)?n.toLowerCase():(e.mask--,"");case"U":return k(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,i,e)+j(t,n,e)},O=function(t,n){return j(t,n,{mask:-1,text:-1})},S=O,A=function(t,n){return w(S(w(t),w(n)))},C=function(t,n){return C=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])},C(t,n)};function E(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}C(t,n),t.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}var M=function(){return M=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t},M.apply(this,arguments)};function F(t,n,e,r){return new(e||(e=Promise))((function(i,u){function o(t){try{s(r.next(t))}catch(t){u(t)}}function a(t){try{s(r.throw(t))}catch(t){u(t)}}function s(t){var n;t.done?i(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 T(t,n){var e,r,i,u,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(u){return function(a){return function(u){if(e)throw new TypeError("Generator is already executing.");for(;o;)try{if(e=1,r&&(i=2&u[0]?r.return:u[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;switch(r=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){o=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(6===u[0]&&o.label<i[1]){o.label=i[1],i=u;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(u);break}i[2]&&o.ops.pop(),o.trys.pop();continue}u=n.call(t,o)}catch(t){u=[6,t],r=0}finally{e=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}function I(t,n,e){if(e||2===arguments.length)for(var r,i=0,u=n.length;i<u;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))}var P=function(t,n){return t.reduce((function(t,e){var r;return M(M({},t),((r={})[e]=n[e],r))}),{})},U=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=i(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 i(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 F(this,void 0,void 0,(function(){var n;return T(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 F(this,void 0,void 0,(function(){var n,e;return T(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}(),q=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 i=n._items.validate(t[r]),u=i.error,o=i.value;if(u)return n.invalid("["+n._type+"]< "+u+"["+r+"] >");t[r]=o}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return E(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}(U),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 E(n,t),n.prototype.parse=function(){return this.unshift((function(t){return{value:i(t)?-1!=[1,"1","true"].indexOf(t):t}}))},n}(U),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 E(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:i(t)?parseFloat(t):t}}))},n}(U),L=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 u=n._keys[r];u.name=r;var o=u.validate(t[r]),a=o.error,s=o.value;a&&e.push(a),i(s)&&(t[r]=s)}})),e.length?n.invalid("["+n._type+"]{ "+e.join(", ")+" }"):{value:t}}return{value:t}}return n.invalid("["+n._type+"]")})),n}return E(n,t),n.prototype.keys=function(t){return this._keys=t,this},n}(U),N=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 E(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.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.prototype.parse=function(){return this.unshift((function(t){return{value:o(t)?JSON.stringify(t):i(t)?t.toString():t}}))},n.prototype.required=function(){var t=this;return this.push((function(n){return n.trin().length?{value:n}:t.invalid("["+t._type+"].required")}))},n}(U),Y=function(){function t(){}return t.array=function(t){return(new q).items(t)},t.boolean=function(){return new B},t.number=function(){return new D},t.object=function(t){return(new L).keys(t)},t.string=function(){return new N},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,I([n],e,!1)).error)},t.prototype.testAsync=function(n){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return F(this,void 0,void 0,(function(){var r;return T(this,(function(i){switch(i.label){case 0:return r=a,[4,t.validateAsync.apply(t,I([n],e,!1))];case 1:return[2,!r.apply(void 0,[i.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},i=0;i<n.length;i++)if((r=n[i].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 F(this,void 0,void 0,(function(){var e,r;return T(this,(function(i){switch(i.label){case 0:e={value:t},r=0,i.label=1;case 1:return r<n.length?[4,n[r].validateAsync(e.value)]:[3,4];case 2:if((e=i.sent()).error)return[2,{error:e.error}];i.label=3;case 3:return r++,[3,1];case 4:return[2,e]}}))}))},t}();t.EventEmitter=m,t.Validation=Y,t.ValidationBase=U,t.allowedObject=P,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.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=[],i=0;i<arguments.length;i++)r[i]=arguments[i];e&&clearTimeout(e),e=setTimeout((function(){return t.apply(void 0,r)}),n)}},t.deniedObject=function(t,n){return P(Object.keys(n).filter((function(n){return-1==t.indexOf(n)})),n)},t.each=function(t,n,r){return e(t)?d(t,n,r):o(t)?g(t,n,r):null},t.forEachAsync=function(t,n,e){return F(void 0,void 0,void 0,(function(){return T(this,(function(r){switch(r.label){case 0:return[4,Promise.all(t.map((function(r,i){return n.call(e,r,i,t)})))];case 1:return r.sent(),[2]}}))}))},t.forEachIndex=d,t.forEachKey=g,t.forEachSeries=function(t,n,e){return F(void 0,void 0,void 0,(function(){var r;return T(this,(function(i){switch(i.label){case 0:r=0,i.label=1;case 1:return r<t.length?[4,n.call(e,t[r],r,t)]:[3,4];case 2:i.sent(),i.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},t.isArray=e,t.isBoolean=r,t.isDef=i,t.isFloat=function(t){return u(t)&&!!(t%1)},t.isFunction=function(t){return"function"==c(t)},t.isInteger=function(t){return u(t)&&!(t%1)},t.isNull=function(t){return null===t},t.isNumber=u,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=b,t.map=function(t,n,e){for(var r="",i=Object.keys(t),u=0;u<i.length;u++)t[r=i[u]]=n.call(e,t[r],r,t);return t},t.mask=O,t.maskMoney=function(t,n,e){return e++,n=parseInt((n||"0").replace(/\W/g,"")).toString(),A(t,n.length<e?("0".repeat(e)+n).slice(-1*e):n)},t.maskReverse=A,t.noop=function(){},t.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","",""],e=n[1],r=n[2],i=n[3];return(r.length?parseFloat(e+"."+r):parseInt(e))+(i||"px")},t.shadeColor=function(t,n){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+l(t,n)).slice(-2)}))},t.simpleID=function(){return p()+h()},t.sleep=function(t){return new Promise((function(n){return setTimeout(n,t)}))},t.stringReverse=w,t.toArray=function(t){return e(t)?t:i(t)?[t]:[]},t.toBool=function(t){return"true"===t||"1"===t},t.type=c,t.uniqueID=function(){return y()+y()+y()+y()},t.upperCamelCase=function(t){return _(t,(function(t){return t.replace(/(\w)(\w*)/g,(function(t,n,e){return n.toUpperCase()+e}))}))},t.uuidv4=function(){return v()+"-"+h()+"-4"+p()+"-"+h()+"-"+(v()+h())},Object.defineProperty(t,"__esModule",{value:!0})}));
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})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/utils.js",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "JavaScript utility library for web and nodejs development",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",