@andrewcaires/utils.js 0.2.21 → 0.2.22

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.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.21
2
+ * @andrewcaires/utils.js v0.2.22
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- "use strict";const e={},t=e=>"array"==l(e),r=e=>"boolean"==l(e),s=e=>"null"!=l(e),i=e=>"number"==l(e),n=e=>"object"==l(e),a=e=>"string"==l(e),o=e=>void 0===e,l=t=>null==t?"null":e[e.toString.call(t)]||"object";["Array","Boolean","Function","Number","Object","String"].forEach((t=>e["[object "+t+"]"]=t.toLowerCase()));const h=(e,t,r)=>Math.max(t,Math.min(r,e)),u=e=>("0"+e).slice(-2),p=e=>parseInt(e,16)||0,c=(e,t)=>{return(r=p(e)+t,h(r,0,255)).toString(16);var r},v=e=>Math.random().toString(16).slice(e),d=()=>v(-3),x=()=>v(-4),m=()=>x()+x(),f=()=>m()+m(),g=e=>("0"+e.toString()).slice(-2),y={"%y":e=>g(e.getFullYear()),"%Y":e=>e.getFullYear().toString(),"%m":e=>g(e.getMonth()+1),"%d":e=>g(e.getDate()),"%H":e=>g(e.getHours()),"%M":e=>g(e.getMinutes()),"%S":e=>g(e.getSeconds())};function _(e,t,r,s){return new(r||(r=Promise))((function(i,n){function a(e){try{l(s.next(e))}catch(e){n(e)}}function o(e){try{l(s.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,o)}l((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const b=(e,t,r)=>{for(let s=0;s<e.length&&!1!==t.call(r,e[s],s,e);s++);return e},k=(e,t,r)=>{let s="";const i=Object.keys(e);for(let n=0;n<i.length&&(s=i[n],!1!==t.call(r,e[s],s,e));n++);return e},w=()=>{},S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",C=(e,t,r)=>{let s="";for(let i=0;i<e.length;i++){const n=S.indexOf(e[i]),a=S.indexOf(t[i%t.length]);s+=-1===n||-1===a?e[i]:S[(r?n-a+62:n+a)%62]}return s},j=(e,t)=>t(e.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,""),O=e=>/^[\d]$/.test(e),A=e=>/^[A-Za-z]$/.test(e),I=e=>/^[^\w]$/.test(e),M=e=>j(e,(e=>e.replace(/\s(\w)/g,(e=>e.toUpperCase())))),E=M,T=e=>j(e,(e=>e.replace(/(\w)(\w*)/g,((e,t,r)=>t.toUpperCase()+r)))),F=e=>e.split("").reverse().join(""),L=e=>(e.maskIndex--,""),N={"#":({value:e})=>e,0:e=>O(e.value)?e.value:L(e),9:e=>O(e.value)?e.value:L(e),A:e=>A(e.value)?e.value:L(e),Z:e=>A(e.value)?e.value:L(e),L:e=>A(e.value)?e.value.toLowerCase():L(e),U:e=>A(e.value)?e.value.toUpperCase():L(e),S:e=>I(e.value)?e.value:L(e)},D=e=>{e.maskIndex++,e.textIndex++;const{mask:t,maskIndex:r,text:s,textIndex:i}=e;e.key=t[r],e.value=s[i];const{key:n,value:a}=e;return o(n)||o(a)?"":(e=>N[e.key]?N[e.key](e):(e.key!=e.value&&e.textIndex--,e.key))(e)+D(e)},H=(e,t)=>D({mask:e,maskIndex:-1,text:t,textIndex:-1,key:"",value:""}),U=H,q=(e,t)=>F(U(F(e),F(t))),B=36e5,Y=24*B,$={ms:1,s:1e3,m:6e4,h:B,d:Y,w:6048e5,y:315576e5},P=["y","d","h","m","s","ms"],R=(e,t)=>e.reduce(((e,r)=>Object.assign(Object.assign({},e),{[r]:t[r]})),{});class z{constructor(){this.name="",this._error="",this._filter=[],this._type="any",this.rules=[],this.custom=[]}empty(e){return this._value=e,this.unshift((e=>{const t=s(e);return{break:!t,value:t?e:this._value}}))}error(e){return this._error=e,this}filter(...e){return this._filter=e,this.unshift((e=>{const t=-1==this._filter.indexOf(e);return{break:!t,value:t?e:void 0}}))}invalid(e){return{error:this._error?this._error:this.name?this.name+":"+e:e}}parse(){return this.unshift((e=>({value:e})))}push(e){return this.rules.push(e),this}required(){return this.unshift((e=>s(e)?{value:e}:this.invalid("["+this._type+"].required")))}test(e){return!a(this.validate(e).error)}testAsync(e){return _(this,void 0,void 0,(function*(){return!a((yield this.validateAsync(e)).error)}))}unshift(e){return this.rules.unshift(e),this}validate(e){if(this.custom.length)return this.invalid("[async]");let t={value:e};for(let e=0;e<this.rules.length;e++){if(t=this.rules[e](t.value),t.error)return{error:t.error};if(t.break)return{value:t.value}}return{value:t.value}}validateAsync(e){return _(this,void 0,void 0,(function*(){let t=this.validate(e);if(t.error)return{error:t.error};for(let e=0;e<this.custom.length;e++){if(t=yield this.custom[e](t.value),t.error)return{error:t.error};if(t.break)return{value:t.value}}return{value:t.value}}))}}class J extends z{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="array",this.push((e=>{if(t(e)){if(this._items){this._items.name="";for(let t=0;t<e.length;t++){const{error:r,value:s}=this._items.validate(e[t]);if(r)return this.invalid("["+this._type+"]< "+r+"["+t+"] >");e[t]=s}}return{value:e}}return this.invalid("["+this._type+"]")}))}between(e,t){return this.min(e),this.max(t)}items(e){return this._items=e,this}length(e){return this._length=e,this.push((e=>e.length==this._length?{value:e}:this.invalid("["+this._type+"].length("+this._length+")")))}max(e){return this._max=e,this.push((e=>e.length<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}min(e){return this._min=e,this.push((e=>e.length>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}}class V extends z{constructor(){super(),this._type="boolean",this.push((e=>r(e)?{value:e}:this.invalid("["+this._type+"]")))}parse(){return this.unshift((e=>({value:s(e)?-1!=[1,"1",!0,"true"].indexOf(e):e})))}}class W extends z{constructor(){super(),this._max=0,this._min=0,this._type="number",this.push((e=>i(e)?{value:e}:this.invalid("["+this._type+"]")))}between(e,t){return this.min(e),this.max(t)}max(e){return this._max=e,this.push((e=>e<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}min(e){return this._min=e,this.push((e=>e>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((e=>({value:s(e)?parseFloat(e):e})))}}class Z extends z{constructor(){super(),this._keys={},this._type="object",this.push((e=>{if(n(e)){const t=[],r={};return Object.keys(this._keys).forEach((i=>{const n=this._keys[i];n.name=i;const{error:a,value:o}=n.validate(e[i]);a&&t.push(a),s(o)&&(r[i]=o)})),t.length?this.invalid("["+this._type+"]{ "+t.join(", ")+" }"):{value:r}}return this.invalid("["+this._type+"]")}))}keys(e){return this._keys=e||{},this}parse(){return this.unshift((e=>{if(!n(e))try{e=JSON.parse(e)}catch(e){return this.invalid("["+this._type+"]")}const t=Object.keys(this._keys);return{value:t.length?R(t,e):e}}))}}class K extends z{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="string",this.push((e=>a(e)?{value:e}:this.invalid("["+this._type+"]")))}between(e,t){return this.min(e),this.max(t)}date(){return this.push((e=>isNaN(new Date(e).getTime())?this.invalid("["+this._type+"].date"):{value:e}))}email(){return this.push((e=>/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(e)?{value:e}:this.invalid("["+this._type+"].email")))}length(e){return this._length=e,this.push((e=>e.length==this._length?{value:e}:this.invalid("["+this._type+"].length("+this._length+")")))}lowerCase(){return this.push((e=>({value:e.toLowerCase()})))}lowerCamelCase(){return this.push((e=>({value:M(e)})))}max(e){return this._max=e,this.push((e=>e.length<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}mask(e){return this.push((t=>({value:H(e,t)})))}min(e){return this._min=e,this.push((e=>e.length>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((e=>({value:n(e)?JSON.stringify(e):s(e)?e.toString():e})))}required(){return this.push((e=>e.length?{value:e}:this.invalid("["+this._type+"].required")))}trim(){return this.push((e=>({value:e.trim()})))}upperCase(){return this.push((e=>({value:e.toUpperCase()})))}upperCamelCase(){return this.push((e=>({value:T(e)})))}}class G{static array(e){return(new J).items(e)}static boolean(){return new V}static number(){return new W}static object(e){return(new Z).keys(e)}static string(){return new K}test(e,...t){return!a(G.validate(e,...t).error)}testAsync(e,...t){return _(this,void 0,void 0,(function*(){return!a((yield G.validateAsync(e,...t)).error)}))}static validate(e,...t){let r={value:e};for(let e=0;e<t.length;e++)if(r=t[e].validate(r.value),r.error)return{error:r.error};return r}static validateAsync(e,...t){return _(this,void 0,void 0,(function*(){let r={value:e};for(let e=0;e<t.length;e++)if(r=yield t[e].validateAsync(r.value),r.error)return{error:r.error};return r}))}}exports.EventEmitter=class{constructor(){this.events=new Map}on(e,t){const r=this.events.get(e);return r?r.push(t):this.events.set(e,[t]),{dispose:()=>this.off(e,t)}}once(e,t){const r=s=>{t(s),this.off(e,r)};return this.on(e,r),{dispose:()=>this.off(e,r)}}off(e,t){const r=this.events.get(e);if(t){if(r){const e=r.indexOf(t);e>=0&&r.splice(e,1)}}else this.events.set(e,[])}emit(e,t){const r=this.events.get(e);r&&r.forEach((e=>e(t)))}},exports.Validation=G,exports.ValidationBase=z,exports.allowedObject=R,exports.cache=()=>{const e=[],t=[];return r=>{let s=e.indexOf(r);return-1==s&&(e.push(r),t.push({}),s=t.length-1),t[s]}},exports.camelCase=E,exports.chunkArray=(e,t)=>{const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r},exports.clamp=h,exports.cutText=(e,t)=>{if(e.length>t){const r=e.substring(0,t).split(" ");return r.pop(),r.join(" ")+"..."}return e},exports.dateFormat=(e,t)=>t.replace(/%[yYmdHMS]/g,(t=>y[t]?y[t](e):t.slice(1))),exports.debounce=(e,t)=>{let r;const s=()=>{r&&clearTimeout(r)};return{cancel:s,run(...i){s(),r=setTimeout((()=>e(...i)),t)}}},exports.decodeHTML=e=>e.replace(/&#(\d+);/g,((e,t)=>String.fromCharCode(t))),exports.deniedObject=(e,t)=>R(Object.keys(t).filter((t=>-1==e.indexOf(t))),t),exports.each=(e,r,s)=>t(e)?b(e,r,s):n(e)?k(e,r,s):null,exports.encodeHTML=e=>e.replace(/[\u00A0-\u9999<>\\&]/g,(e=>"&#"+e.charCodeAt(0)+";")),exports.forEachAsync=(e,t,r)=>_(void 0,void 0,void 0,(function*(){yield Promise.allSettled(e.map(((s,i)=>t.call(r,s,i,e)))).catch(w)})),exports.forEachIndex=b,exports.forEachKey=k,exports.forEachSeries=(e,t,r)=>_(void 0,void 0,void 0,(function*(){for(let s=0;s<e.length;s++)yield t.call(r,e[s],s,e).catch(w)})),exports.forLoop=(e,t,r)=>{for(let s=1;s<=e&&!1!==t.call(r,s,e);s++);return e},exports.hash=e=>(e=C(S,e,!1),{generate:t=>C(t,e,!1),reverse:t=>C(t,e,!0)}),exports.hexToRgb=e=>{var t;return(null===(t=e.replace(/^#/,"").match(/.{1,2}/g))||void 0===t?void 0:t.map((e=>p(e))))||[]},exports.isArray=t,exports.isBoolean=r,exports.isCharacter=e=>/^[\w]$/.test(e),exports.isDef=s,exports.isDigit=O,exports.isFloat=e=>i(e)&&!!(e%1),exports.isFunction=e=>"function"==l(e),exports.isInteger=e=>i(e)&&!(e%1),exports.isLetter=A,exports.isNull=e=>null===e,exports.isNumber=i,exports.isObject=n,exports.isString=a,exports.isSymbol=I,exports.isUndefined=o,exports.lerp=(e,t,r)=>e+(t-e)*h(r,0,1),exports.loop=(e,t)=>{let r=!1;const s=()=>_(void 0,void 0,void 0,(function*(){r&&(yield e(),setTimeout(s,t))}));return{start(){r||(r=!0,s())},stop(){r=!1}}},exports.lowerCamelCase=M,exports.map=(e,t,r)=>{let s="";const i=Object.keys(e);for(let n=0;n<i.length;n++)s=i[n],e[s]=t.call(r,e[s],s,e);return e},exports.mask=H,exports.maskMoney=(e,t,r)=>(r++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),q(e,t.length<r?("0".repeat(r)+t).slice(-1*r):t)),exports.maskReverse=q,exports.maskTest=(e,t)=>e.length==U(e,t).length,exports.msToString=e=>{const t=[];return P.forEach((r=>{const s=$[r],i=(e-e%s)/s;i&&(e-=i*s,t.push(i.toString()+r))})),t.join(" ")},exports.noop=w,exports.parseMs=e=>{const t=/(-?(?:\d+)?\.?\d+) *(ms|s|m|h|d|w|y)/gm;let r,s=0;for(;null!==(r=t.exec(e));)r.index===t.lastIndex&&t.lastIndex++,s+=parseFloat(r[1])*$[r[2]]||0;return s},exports.parseSize=e=>{if(i(e))return e+"px";const t=(e=>/(-?(?:\d+)?\.?\d+) *(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(e))(e);return t?parseFloat(t[1])+(t[2]||"px"):"0px"},exports.rangeArray=(e,t,r=1)=>Array.from({length:(t-e)/r+1},((t,s)=>e+s*r)),exports.rgbToHex=(e,t,r)=>"#"+u(e.toString(16))+u(t.toString(16))+u(r.toString(16)),exports.shadeColor=(e,t)=>"#"+e.replace(/^#/,"").replace(/../g,(e=>u(c(e,t)))),exports.shuffleArray=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},exports.simpleID=()=>d()+x(),exports.sleep=e=>new Promise((t=>setTimeout(t,e))),exports.stringReverse=F,exports.toArray=e=>t(e)?e:s(e)?[e]:[],exports.toBool=e=>"true"===e||"1"===e,exports.type=l,exports.uniqueID=()=>f()+f()+f()+f(),exports.upperCamelCase=T,exports.uuidv4=()=>m()+"-"+x()+"-4"+d()+"-"+x()+"-"+(m()+x());
7
+ "use strict";const e={},t=e=>"array"==l(e),r=e=>"boolean"==l(e),s=e=>"null"!=l(e),i=e=>"number"==l(e),n=e=>"object"==l(e),a=e=>"string"==l(e),o=e=>void 0===e,l=t=>null==t?"null":e[e.toString.call(t)]||"object";["Array","Boolean","Function","Number","Object","String"].forEach((t=>e["[object "+t+"]"]=t.toLowerCase()));const h=(e,t,r)=>Math.max(t,Math.min(r,e)),u=e=>("0"+e).slice(-2),p=e=>parseInt(e,16)||0,c=(e,t)=>{return(r=p(e)+t,h(r,0,255)).toString(16);var r},v=e=>Math.random().toString(16).slice(e),d=()=>v(-3),x=()=>v(-4),m=()=>x()+x(),f=()=>m()+m(),g=e=>("0"+e.toString()).slice(-2),y={"%y":e=>g(e.getFullYear()),"%Y":e=>e.getFullYear().toString(),"%m":e=>g(e.getMonth()+1),"%d":e=>g(e.getDate()),"%H":e=>g(e.getHours()),"%M":e=>g(e.getMinutes()),"%S":e=>g(e.getSeconds())};function _(e,t,r,s){return new(r||(r=Promise))((function(i,n){function a(e){try{l(s.next(e))}catch(e){n(e)}}function o(e){try{l(s.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,o)}l((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const b=(e,t,r)=>{for(let s=0;s<e.length&&!1!==t.call(r,e[s],s,e);s++);return e},k=(e,t,r)=>{let s="";const i=Object.keys(e);for(let n=0;n<i.length&&(s=i[n],!1!==t.call(r,e[s],s,e));n++);return e},w=()=>{},S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",C=(e,t,r)=>{let s="";for(let i=0;i<e.length;i++){const n=S.indexOf(e[i]),a=S.indexOf(t[i%t.length]);s+=-1===n||-1===a?e[i]:S[(r?n-a+62:n+a)%62]}return s},j=(e,t)=>t(e.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,""),O=e=>/^[\d]$/.test(e),A=e=>/^[A-Za-z]$/.test(e),I=e=>/^[^\w]$/.test(e),M=e=>j(e,(e=>e.replace(/\s(\w)/g,(e=>e.toUpperCase())))),E=M,T=e=>j(e,(e=>e.replace(/(\w)(\w*)/g,((e,t,r)=>t.toUpperCase()+r)))),F=e=>e.split("").reverse().join(""),L=e=>(e.maskIndex--,""),N={"#":({value:e})=>e,0:e=>O(e.value)?e.value:L(e),9:e=>O(e.value)?e.value:L(e),A:e=>A(e.value)?e.value:L(e),Z:e=>A(e.value)?e.value:L(e),L:e=>A(e.value)?e.value.toLowerCase():L(e),U:e=>A(e.value)?e.value.toUpperCase():L(e),S:e=>I(e.value)?e.value:L(e)},D=e=>{e.maskIndex++,e.textIndex++;const{mask:t,maskIndex:r,text:s,textIndex:i}=e;e.key=t[r],e.value=s[i];const{key:n,value:a}=e;return o(n)||o(a)?"":(e=>N[e.key]?N[e.key](e):(e.key!=e.value&&e.textIndex--,e.key))(e)+D(e)},H=(e,t)=>D({mask:e,maskIndex:-1,text:t,textIndex:-1,key:"",value:""}),U=H,q=(e,t)=>F(U(F(e),F(t))),B=36e5,Y=24*B,$={ms:1,s:1e3,m:6e4,h:B,d:Y,w:6048e5,y:315576e5},P=["y","d","h","m","s","ms"],R=(e,t)=>e.reduce(((e,r)=>Object.assign(Object.assign({},e),{[r]:t[r]})),{}),z=(e,...t)=>{if(!t.length)return e;const r=t.shift();if(n(e)&&n(r))for(const t in r)n(r[t])?(e[t]||(e=Object.assign(Object.assign({},e),{[t]:{}})),e[t]=z(e[t],r[t])):e=Object.assign(Object.assign({},e),{[t]:r[t]});return z(e,...t)};class J{constructor(){this.name="",this._error="",this._filter=[],this._type="any",this.rules=[],this.custom=[]}empty(e){return this._value=e,this.unshift((e=>{const t=s(e);return{break:!t,value:t?e:this._value}}))}error(e){return this._error=e,this}filter(...e){return this._filter=e,this.unshift((e=>{const t=-1==this._filter.indexOf(e);return{break:!t,value:t?e:void 0}}))}invalid(e){return{error:this._error?this._error:this.name?this.name+":"+e:e}}parse(){return this.unshift((e=>({value:e})))}push(e){return this.rules.push(e),this}required(){return this.unshift((e=>s(e)?{value:e}:this.invalid("["+this._type+"].required")))}test(e){return!a(this.validate(e).error)}testAsync(e){return _(this,void 0,void 0,(function*(){return!a((yield this.validateAsync(e)).error)}))}unshift(e){return this.rules.unshift(e),this}validate(e){if(this.custom.length)return this.invalid("[async]");let t={value:e};for(let e=0;e<this.rules.length;e++){if(t=this.rules[e](t.value),t.error)return{error:t.error};if(t.break)return{value:t.value}}return{value:t.value}}validateAsync(e){return _(this,void 0,void 0,(function*(){let t=this.validate(e);if(t.error)return{error:t.error};for(let e=0;e<this.custom.length;e++){if(t=yield this.custom[e](t.value),t.error)return{error:t.error};if(t.break)return{value:t.value}}return{value:t.value}}))}}class V extends J{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="array",this.push((e=>{if(t(e)){if(this._items){this._items.name="";for(let t=0;t<e.length;t++){const{error:r,value:s}=this._items.validate(e[t]);if(r)return this.invalid("["+this._type+"]< "+r+"["+t+"] >");e[t]=s}}return{value:e}}return this.invalid("["+this._type+"]")}))}between(e,t){return this.min(e),this.max(t)}items(e){return this._items=e,this}length(e){return this._length=e,this.push((e=>e.length==this._length?{value:e}:this.invalid("["+this._type+"].length("+this._length+")")))}max(e){return this._max=e,this.push((e=>e.length<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}min(e){return this._min=e,this.push((e=>e.length>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}}class W extends J{constructor(){super(),this._type="boolean",this.push((e=>r(e)?{value:e}:this.invalid("["+this._type+"]")))}parse(){return this.unshift((e=>({value:s(e)?-1!=[1,"1",!0,"true"].indexOf(e):e})))}}class Z extends J{constructor(){super(),this._max=0,this._min=0,this._type="number",this.push((e=>i(e)?{value:e}:this.invalid("["+this._type+"]")))}between(e,t){return this.min(e),this.max(t)}max(e){return this._max=e,this.push((e=>e<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}min(e){return this._min=e,this.push((e=>e>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((e=>({value:s(e)?parseFloat(e):e})))}}class K extends J{constructor(){super(),this._keys={},this._type="object",this.push((e=>{if(n(e)){const t=[],r={};return Object.keys(this._keys).forEach((i=>{const n=this._keys[i];n.name=i;const{error:a,value:o}=n.validate(e[i]);a&&t.push(a),s(o)&&(r[i]=o)})),t.length?this.invalid("["+this._type+"]{ "+t.join(", ")+" }"):{value:r}}return this.invalid("["+this._type+"]")}))}keys(e){return this._keys=e||{},this}parse(){return this.unshift((e=>{if(!n(e))try{e=JSON.parse(e)}catch(e){return this.invalid("["+this._type+"]")}const t=Object.keys(this._keys);return{value:t.length?R(t,e):e}}))}}class G extends J{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="string",this.push((e=>a(e)?{value:e}:this.invalid("["+this._type+"]")))}between(e,t){return this.min(e),this.max(t)}date(){return this.push((e=>isNaN(new Date(e).getTime())?this.invalid("["+this._type+"].date"):{value:e}))}email(){return this.push((e=>/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(e)?{value:e}:this.invalid("["+this._type+"].email")))}length(e){return this._length=e,this.push((e=>e.length==this._length?{value:e}:this.invalid("["+this._type+"].length("+this._length+")")))}lowerCase(){return this.push((e=>({value:e.toLowerCase()})))}lowerCamelCase(){return this.push((e=>({value:M(e)})))}max(e){return this._max=e,this.push((e=>e.length<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}mask(e){return this.push((t=>({value:H(e,t)})))}min(e){return this._min=e,this.push((e=>e.length>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((e=>({value:n(e)?JSON.stringify(e):s(e)?e.toString():e})))}required(){return this.push((e=>e.length?{value:e}:this.invalid("["+this._type+"].required")))}trim(){return this.push((e=>({value:e.trim()})))}upperCase(){return this.push((e=>({value:e.toUpperCase()})))}upperCamelCase(){return this.push((e=>({value:T(e)})))}}class Q{static array(e){return(new V).items(e)}static boolean(){return new W}static number(){return new Z}static object(e){return(new K).keys(e)}static string(){return new G}test(e,...t){return!a(Q.validate(e,...t).error)}testAsync(e,...t){return _(this,void 0,void 0,(function*(){return!a((yield Q.validateAsync(e,...t)).error)}))}static validate(e,...t){let r={value:e};for(let e=0;e<t.length;e++)if(r=t[e].validate(r.value),r.error)return{error:r.error};return r}static validateAsync(e,...t){return _(this,void 0,void 0,(function*(){let r={value:e};for(let e=0;e<t.length;e++)if(r=yield t[e].validateAsync(r.value),r.error)return{error:r.error};return r}))}}exports.EventEmitter=class{constructor(){this.events=new Map}on(e,t){const r=this.events.get(e);return r?r.push(t):this.events.set(e,[t]),{dispose:()=>this.off(e,t)}}once(e,t){const r=s=>{t(s),this.off(e,r)};return this.on(e,r),{dispose:()=>this.off(e,r)}}off(e,t){const r=this.events.get(e);if(t){if(r){const e=r.indexOf(t);e>=0&&r.splice(e,1)}}else this.events.set(e,[])}emit(e,t){const r=this.events.get(e);r&&r.forEach((e=>e(t)))}},exports.Validation=Q,exports.ValidationBase=J,exports.allowed=R,exports.cache=()=>{const e=[],t=[];return r=>{let s=e.indexOf(r);return-1==s&&(e.push(r),t.push({}),s=t.length-1),t[s]}},exports.camelCase=E,exports.chunkArray=(e,t)=>{const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r},exports.clamp=h,exports.cutText=(e,t)=>{if(e.length>t){const r=e.substring(0,t).split(" ");return r.pop(),r.join(" ")+"..."}return e},exports.dateFormat=(e,t)=>t.replace(/%[yYmdHMS]/g,(t=>y[t]?y[t](e):t.slice(1))),exports.debounce=(e,t)=>{let r;const s=()=>{r&&clearTimeout(r)};return{cancel:s,run(...i){s(),r=setTimeout((()=>e(...i)),t)}}},exports.decodeHTML=e=>e.replace(/&#(\d+);/g,((e,t)=>String.fromCharCode(t))),exports.denied=(e,t)=>R(Object.keys(t).filter((t=>-1==e.indexOf(t))),t),exports.each=(e,r,s)=>t(e)?b(e,r,s):n(e)?k(e,r,s):null,exports.encodeHTML=e=>e.replace(/[\u00A0-\u9999<>\\&]/g,(e=>"&#"+e.charCodeAt(0)+";")),exports.forEachAsync=(e,t,r)=>_(void 0,void 0,void 0,(function*(){yield Promise.allSettled(e.map(((s,i)=>t.call(r,s,i,e)))).catch(w)})),exports.forEachIndex=b,exports.forEachKey=k,exports.forEachSeries=(e,t,r)=>_(void 0,void 0,void 0,(function*(){for(let s=0;s<e.length;s++)yield t.call(r,e[s],s,e).catch(w)})),exports.forLoop=(e,t,r)=>{for(let s=1;s<=e&&!1!==t.call(r,s,e);s++);return e},exports.hash=e=>(e=C(S,e,!1),{generate:t=>C(t,e,!1),reverse:t=>C(t,e,!0)}),exports.hexToRgb=e=>{var t;return(null===(t=e.replace(/^#/,"").match(/.{1,2}/g))||void 0===t?void 0:t.map((e=>p(e))))||[]},exports.isArray=t,exports.isBoolean=r,exports.isCharacter=e=>/^[\w]$/.test(e),exports.isDef=s,exports.isDigit=O,exports.isFloat=e=>i(e)&&!!(e%1),exports.isFunction=e=>"function"==l(e),exports.isInteger=e=>i(e)&&!(e%1),exports.isLetter=A,exports.isNull=e=>null===e,exports.isNumber=i,exports.isObject=n,exports.isString=a,exports.isSymbol=I,exports.isUndefined=o,exports.lerp=(e,t,r)=>e+(t-e)*h(r,0,1),exports.loop=(e,t)=>{let r=!1;const s=()=>_(void 0,void 0,void 0,(function*(){r&&(yield e(),setTimeout(s,t))}));return{start(){r||(r=!0,s())},stop(){r=!1}}},exports.lowerCamelCase=M,exports.map=(e,t,r)=>{let s="";const i=Object.keys(e);for(let n=0;n<i.length;n++)s=i[n],e[s]=t.call(r,e[s],s,e);return e},exports.mask=H,exports.maskMoney=(e,t,r)=>(r++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),q(e,t.length<r?("0".repeat(r)+t).slice(-1*r):t)),exports.maskReverse=q,exports.maskTest=(e,t)=>e.length==U(e,t).length,exports.merge=z,exports.msToString=e=>{const t=[];return P.forEach((r=>{const s=$[r],i=(e-e%s)/s;i&&(e-=i*s,t.push(i.toString()+r))})),t.join(" ")},exports.noop=w,exports.parseMs=e=>{const t=/(-?(?:\d+)?\.?\d+) *(ms|s|m|h|d|w|y)/gm;let r,s=0;for(;null!==(r=t.exec(e));)r.index===t.lastIndex&&t.lastIndex++,s+=parseFloat(r[1])*$[r[2]]||0;return s},exports.parseSize=e=>{if(i(e))return e+"px";const t=(e=>/(-?(?:\d+)?\.?\d+) *(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(e))(e);return t?parseFloat(t[1])+(t[2]||"px"):"0px"},exports.rangeArray=(e,t,r=1)=>Array.from({length:(t-e)/r+1},((t,s)=>e+s*r)),exports.rgbToHex=(e,t,r)=>"#"+u(e.toString(16))+u(t.toString(16))+u(r.toString(16)),exports.shadeColor=(e,t)=>"#"+e.replace(/^#/,"").replace(/../g,(e=>u(c(e,t)))),exports.shuffleArray=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},exports.simpleID=()=>d()+x(),exports.sleep=e=>new Promise((t=>setTimeout(t,e))),exports.stringReverse=F,exports.toArray=e=>t(e)?e:s(e)?[e]:[],exports.toBool=e=>"true"===e||"1"===e,exports.type=l,exports.uniqueID=()=>f()+f()+f()+f(),exports.upperCamelCase=T,exports.uuidv4=()=>m()+"-"+x()+"-4"+d()+"-"+x()+"-"+(m()+x());
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.21
2
+ * @andrewcaires/utils.js v0.2.22
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
@@ -93,8 +93,9 @@ declare const msToString: (ms: number) => string;
93
93
  declare const clamp: (value: number, min: number, max: number) => number;
94
94
  declare const lerp: (value1: number, value2: number, amount: number) => number;
95
95
 
96
- declare const allowedObject: (allowed: string[], raw: TypeObjectAny) => TypeObjectAny;
97
- declare const deniedObject: (denied: string[], raw: TypeObjectAny) => TypeObjectAny;
96
+ declare const allowed: (allowed: Array<string>, target: TypeObjectAny) => TypeObjectAny;
97
+ declare const denied: (denied: Array<string>, target: TypeObjectAny) => TypeObjectAny;
98
+ declare const merge: (target: TypeObjectAny, ...sources: Array<TypeObjectAny>) => TypeObjectAny;
98
99
 
99
100
  type ForEachCallback<T> = TypeCallback<T, number, Array<T>, Promise<void>>;
100
101
  declare const forEachAsync: <T>(array: T[], callback: ForEachCallback<T>, thisArg?: any) => Promise<void>;
@@ -224,4 +225,4 @@ declare class Validation {
224
225
  static validateAsync(value?: any, ...rules: Array<ValidationBase>): Promise<IValidationResult>;
225
226
  }
226
227
 
227
- export { type CacheCallback, type EachCallback, type EventCallback, EventEmitter, type EventList, type ForEachCallback, type IDebounceCallbacks, type IEventDisposable, type IHash, type ILoopCallbacks, type IValidationResult, type LoopCallback, type TypeArray, type TypeArrayAny, type TypeArrayFunction, type TypeArrayNumber, type TypeArrayString, type TypeCallback, type TypeCallbackArray, type TypeCallbackFunction, type TypeCallbackMap, type TypeCallbackObject, type TypeObject, type TypeObjectAny, type TypeObjectFunction, type TypeObjectNumber, type TypeObjectString, Validation, ValidationBase, type ValidationCallback, type ValidationCallbackAsync, allowedObject, cache, camelCase, chunkArray, clamp, cutText, dateFormat, debounce, decodeHTML, deniedObject, each, encodeHTML, forEachAsync, forEachIndex, forEachKey, forEachSeries, forLoop, hash, hexToRgb, isArray, isBoolean, isCharacter, isDef, isDigit, isFloat, isFunction, isInteger, isLetter, isNull, isNumber, isObject, isString, isSymbol, isUndefined, lerp, loop, lowerCamelCase, map, mask, maskMoney, maskReverse, maskTest, msToString, noop, parseMs, parseSize, rangeArray, rgbToHex, shadeColor, shuffleArray, simpleID, sleep, stringReverse, toArray, toBool, type, uniqueID, upperCamelCase, uuidv4 };
228
+ export { type CacheCallback, type EachCallback, type EventCallback, EventEmitter, type EventList, type ForEachCallback, type IDebounceCallbacks, type IEventDisposable, type IHash, type ILoopCallbacks, type IValidationResult, type LoopCallback, type TypeArray, type TypeArrayAny, type TypeArrayFunction, type TypeArrayNumber, type TypeArrayString, type TypeCallback, type TypeCallbackArray, type TypeCallbackFunction, type TypeCallbackMap, type TypeCallbackObject, type TypeObject, type TypeObjectAny, type TypeObjectFunction, type TypeObjectNumber, type TypeObjectString, Validation, ValidationBase, type ValidationCallback, type ValidationCallbackAsync, allowed, cache, camelCase, chunkArray, clamp, cutText, dateFormat, debounce, decodeHTML, denied, each, encodeHTML, forEachAsync, forEachIndex, forEachKey, forEachSeries, forLoop, hash, hexToRgb, isArray, isBoolean, isCharacter, isDef, isDigit, isFloat, isFunction, isInteger, isLetter, isNull, isNumber, isObject, isString, isSymbol, isUndefined, lerp, loop, lowerCamelCase, map, mask, maskMoney, maskReverse, maskTest, merge, msToString, noop, parseMs, parseSize, rangeArray, rgbToHex, shadeColor, shuffleArray, 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.21
2
+ * @andrewcaires/utils.js v0.2.22
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- const t={},e=t=>"array"==v(t),r=t=>"boolean"==v(t),s=t=>"null"!=v(t),i=t=>"function"==v(t),n=t=>"number"==v(t),a=t=>"object"==v(t),h=t=>"string"==v(t),u=t=>n(t)&&!!(t%1),l=t=>n(t)&&!(t%1),o=t=>null===t,c=t=>void 0===t,v=e=>null==e?"null":t[t.toString.call(e)]||"object";["Array","Boolean","Function","Number","Object","String"].forEach((e=>t["[object "+e+"]"]=e.toLowerCase()));const p=(t,e)=>{const r=[];for(let s=0;s<t.length;s+=e)r.push(t.slice(s,s+e));return r},d=(t,e,r=1)=>Array.from({length:(e-t)/r+1},((e,s)=>t+s*r)),m=t=>{for(let e=t.length-1;e>0;e--){const r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t},f=t=>e(t)?t:s(t)?[t]:[],g=t=>"true"===t||"1"===t,y=()=>{const t=[],e=[];return r=>{let s=t.indexOf(r);return-1==s&&(t.push(r),e.push({}),s=e.length-1),e[s]}},_=(t,e,r)=>Math.max(e,Math.min(r,t)),x=(t,e,r)=>t+(e-t)*_(r,0,1),w=t=>("0"+t).slice(-2),k=t=>parseInt(t,16)||0,b=(t,e)=>{return(r=k(t)+e,_(r,0,255)).toString(16);var r},S=t=>{var e;return(null===(e=t.replace(/^#/,"").match(/.{1,2}/g))||void 0===e?void 0:e.map((t=>k(t))))||[]},j=(t,e,r)=>"#"+w(t.toString(16))+w(e.toString(16))+w(r.toString(16)),C=(t,e)=>"#"+t.replace(/^#/,"").replace(/../g,(t=>w(b(t,e)))),O=t=>Math.random().toString(16).slice(t),A=()=>O(-3),I=()=>O(-4),M=()=>I()+I(),E=()=>M()+M(),F=()=>A()+I(),L=()=>E()+E()+E()+E(),N=()=>M()+"-"+I()+"-4"+A()+"-"+I()+"-"+(M()+I()),T=t=>("0"+t.toString()).slice(-2),U={"%y":t=>T(t.getFullYear()),"%Y":t=>t.getFullYear().toString(),"%m":t=>T(t.getMonth()+1),"%d":t=>T(t.getDate()),"%H":t=>T(t.getHours()),"%M":t=>T(t.getMinutes()),"%S":t=>T(t.getSeconds())},q=(t,e)=>e.replace(/%[yYmdHMS]/g,(e=>U[e]?U[e](t):e.slice(1)));function Y(t,e,r,s){return new(r||(r=Promise))((function(i,n){function a(t){try{u(s.next(t))}catch(t){n(t)}}function h(t){try{u(s.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,h)}u((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const $=(t,e)=>{let r;const s=()=>{r&&clearTimeout(r)};return{cancel:s,run(...i){s(),r=setTimeout((()=>t(...i)),e)}}},H=(t,e)=>{let r=!1;const s=()=>Y(void 0,void 0,void 0,(function*(){r&&(yield t(),setTimeout(s,e))}));return{start(){r||(r=!0,s())},stop(){r=!1}}};class P{constructor(){this.events=new Map}on(t,e){const r=this.events.get(t);return r?r.push(e):this.events.set(t,[e]),{dispose:()=>this.off(t,e)}}once(t,e){const r=s=>{e(s),this.off(t,r)};return this.on(t,r),{dispose:()=>this.off(t,r)}}off(t,e){const r=this.events.get(t);if(e){if(r){const t=r.indexOf(e);t>=0&&r.splice(t,1)}}else this.events.set(t,[])}emit(t,e){const r=this.events.get(t);r&&r.forEach((t=>t(e)))}}const D=(t,r,s)=>e(t)?J(t,r,s):a(t)?W(t,r,s):null,J=(t,e,r)=>{for(let s=0;s<t.length&&!1!==e.call(r,t[s],s,t);s++);return t},W=(t,e,r)=>{let s="";const i=Object.keys(t);for(let n=0;n<i.length&&(s=i[n],!1!==e.call(r,t[s],s,t));n++);return t},Z=(t,e,r)=>{for(let s=1;s<=t&&!1!==e.call(r,s,t);s++);return t},z=(t,e,r)=>{let s="";const i=Object.keys(t);for(let n=0;n<i.length;n++)s=i[n],t[s]=e.call(r,t[s],s,t);return t},B=()=>{},G="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",K=(t,e,r)=>{let s="";for(let i=0;i<t.length;i++){const n=G.indexOf(t[i]),a=G.indexOf(e[i%e.length]);s+=-1===n||-1===a?t[i]:G[(r?n-a+62:n+a)%62]}return s},Q=t=>(t=K(G,t,!1),{generate:e=>K(e,t,!1),reverse:e=>K(e,t,!0)}),R=(t,e)=>{if(t.length>e){const r=t.substring(0,e).split(" ");return r.pop(),r.join(" ")+"..."}return t},V=t=>t.replace(/&#(\d+);/g,((t,e)=>String.fromCharCode(e))),X=t=>t.replace(/[\u00A0-\u9999<>\\&]/g,(t=>"&#"+t.charCodeAt(0)+";")),tt=(t,e)=>e(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,""),et=t=>/^[\w]$/.test(t),rt=t=>/^[\d]$/.test(t),st=t=>/^[A-Za-z]$/.test(t),it=t=>/^[^\w]$/.test(t),nt=t=>tt(t,(t=>t.replace(/\s(\w)/g,(t=>t.toUpperCase())))),at=nt,ht=t=>tt(t,(t=>t.replace(/(\w)(\w*)/g,((t,e,r)=>e.toUpperCase()+r)))),ut=t=>t.split("").reverse().join(""),lt=t=>(t.maskIndex--,""),ot={"#":({value:t})=>t,0:t=>rt(t.value)?t.value:lt(t),9:t=>rt(t.value)?t.value:lt(t),A:t=>st(t.value)?t.value:lt(t),Z:t=>st(t.value)?t.value:lt(t),L:t=>st(t.value)?t.value.toLowerCase():lt(t),U:t=>st(t.value)?t.value.toUpperCase():lt(t),S:t=>it(t.value)?t.value:lt(t)},ct=t=>{t.maskIndex++,t.textIndex++;const{mask:e,maskIndex:r,text:s,textIndex:i}=t;t.key=e[r],t.value=s[i];const{key:n,value:a}=t;return c(n)||c(a)?"":(t=>ot[t.key]?ot[t.key](t):(t.key!=t.value&&t.textIndex--,t.key))(t)+ct(t)},vt=(t,e)=>ct({mask:t,maskIndex:-1,text:e,textIndex:-1,key:"",value:""}),pt=(t,e,r)=>(r++,e=parseInt((e||"0").replace(/\W/g,"")).toString(),ft(t,e.length<r?("0".repeat(r)+e).slice(-1*r):e)),dt=vt,mt=(t,e)=>t.length==dt(t,e).length,ft=(t,e)=>ut(dt(ut(t),ut(e))),gt=36e5,yt=24*gt,_t={ms:1,s:1e3,m:6e4,h:gt,d:yt,w:6048e5,y:315576e5},xt=t=>{const e=/(-?(?:\d+)?\.?\d+) *(ms|s|m|h|d|w|y)/gm;let r,s=0;for(;null!==(r=e.exec(t));)r.index===e.lastIndex&&e.lastIndex++,s+=parseFloat(r[1])*_t[r[2]]||0;return s},wt=["y","d","h","m","s","ms"],kt=t=>{const e=[];return wt.forEach((r=>{const s=_t[r],i=(t-t%s)/s;i&&(t-=i*s,e.push(i.toString()+r))})),e.join(" ")},bt=(t,e)=>t.reduce(((t,r)=>Object.assign(Object.assign({},t),{[r]:e[r]})),{}),St=(t,e)=>bt(Object.keys(e).filter((e=>-1==t.indexOf(e))),e),jt=(t,e,r)=>Y(void 0,void 0,void 0,(function*(){yield Promise.allSettled(t.map(((s,i)=>e.call(r,s,i,t)))).catch(B)})),Ct=(t,e,r)=>Y(void 0,void 0,void 0,(function*(){for(let s=0;s<t.length;s++)yield e.call(r,t[s],s,t).catch(B)})),Ot=t=>new Promise((e=>setTimeout(e,t))),At=t=>{if(n(t))return t+"px";const e=(t=>/(-?(?:\d+)?\.?\d+) *(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(t))(t);return e?parseFloat(e[1])+(e[2]||"px"):"0px"};class It{constructor(){this.name="",this._error="",this._filter=[],this._type="any",this.rules=[],this.custom=[]}empty(t){return this._value=t,this.unshift((t=>{const e=s(t);return{break:!e,value:e?t:this._value}}))}error(t){return this._error=t,this}filter(...t){return this._filter=t,this.unshift((t=>{const e=-1==this._filter.indexOf(t);return{break:!e,value:e?t:void 0}}))}invalid(t){return{error:this._error?this._error:this.name?this.name+":"+t:t}}parse(){return this.unshift((t=>({value:t})))}push(t){return this.rules.push(t),this}required(){return this.unshift((t=>s(t)?{value:t}:this.invalid("["+this._type+"].required")))}test(t){return!h(this.validate(t).error)}testAsync(t){return Y(this,void 0,void 0,(function*(){return!h((yield this.validateAsync(t)).error)}))}unshift(t){return this.rules.unshift(t),this}validate(t){if(this.custom.length)return this.invalid("[async]");let e={value:t};for(let t=0;t<this.rules.length;t++){if(e=this.rules[t](e.value),e.error)return{error:e.error};if(e.break)return{value:e.value}}return{value:e.value}}validateAsync(t){return Y(this,void 0,void 0,(function*(){let e=this.validate(t);if(e.error)return{error:e.error};for(let t=0;t<this.custom.length;t++){if(e=yield this.custom[t](e.value),e.error)return{error:e.error};if(e.break)return{value:e.value}}return{value:e.value}}))}}class Mt extends It{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="array",this.push((t=>{if(e(t)){if(this._items){this._items.name="";for(let e=0;e<t.length;e++){const{error:r,value:s}=this._items.validate(t[e]);if(r)return this.invalid("["+this._type+"]< "+r+"["+e+"] >");t[e]=s}}return{value:t}}return this.invalid("["+this._type+"]")}))}between(t,e){return this.min(t),this.max(e)}items(t){return this._items=t,this}length(t){return this._length=t,this.push((t=>t.length==this._length?{value:t}:this.invalid("["+this._type+"].length("+this._length+")")))}max(t){return this._max=t,this.push((t=>t.length<=this._max?{value:t}:this.invalid("["+this._type+"].max("+this._max+")")))}min(t){return this._min=t,this.push((t=>t.length>=this._min?{value:t}:this.invalid("["+this._type+"].min("+this._min+")")))}}class Et extends It{constructor(){super(),this._type="boolean",this.push((t=>r(t)?{value:t}:this.invalid("["+this._type+"]")))}parse(){return this.unshift((t=>({value:s(t)?-1!=[1,"1",!0,"true"].indexOf(t):t})))}}class Ft extends It{constructor(){super(),this._max=0,this._min=0,this._type="number",this.push((t=>n(t)?{value:t}:this.invalid("["+this._type+"]")))}between(t,e){return this.min(t),this.max(e)}max(t){return this._max=t,this.push((t=>t<=this._max?{value:t}:this.invalid("["+this._type+"].max("+this._max+")")))}min(t){return this._min=t,this.push((t=>t>=this._min?{value:t}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((t=>({value:s(t)?parseFloat(t):t})))}}class Lt extends It{constructor(){super(),this._keys={},this._type="object",this.push((t=>{if(a(t)){const e=[],r={};return Object.keys(this._keys).forEach((i=>{const n=this._keys[i];n.name=i;const{error:a,value:h}=n.validate(t[i]);a&&e.push(a),s(h)&&(r[i]=h)})),e.length?this.invalid("["+this._type+"]{ "+e.join(", ")+" }"):{value:r}}return this.invalid("["+this._type+"]")}))}keys(t){return this._keys=t||{},this}parse(){return this.unshift((t=>{if(!a(t))try{t=JSON.parse(t)}catch(t){return this.invalid("["+this._type+"]")}const e=Object.keys(this._keys);return{value:e.length?bt(e,t):t}}))}}class Nt extends It{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="string",this.push((t=>h(t)?{value:t}:this.invalid("["+this._type+"]")))}between(t,e){return this.min(t),this.max(e)}date(){return this.push((t=>isNaN(new Date(t).getTime())?this.invalid("["+this._type+"].date"):{value:t}))}email(){return this.push((t=>/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(t)?{value:t}:this.invalid("["+this._type+"].email")))}length(t){return this._length=t,this.push((t=>t.length==this._length?{value:t}:this.invalid("["+this._type+"].length("+this._length+")")))}lowerCase(){return this.push((t=>({value:t.toLowerCase()})))}lowerCamelCase(){return this.push((t=>({value:nt(t)})))}max(t){return this._max=t,this.push((t=>t.length<=this._max?{value:t}:this.invalid("["+this._type+"].max("+this._max+")")))}mask(t){return this.push((e=>({value:vt(t,e)})))}min(t){return this._min=t,this.push((t=>t.length>=this._min?{value:t}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((t=>({value:a(t)?JSON.stringify(t):s(t)?t.toString():t})))}required(){return this.push((t=>t.length?{value:t}:this.invalid("["+this._type+"].required")))}trim(){return this.push((t=>({value:t.trim()})))}upperCase(){return this.push((t=>({value:t.toUpperCase()})))}upperCamelCase(){return this.push((t=>({value:ht(t)})))}}class Tt{static array(t){return(new Mt).items(t)}static boolean(){return new Et}static number(){return new Ft}static object(t){return(new Lt).keys(t)}static string(){return new Nt}test(t,...e){return!h(Tt.validate(t,...e).error)}testAsync(t,...e){return Y(this,void 0,void 0,(function*(){return!h((yield Tt.validateAsync(t,...e)).error)}))}static validate(t,...e){let r={value:t};for(let t=0;t<e.length;t++)if(r=e[t].validate(r.value),r.error)return{error:r.error};return r}static validateAsync(t,...e){return Y(this,void 0,void 0,(function*(){let r={value:t};for(let t=0;t<e.length;t++)if(r=yield e[t].validateAsync(r.value),r.error)return{error:r.error};return r}))}}export{P as EventEmitter,Tt as Validation,It as ValidationBase,bt as allowedObject,y as cache,at as camelCase,p as chunkArray,_ as clamp,R as cutText,q as dateFormat,$ as debounce,V as decodeHTML,St as deniedObject,D as each,X as encodeHTML,jt as forEachAsync,J as forEachIndex,W as forEachKey,Ct as forEachSeries,Z as forLoop,Q as hash,S as hexToRgb,e as isArray,r as isBoolean,et as isCharacter,s as isDef,rt as isDigit,u as isFloat,i as isFunction,l as isInteger,st as isLetter,o as isNull,n as isNumber,a as isObject,h as isString,it as isSymbol,c as isUndefined,x as lerp,H as loop,nt as lowerCamelCase,z as map,vt as mask,pt as maskMoney,ft as maskReverse,mt as maskTest,kt as msToString,B as noop,xt as parseMs,At as parseSize,d as rangeArray,j as rgbToHex,C as shadeColor,m as shuffleArray,F as simpleID,Ot as sleep,ut as stringReverse,f as toArray,g as toBool,v as type,L as uniqueID,ht as upperCamelCase,N as uuidv4};
7
+ const t={},e=t=>"array"==v(t),r=t=>"boolean"==v(t),s=t=>"null"!=v(t),i=t=>"function"==v(t),n=t=>"number"==v(t),a=t=>"object"==v(t),h=t=>"string"==v(t),u=t=>n(t)&&!!(t%1),l=t=>n(t)&&!(t%1),o=t=>null===t,c=t=>void 0===t,v=e=>null==e?"null":t[t.toString.call(e)]||"object";["Array","Boolean","Function","Number","Object","String"].forEach((e=>t["[object "+e+"]"]=e.toLowerCase()));const p=(t,e)=>{const r=[];for(let s=0;s<t.length;s+=e)r.push(t.slice(s,s+e));return r},d=(t,e,r=1)=>Array.from({length:(e-t)/r+1},((e,s)=>t+s*r)),m=t=>{for(let e=t.length-1;e>0;e--){const r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t},f=t=>e(t)?t:s(t)?[t]:[],g=t=>"true"===t||"1"===t,y=()=>{const t=[],e=[];return r=>{let s=t.indexOf(r);return-1==s&&(t.push(r),e.push({}),s=e.length-1),e[s]}},_=(t,e,r)=>Math.max(e,Math.min(r,t)),x=(t,e,r)=>t+(e-t)*_(r,0,1),b=t=>("0"+t).slice(-2),w=t=>parseInt(t,16)||0,k=(t,e)=>{return(r=w(t)+e,_(r,0,255)).toString(16);var r},S=t=>{var e;return(null===(e=t.replace(/^#/,"").match(/.{1,2}/g))||void 0===e?void 0:e.map((t=>w(t))))||[]},j=(t,e,r)=>"#"+b(t.toString(16))+b(e.toString(16))+b(r.toString(16)),O=(t,e)=>"#"+t.replace(/^#/,"").replace(/../g,(t=>b(k(t,e)))),C=t=>Math.random().toString(16).slice(t),A=()=>C(-3),I=()=>C(-4),M=()=>I()+I(),E=()=>M()+M(),F=()=>A()+I(),L=()=>E()+E()+E()+E(),N=()=>M()+"-"+I()+"-4"+A()+"-"+I()+"-"+(M()+I()),T=t=>("0"+t.toString()).slice(-2),U={"%y":t=>T(t.getFullYear()),"%Y":t=>t.getFullYear().toString(),"%m":t=>T(t.getMonth()+1),"%d":t=>T(t.getDate()),"%H":t=>T(t.getHours()),"%M":t=>T(t.getMinutes()),"%S":t=>T(t.getSeconds())},q=(t,e)=>e.replace(/%[yYmdHMS]/g,(e=>U[e]?U[e](t):e.slice(1)));function Y(t,e,r,s){return new(r||(r=Promise))((function(i,n){function a(t){try{u(s.next(t))}catch(t){n(t)}}function h(t){try{u(s.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,h)}u((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const $=(t,e)=>{let r;const s=()=>{r&&clearTimeout(r)};return{cancel:s,run(...i){s(),r=setTimeout((()=>t(...i)),e)}}},H=(t,e)=>{let r=!1;const s=()=>Y(void 0,void 0,void 0,(function*(){r&&(yield t(),setTimeout(s,e))}));return{start(){r||(r=!0,s())},stop(){r=!1}}};class P{constructor(){this.events=new Map}on(t,e){const r=this.events.get(t);return r?r.push(e):this.events.set(t,[e]),{dispose:()=>this.off(t,e)}}once(t,e){const r=s=>{e(s),this.off(t,r)};return this.on(t,r),{dispose:()=>this.off(t,r)}}off(t,e){const r=this.events.get(t);if(e){if(r){const t=r.indexOf(e);t>=0&&r.splice(t,1)}}else this.events.set(t,[])}emit(t,e){const r=this.events.get(t);r&&r.forEach((t=>t(e)))}}const D=(t,r,s)=>e(t)?J(t,r,s):a(t)?W(t,r,s):null,J=(t,e,r)=>{for(let s=0;s<t.length&&!1!==e.call(r,t[s],s,t);s++);return t},W=(t,e,r)=>{let s="";const i=Object.keys(t);for(let n=0;n<i.length&&(s=i[n],!1!==e.call(r,t[s],s,t));n++);return t},Z=(t,e,r)=>{for(let s=1;s<=t&&!1!==e.call(r,s,t);s++);return t},z=(t,e,r)=>{let s="";const i=Object.keys(t);for(let n=0;n<i.length;n++)s=i[n],t[s]=e.call(r,t[s],s,t);return t},B=()=>{},G="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",K=(t,e,r)=>{let s="";for(let i=0;i<t.length;i++){const n=G.indexOf(t[i]),a=G.indexOf(e[i%e.length]);s+=-1===n||-1===a?t[i]:G[(r?n-a+62:n+a)%62]}return s},Q=t=>(t=K(G,t,!1),{generate:e=>K(e,t,!1),reverse:e=>K(e,t,!0)}),R=(t,e)=>{if(t.length>e){const r=t.substring(0,e).split(" ");return r.pop(),r.join(" ")+"..."}return t},V=t=>t.replace(/&#(\d+);/g,((t,e)=>String.fromCharCode(e))),X=t=>t.replace(/[\u00A0-\u9999<>\\&]/g,(t=>"&#"+t.charCodeAt(0)+";")),tt=(t,e)=>e(t.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,""),et=t=>/^[\w]$/.test(t),rt=t=>/^[\d]$/.test(t),st=t=>/^[A-Za-z]$/.test(t),it=t=>/^[^\w]$/.test(t),nt=t=>tt(t,(t=>t.replace(/\s(\w)/g,(t=>t.toUpperCase())))),at=nt,ht=t=>tt(t,(t=>t.replace(/(\w)(\w*)/g,((t,e,r)=>e.toUpperCase()+r)))),ut=t=>t.split("").reverse().join(""),lt=t=>(t.maskIndex--,""),ot={"#":({value:t})=>t,0:t=>rt(t.value)?t.value:lt(t),9:t=>rt(t.value)?t.value:lt(t),A:t=>st(t.value)?t.value:lt(t),Z:t=>st(t.value)?t.value:lt(t),L:t=>st(t.value)?t.value.toLowerCase():lt(t),U:t=>st(t.value)?t.value.toUpperCase():lt(t),S:t=>it(t.value)?t.value:lt(t)},ct=t=>{t.maskIndex++,t.textIndex++;const{mask:e,maskIndex:r,text:s,textIndex:i}=t;t.key=e[r],t.value=s[i];const{key:n,value:a}=t;return c(n)||c(a)?"":(t=>ot[t.key]?ot[t.key](t):(t.key!=t.value&&t.textIndex--,t.key))(t)+ct(t)},vt=(t,e)=>ct({mask:t,maskIndex:-1,text:e,textIndex:-1,key:"",value:""}),pt=(t,e,r)=>(r++,e=parseInt((e||"0").replace(/\W/g,"")).toString(),ft(t,e.length<r?("0".repeat(r)+e).slice(-1*r):e)),dt=vt,mt=(t,e)=>t.length==dt(t,e).length,ft=(t,e)=>ut(dt(ut(t),ut(e))),gt=36e5,yt=24*gt,_t={ms:1,s:1e3,m:6e4,h:gt,d:yt,w:6048e5,y:315576e5},xt=t=>{const e=/(-?(?:\d+)?\.?\d+) *(ms|s|m|h|d|w|y)/gm;let r,s=0;for(;null!==(r=e.exec(t));)r.index===e.lastIndex&&e.lastIndex++,s+=parseFloat(r[1])*_t[r[2]]||0;return s},bt=["y","d","h","m","s","ms"],wt=t=>{const e=[];return bt.forEach((r=>{const s=_t[r],i=(t-t%s)/s;i&&(t-=i*s,e.push(i.toString()+r))})),e.join(" ")},kt=(t,e)=>t.reduce(((t,r)=>Object.assign(Object.assign({},t),{[r]:e[r]})),{}),St=(t,e)=>kt(Object.keys(e).filter((e=>-1==t.indexOf(e))),e),jt=(t,...e)=>{if(!e.length)return t;const r=e.shift();if(a(t)&&a(r))for(const e in r)a(r[e])?(t[e]||(t=Object.assign(Object.assign({},t),{[e]:{}})),t[e]=jt(t[e],r[e])):t=Object.assign(Object.assign({},t),{[e]:r[e]});return jt(t,...e)},Ot=(t,e,r)=>Y(void 0,void 0,void 0,(function*(){yield Promise.allSettled(t.map(((s,i)=>e.call(r,s,i,t)))).catch(B)})),Ct=(t,e,r)=>Y(void 0,void 0,void 0,(function*(){for(let s=0;s<t.length;s++)yield e.call(r,t[s],s,t).catch(B)})),At=t=>new Promise((e=>setTimeout(e,t))),It=t=>{if(n(t))return t+"px";const e=(t=>/(-?(?:\d+)?\.?\d+) *(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(t))(t);return e?parseFloat(e[1])+(e[2]||"px"):"0px"};class Mt{constructor(){this.name="",this._error="",this._filter=[],this._type="any",this.rules=[],this.custom=[]}empty(t){return this._value=t,this.unshift((t=>{const e=s(t);return{break:!e,value:e?t:this._value}}))}error(t){return this._error=t,this}filter(...t){return this._filter=t,this.unshift((t=>{const e=-1==this._filter.indexOf(t);return{break:!e,value:e?t:void 0}}))}invalid(t){return{error:this._error?this._error:this.name?this.name+":"+t:t}}parse(){return this.unshift((t=>({value:t})))}push(t){return this.rules.push(t),this}required(){return this.unshift((t=>s(t)?{value:t}:this.invalid("["+this._type+"].required")))}test(t){return!h(this.validate(t).error)}testAsync(t){return Y(this,void 0,void 0,(function*(){return!h((yield this.validateAsync(t)).error)}))}unshift(t){return this.rules.unshift(t),this}validate(t){if(this.custom.length)return this.invalid("[async]");let e={value:t};for(let t=0;t<this.rules.length;t++){if(e=this.rules[t](e.value),e.error)return{error:e.error};if(e.break)return{value:e.value}}return{value:e.value}}validateAsync(t){return Y(this,void 0,void 0,(function*(){let e=this.validate(t);if(e.error)return{error:e.error};for(let t=0;t<this.custom.length;t++){if(e=yield this.custom[t](e.value),e.error)return{error:e.error};if(e.break)return{value:e.value}}return{value:e.value}}))}}class Et extends Mt{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="array",this.push((t=>{if(e(t)){if(this._items){this._items.name="";for(let e=0;e<t.length;e++){const{error:r,value:s}=this._items.validate(t[e]);if(r)return this.invalid("["+this._type+"]< "+r+"["+e+"] >");t[e]=s}}return{value:t}}return this.invalid("["+this._type+"]")}))}between(t,e){return this.min(t),this.max(e)}items(t){return this._items=t,this}length(t){return this._length=t,this.push((t=>t.length==this._length?{value:t}:this.invalid("["+this._type+"].length("+this._length+")")))}max(t){return this._max=t,this.push((t=>t.length<=this._max?{value:t}:this.invalid("["+this._type+"].max("+this._max+")")))}min(t){return this._min=t,this.push((t=>t.length>=this._min?{value:t}:this.invalid("["+this._type+"].min("+this._min+")")))}}class Ft extends Mt{constructor(){super(),this._type="boolean",this.push((t=>r(t)?{value:t}:this.invalid("["+this._type+"]")))}parse(){return this.unshift((t=>({value:s(t)?-1!=[1,"1",!0,"true"].indexOf(t):t})))}}class Lt extends Mt{constructor(){super(),this._max=0,this._min=0,this._type="number",this.push((t=>n(t)?{value:t}:this.invalid("["+this._type+"]")))}between(t,e){return this.min(t),this.max(e)}max(t){return this._max=t,this.push((t=>t<=this._max?{value:t}:this.invalid("["+this._type+"].max("+this._max+")")))}min(t){return this._min=t,this.push((t=>t>=this._min?{value:t}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((t=>({value:s(t)?parseFloat(t):t})))}}class Nt extends Mt{constructor(){super(),this._keys={},this._type="object",this.push((t=>{if(a(t)){const e=[],r={};return Object.keys(this._keys).forEach((i=>{const n=this._keys[i];n.name=i;const{error:a,value:h}=n.validate(t[i]);a&&e.push(a),s(h)&&(r[i]=h)})),e.length?this.invalid("["+this._type+"]{ "+e.join(", ")+" }"):{value:r}}return this.invalid("["+this._type+"]")}))}keys(t){return this._keys=t||{},this}parse(){return this.unshift((t=>{if(!a(t))try{t=JSON.parse(t)}catch(t){return this.invalid("["+this._type+"]")}const e=Object.keys(this._keys);return{value:e.length?kt(e,t):t}}))}}class Tt extends Mt{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="string",this.push((t=>h(t)?{value:t}:this.invalid("["+this._type+"]")))}between(t,e){return this.min(t),this.max(e)}date(){return this.push((t=>isNaN(new Date(t).getTime())?this.invalid("["+this._type+"].date"):{value:t}))}email(){return this.push((t=>/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(t)?{value:t}:this.invalid("["+this._type+"].email")))}length(t){return this._length=t,this.push((t=>t.length==this._length?{value:t}:this.invalid("["+this._type+"].length("+this._length+")")))}lowerCase(){return this.push((t=>({value:t.toLowerCase()})))}lowerCamelCase(){return this.push((t=>({value:nt(t)})))}max(t){return this._max=t,this.push((t=>t.length<=this._max?{value:t}:this.invalid("["+this._type+"].max("+this._max+")")))}mask(t){return this.push((e=>({value:vt(t,e)})))}min(t){return this._min=t,this.push((t=>t.length>=this._min?{value:t}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((t=>({value:a(t)?JSON.stringify(t):s(t)?t.toString():t})))}required(){return this.push((t=>t.length?{value:t}:this.invalid("["+this._type+"].required")))}trim(){return this.push((t=>({value:t.trim()})))}upperCase(){return this.push((t=>({value:t.toUpperCase()})))}upperCamelCase(){return this.push((t=>({value:ht(t)})))}}class Ut{static array(t){return(new Et).items(t)}static boolean(){return new Ft}static number(){return new Lt}static object(t){return(new Nt).keys(t)}static string(){return new Tt}test(t,...e){return!h(Ut.validate(t,...e).error)}testAsync(t,...e){return Y(this,void 0,void 0,(function*(){return!h((yield Ut.validateAsync(t,...e)).error)}))}static validate(t,...e){let r={value:t};for(let t=0;t<e.length;t++)if(r=e[t].validate(r.value),r.error)return{error:r.error};return r}static validateAsync(t,...e){return Y(this,void 0,void 0,(function*(){let r={value:t};for(let t=0;t<e.length;t++)if(r=yield e[t].validateAsync(r.value),r.error)return{error:r.error};return r}))}}export{P as EventEmitter,Ut as Validation,Mt as ValidationBase,kt as allowed,y as cache,at as camelCase,p as chunkArray,_ as clamp,R as cutText,q as dateFormat,$ as debounce,V as decodeHTML,St as denied,D as each,X as encodeHTML,Ot as forEachAsync,J as forEachIndex,W as forEachKey,Ct as forEachSeries,Z as forLoop,Q as hash,S as hexToRgb,e as isArray,r as isBoolean,et as isCharacter,s as isDef,rt as isDigit,u as isFloat,i as isFunction,l as isInteger,st as isLetter,o as isNull,n as isNumber,a as isObject,h as isString,it as isSymbol,c as isUndefined,x as lerp,H as loop,nt as lowerCamelCase,z as map,vt as mask,pt as maskMoney,ft as maskReverse,mt as maskTest,jt as merge,wt as msToString,B as noop,xt as parseMs,It as parseSize,d as rangeArray,j as rgbToHex,O as shadeColor,m as shuffleArray,F as simpleID,At as sleep,ut as stringReverse,f as toArray,g as toBool,v as type,L as uniqueID,ht as upperCamelCase,N as uuidv4};
package/dist/index.min.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.2.21
2
+ * @andrewcaires/utils.js v0.2.22
3
3
  * JavaScript utility library for web and nodejs development
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- var UtilsJS=function(e){"use strict";const t={},r=e=>"array"==h(e),s=e=>"boolean"==h(e),i=e=>"null"!=h(e),n=e=>"number"==h(e),a=e=>"object"==h(e),l=e=>"string"==h(e),u=e=>void 0===e,h=e=>null==e?"null":t[t.toString.call(e)]||"object";["Array","Boolean","Function","Number","Object","String"].forEach((e=>t["[object "+e+"]"]=e.toLowerCase()));const o=(e,t,r)=>Math.max(t,Math.min(r,e)),c=e=>("0"+e).slice(-2),v=e=>parseInt(e,16)||0,p=(e,t)=>{return(r=v(e)+t,o(r,0,255)).toString(16);var r},d=e=>Math.random().toString(16).slice(e),m=()=>d(-3),f=()=>d(-4),g=()=>f()+f(),y=()=>g()+g(),_=e=>("0"+e.toString()).slice(-2),x={"%y":e=>_(e.getFullYear()),"%Y":e=>e.getFullYear().toString(),"%m":e=>_(e.getMonth()+1),"%d":e=>_(e.getDate()),"%H":e=>_(e.getHours()),"%M":e=>_(e.getMinutes()),"%S":e=>_(e.getSeconds())};function b(e,t,r,s){return new(r||(r=Promise))((function(i,n){function a(e){try{u(s.next(e))}catch(e){n(e)}}function l(e){try{u(s.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,l)}u((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const k=(e,t,r)=>{for(let s=0;s<e.length&&!1!==t.call(r,e[s],s,e);s++);return e},w=(e,t,r)=>{let s="";const i=Object.keys(e);for(let n=0;n<i.length&&(s=i[n],!1!==t.call(r,e[s],s,e));n++);return e},S=()=>{},C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",j=(e,t,r)=>{let s="";for(let i=0;i<e.length;i++){const n=C.indexOf(e[i]),a=C.indexOf(t[i%t.length]);s+=-1===n||-1===a?e[i]:C[(r?n-a+62:n+a)%62]}return s},O=(e,t)=>t(e.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,""),A=e=>/^[\d]$/.test(e),I=e=>/^[A-Za-z]$/.test(e),M=e=>/^[^\w]$/.test(e),E=e=>O(e,(e=>e.replace(/\s(\w)/g,(e=>e.toUpperCase())))),T=E,F=e=>O(e,(e=>e.replace(/(\w)(\w*)/g,((e,t,r)=>t.toUpperCase()+r)))),L=e=>e.split("").reverse().join(""),N=e=>(e.maskIndex--,""),U={"#":({value:e})=>e,0:e=>A(e.value)?e.value:N(e),9:e=>A(e.value)?e.value:N(e),A:e=>I(e.value)?e.value:N(e),Z:e=>I(e.value)?e.value:N(e),L:e=>I(e.value)?e.value.toLowerCase():N(e),U:e=>I(e.value)?e.value.toUpperCase():N(e),S:e=>M(e.value)?e.value:N(e)},D=e=>{e.maskIndex++,e.textIndex++;const{mask:t,maskIndex:r,text:s,textIndex:i}=e;e.key=t[r],e.value=s[i];const{key:n,value:a}=e;return u(n)||u(a)?"":(e=>U[e.key]?U[e.key](e):(e.key!=e.value&&e.textIndex--,e.key))(e)+D(e)},H=(e,t)=>D({mask:e,maskIndex:-1,text:t,textIndex:-1,key:"",value:""}),q=H,B=(e,t)=>L(q(L(e),L(t))),Y=36e5,$=24*Y,J={ms:1,s:1e3,m:6e4,h:Y,d:$,w:6048e5,y:315576e5},P=["y","d","h","m","s","ms"],R=(e,t)=>e.reduce(((e,r)=>Object.assign(Object.assign({},e),{[r]:t[r]})),{});class z{constructor(){this.name="",this._error="",this._filter=[],this._type="any",this.rules=[],this.custom=[]}empty(e){return this._value=e,this.unshift((e=>{const t=i(e);return{break:!t,value:t?e:this._value}}))}error(e){return this._error=e,this}filter(...e){return this._filter=e,this.unshift((e=>{const t=-1==this._filter.indexOf(e);return{break:!t,value:t?e:void 0}}))}invalid(e){return{error:this._error?this._error:this.name?this.name+":"+e:e}}parse(){return this.unshift((e=>({value:e})))}push(e){return this.rules.push(e),this}required(){return this.unshift((e=>i(e)?{value:e}:this.invalid("["+this._type+"].required")))}test(e){return!l(this.validate(e).error)}testAsync(e){return b(this,void 0,void 0,(function*(){return!l((yield this.validateAsync(e)).error)}))}unshift(e){return this.rules.unshift(e),this}validate(e){if(this.custom.length)return this.invalid("[async]");let t={value:e};for(let e=0;e<this.rules.length;e++){if(t=this.rules[e](t.value),t.error)return{error:t.error};if(t.break)return{value:t.value}}return{value:t.value}}validateAsync(e){return b(this,void 0,void 0,(function*(){let t=this.validate(e);if(t.error)return{error:t.error};for(let e=0;e<this.custom.length;e++){if(t=yield this.custom[e](t.value),t.error)return{error:t.error};if(t.break)return{value:t.value}}return{value:t.value}}))}}class V extends z{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="array",this.push((e=>{if(r(e)){if(this._items){this._items.name="";for(let t=0;t<e.length;t++){const{error:r,value:s}=this._items.validate(e[t]);if(r)return this.invalid("["+this._type+"]< "+r+"["+t+"] >");e[t]=s}}return{value:e}}return this.invalid("["+this._type+"]")}))}between(e,t){return this.min(e),this.max(t)}items(e){return this._items=e,this}length(e){return this._length=e,this.push((e=>e.length==this._length?{value:e}:this.invalid("["+this._type+"].length("+this._length+")")))}max(e){return this._max=e,this.push((e=>e.length<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}min(e){return this._min=e,this.push((e=>e.length>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}}class W extends z{constructor(){super(),this._type="boolean",this.push((e=>s(e)?{value:e}:this.invalid("["+this._type+"]")))}parse(){return this.unshift((e=>({value:i(e)?-1!=[1,"1",!0,"true"].indexOf(e):e})))}}class Z extends z{constructor(){super(),this._max=0,this._min=0,this._type="number",this.push((e=>n(e)?{value:e}:this.invalid("["+this._type+"]")))}between(e,t){return this.min(e),this.max(t)}max(e){return this._max=e,this.push((e=>e<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}min(e){return this._min=e,this.push((e=>e>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((e=>({value:i(e)?parseFloat(e):e})))}}class K extends z{constructor(){super(),this._keys={},this._type="object",this.push((e=>{if(a(e)){const t=[],r={};return Object.keys(this._keys).forEach((s=>{const n=this._keys[s];n.name=s;const{error:a,value:l}=n.validate(e[s]);a&&t.push(a),i(l)&&(r[s]=l)})),t.length?this.invalid("["+this._type+"]{ "+t.join(", ")+" }"):{value:r}}return this.invalid("["+this._type+"]")}))}keys(e){return this._keys=e||{},this}parse(){return this.unshift((e=>{if(!a(e))try{e=JSON.parse(e)}catch(e){return this.invalid("["+this._type+"]")}const t=Object.keys(this._keys);return{value:t.length?R(t,e):e}}))}}class G extends z{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="string",this.push((e=>l(e)?{value:e}:this.invalid("["+this._type+"]")))}between(e,t){return this.min(e),this.max(t)}date(){return this.push((e=>isNaN(new Date(e).getTime())?this.invalid("["+this._type+"].date"):{value:e}))}email(){return this.push((e=>/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(e)?{value:e}:this.invalid("["+this._type+"].email")))}length(e){return this._length=e,this.push((e=>e.length==this._length?{value:e}:this.invalid("["+this._type+"].length("+this._length+")")))}lowerCase(){return this.push((e=>({value:e.toLowerCase()})))}lowerCamelCase(){return this.push((e=>({value:E(e)})))}max(e){return this._max=e,this.push((e=>e.length<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}mask(e){return this.push((t=>({value:H(e,t)})))}min(e){return this._min=e,this.push((e=>e.length>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((e=>({value:a(e)?JSON.stringify(e):i(e)?e.toString():e})))}required(){return this.push((e=>e.length?{value:e}:this.invalid("["+this._type+"].required")))}trim(){return this.push((e=>({value:e.trim()})))}upperCase(){return this.push((e=>({value:e.toUpperCase()})))}upperCamelCase(){return this.push((e=>({value:F(e)})))}}class Q{static array(e){return(new V).items(e)}static boolean(){return new W}static number(){return new Z}static object(e){return(new K).keys(e)}static string(){return new G}test(e,...t){return!l(Q.validate(e,...t).error)}testAsync(e,...t){return b(this,void 0,void 0,(function*(){return!l((yield Q.validateAsync(e,...t)).error)}))}static validate(e,...t){let r={value:e};for(let e=0;e<t.length;e++)if(r=t[e].validate(r.value),r.error)return{error:r.error};return r}static validateAsync(e,...t){return b(this,void 0,void 0,(function*(){let r={value:e};for(let e=0;e<t.length;e++)if(r=yield t[e].validateAsync(r.value),r.error)return{error:r.error};return r}))}}return e.EventEmitter=class{constructor(){this.events=new Map}on(e,t){const r=this.events.get(e);return r?r.push(t):this.events.set(e,[t]),{dispose:()=>this.off(e,t)}}once(e,t){const r=s=>{t(s),this.off(e,r)};return this.on(e,r),{dispose:()=>this.off(e,r)}}off(e,t){const r=this.events.get(e);if(t){if(r){const e=r.indexOf(t);e>=0&&r.splice(e,1)}}else this.events.set(e,[])}emit(e,t){const r=this.events.get(e);r&&r.forEach((e=>e(t)))}},e.Validation=Q,e.ValidationBase=z,e.allowedObject=R,e.cache=()=>{const e=[],t=[];return r=>{let s=e.indexOf(r);return-1==s&&(e.push(r),t.push({}),s=t.length-1),t[s]}},e.camelCase=T,e.chunkArray=(e,t)=>{const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r},e.clamp=o,e.cutText=(e,t)=>{if(e.length>t){const r=e.substring(0,t).split(" ");return r.pop(),r.join(" ")+"..."}return e},e.dateFormat=(e,t)=>t.replace(/%[yYmdHMS]/g,(t=>x[t]?x[t](e):t.slice(1))),e.debounce=(e,t)=>{let r;const s=()=>{r&&clearTimeout(r)};return{cancel:s,run(...i){s(),r=setTimeout((()=>e(...i)),t)}}},e.decodeHTML=e=>e.replace(/&#(\d+);/g,((e,t)=>String.fromCharCode(t))),e.deniedObject=(e,t)=>R(Object.keys(t).filter((t=>-1==e.indexOf(t))),t),e.each=(e,t,s)=>r(e)?k(e,t,s):a(e)?w(e,t,s):null,e.encodeHTML=e=>e.replace(/[\u00A0-\u9999<>\\&]/g,(e=>"&#"+e.charCodeAt(0)+";")),e.forEachAsync=(e,t,r)=>b(void 0,void 0,void 0,(function*(){yield Promise.allSettled(e.map(((s,i)=>t.call(r,s,i,e)))).catch(S)})),e.forEachIndex=k,e.forEachKey=w,e.forEachSeries=(e,t,r)=>b(void 0,void 0,void 0,(function*(){for(let s=0;s<e.length;s++)yield t.call(r,e[s],s,e).catch(S)})),e.forLoop=(e,t,r)=>{for(let s=1;s<=e&&!1!==t.call(r,s,e);s++);return e},e.hash=e=>(e=j(C,e,!1),{generate:t=>j(t,e,!1),reverse:t=>j(t,e,!0)}),e.hexToRgb=e=>{var t;return(null===(t=e.replace(/^#/,"").match(/.{1,2}/g))||void 0===t?void 0:t.map((e=>v(e))))||[]},e.isArray=r,e.isBoolean=s,e.isCharacter=e=>/^[\w]$/.test(e),e.isDef=i,e.isDigit=A,e.isFloat=e=>n(e)&&!!(e%1),e.isFunction=e=>"function"==h(e),e.isInteger=e=>n(e)&&!(e%1),e.isLetter=I,e.isNull=e=>null===e,e.isNumber=n,e.isObject=a,e.isString=l,e.isSymbol=M,e.isUndefined=u,e.lerp=(e,t,r)=>e+(t-e)*o(r,0,1),e.loop=(e,t)=>{let r=!1;const s=()=>b(void 0,void 0,void 0,(function*(){r&&(yield e(),setTimeout(s,t))}));return{start(){r||(r=!0,s())},stop(){r=!1}}},e.lowerCamelCase=E,e.map=(e,t,r)=>{let s="";const i=Object.keys(e);for(let n=0;n<i.length;n++)s=i[n],e[s]=t.call(r,e[s],s,e);return e},e.mask=H,e.maskMoney=(e,t,r)=>(r++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),B(e,t.length<r?("0".repeat(r)+t).slice(-1*r):t)),e.maskReverse=B,e.maskTest=(e,t)=>e.length==q(e,t).length,e.msToString=e=>{const t=[];return P.forEach((r=>{const s=J[r],i=(e-e%s)/s;i&&(e-=i*s,t.push(i.toString()+r))})),t.join(" ")},e.noop=S,e.parseMs=e=>{const t=/(-?(?:\d+)?\.?\d+) *(ms|s|m|h|d|w|y)/gm;let r,s=0;for(;null!==(r=t.exec(e));)r.index===t.lastIndex&&t.lastIndex++,s+=parseFloat(r[1])*J[r[2]]||0;return s},e.parseSize=e=>{if(n(e))return e+"px";const t=(e=>/(-?(?:\d+)?\.?\d+) *(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(e))(e);return t?parseFloat(t[1])+(t[2]||"px"):"0px"},e.rangeArray=(e,t,r=1)=>Array.from({length:(t-e)/r+1},((t,s)=>e+s*r)),e.rgbToHex=(e,t,r)=>"#"+c(e.toString(16))+c(t.toString(16))+c(r.toString(16)),e.shadeColor=(e,t)=>"#"+e.replace(/^#/,"").replace(/../g,(e=>c(p(e,t)))),e.shuffleArray=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},e.simpleID=()=>m()+f(),e.sleep=e=>new Promise((t=>setTimeout(t,e))),e.stringReverse=L,e.toArray=e=>r(e)?e:i(e)?[e]:[],e.toBool=e=>"true"===e||"1"===e,e.type=h,e.uniqueID=()=>y()+y()+y()+y(),e.upperCamelCase=F,e.uuidv4=()=>g()+"-"+f()+"-4"+m()+"-"+f()+"-"+(g()+f()),e}({});
7
+ var UtilsJS=function(e){"use strict";const t={},r=e=>"array"==h(e),s=e=>"boolean"==h(e),i=e=>"null"!=h(e),n=e=>"number"==h(e),a=e=>"object"==h(e),l=e=>"string"==h(e),u=e=>void 0===e,h=e=>null==e?"null":t[t.toString.call(e)]||"object";["Array","Boolean","Function","Number","Object","String"].forEach((e=>t["[object "+e+"]"]=e.toLowerCase()));const o=(e,t,r)=>Math.max(t,Math.min(r,e)),c=e=>("0"+e).slice(-2),v=e=>parseInt(e,16)||0,p=(e,t)=>{return(r=v(e)+t,o(r,0,255)).toString(16);var r},d=e=>Math.random().toString(16).slice(e),m=()=>d(-3),f=()=>d(-4),g=()=>f()+f(),y=()=>g()+g(),_=e=>("0"+e.toString()).slice(-2),x={"%y":e=>_(e.getFullYear()),"%Y":e=>e.getFullYear().toString(),"%m":e=>_(e.getMonth()+1),"%d":e=>_(e.getDate()),"%H":e=>_(e.getHours()),"%M":e=>_(e.getMinutes()),"%S":e=>_(e.getSeconds())};function b(e,t,r,s){return new(r||(r=Promise))((function(i,n){function a(e){try{u(s.next(e))}catch(e){n(e)}}function l(e){try{u(s.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,l)}u((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const k=(e,t,r)=>{for(let s=0;s<e.length&&!1!==t.call(r,e[s],s,e);s++);return e},w=(e,t,r)=>{let s="";const i=Object.keys(e);for(let n=0;n<i.length&&(s=i[n],!1!==t.call(r,e[s],s,e));n++);return e},S=()=>{},C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",j=(e,t,r)=>{let s="";for(let i=0;i<e.length;i++){const n=C.indexOf(e[i]),a=C.indexOf(t[i%t.length]);s+=-1===n||-1===a?e[i]:C[(r?n-a+62:n+a)%62]}return s},O=(e,t)=>t(e.toLowerCase().replace(/\W+/g," ")).replace(/\s/g,""),A=e=>/^[\d]$/.test(e),I=e=>/^[A-Za-z]$/.test(e),M=e=>/^[^\w]$/.test(e),E=e=>O(e,(e=>e.replace(/\s(\w)/g,(e=>e.toUpperCase())))),T=E,F=e=>O(e,(e=>e.replace(/(\w)(\w*)/g,((e,t,r)=>t.toUpperCase()+r)))),L=e=>e.split("").reverse().join(""),N=e=>(e.maskIndex--,""),U={"#":({value:e})=>e,0:e=>A(e.value)?e.value:N(e),9:e=>A(e.value)?e.value:N(e),A:e=>I(e.value)?e.value:N(e),Z:e=>I(e.value)?e.value:N(e),L:e=>I(e.value)?e.value.toLowerCase():N(e),U:e=>I(e.value)?e.value.toUpperCase():N(e),S:e=>M(e.value)?e.value:N(e)},D=e=>{e.maskIndex++,e.textIndex++;const{mask:t,maskIndex:r,text:s,textIndex:i}=e;e.key=t[r],e.value=s[i];const{key:n,value:a}=e;return u(n)||u(a)?"":(e=>U[e.key]?U[e.key](e):(e.key!=e.value&&e.textIndex--,e.key))(e)+D(e)},H=(e,t)=>D({mask:e,maskIndex:-1,text:t,textIndex:-1,key:"",value:""}),q=H,B=(e,t)=>L(q(L(e),L(t))),Y=36e5,$=24*Y,J={ms:1,s:1e3,m:6e4,h:Y,d:$,w:6048e5,y:315576e5},P=["y","d","h","m","s","ms"],R=(e,t)=>e.reduce(((e,r)=>Object.assign(Object.assign({},e),{[r]:t[r]})),{}),z=(e,...t)=>{if(!t.length)return e;const r=t.shift();if(a(e)&&a(r))for(const t in r)a(r[t])?(e[t]||(e=Object.assign(Object.assign({},e),{[t]:{}})),e[t]=z(e[t],r[t])):e=Object.assign(Object.assign({},e),{[t]:r[t]});return z(e,...t)};class V{constructor(){this.name="",this._error="",this._filter=[],this._type="any",this.rules=[],this.custom=[]}empty(e){return this._value=e,this.unshift((e=>{const t=i(e);return{break:!t,value:t?e:this._value}}))}error(e){return this._error=e,this}filter(...e){return this._filter=e,this.unshift((e=>{const t=-1==this._filter.indexOf(e);return{break:!t,value:t?e:void 0}}))}invalid(e){return{error:this._error?this._error:this.name?this.name+":"+e:e}}parse(){return this.unshift((e=>({value:e})))}push(e){return this.rules.push(e),this}required(){return this.unshift((e=>i(e)?{value:e}:this.invalid("["+this._type+"].required")))}test(e){return!l(this.validate(e).error)}testAsync(e){return b(this,void 0,void 0,(function*(){return!l((yield this.validateAsync(e)).error)}))}unshift(e){return this.rules.unshift(e),this}validate(e){if(this.custom.length)return this.invalid("[async]");let t={value:e};for(let e=0;e<this.rules.length;e++){if(t=this.rules[e](t.value),t.error)return{error:t.error};if(t.break)return{value:t.value}}return{value:t.value}}validateAsync(e){return b(this,void 0,void 0,(function*(){let t=this.validate(e);if(t.error)return{error:t.error};for(let e=0;e<this.custom.length;e++){if(t=yield this.custom[e](t.value),t.error)return{error:t.error};if(t.break)return{value:t.value}}return{value:t.value}}))}}class W extends V{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="array",this.push((e=>{if(r(e)){if(this._items){this._items.name="";for(let t=0;t<e.length;t++){const{error:r,value:s}=this._items.validate(e[t]);if(r)return this.invalid("["+this._type+"]< "+r+"["+t+"] >");e[t]=s}}return{value:e}}return this.invalid("["+this._type+"]")}))}between(e,t){return this.min(e),this.max(t)}items(e){return this._items=e,this}length(e){return this._length=e,this.push((e=>e.length==this._length?{value:e}:this.invalid("["+this._type+"].length("+this._length+")")))}max(e){return this._max=e,this.push((e=>e.length<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}min(e){return this._min=e,this.push((e=>e.length>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}}class Z extends V{constructor(){super(),this._type="boolean",this.push((e=>s(e)?{value:e}:this.invalid("["+this._type+"]")))}parse(){return this.unshift((e=>({value:i(e)?-1!=[1,"1",!0,"true"].indexOf(e):e})))}}class K extends V{constructor(){super(),this._max=0,this._min=0,this._type="number",this.push((e=>n(e)?{value:e}:this.invalid("["+this._type+"]")))}between(e,t){return this.min(e),this.max(t)}max(e){return this._max=e,this.push((e=>e<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}min(e){return this._min=e,this.push((e=>e>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((e=>({value:i(e)?parseFloat(e):e})))}}class G extends V{constructor(){super(),this._keys={},this._type="object",this.push((e=>{if(a(e)){const t=[],r={};return Object.keys(this._keys).forEach((s=>{const n=this._keys[s];n.name=s;const{error:a,value:l}=n.validate(e[s]);a&&t.push(a),i(l)&&(r[s]=l)})),t.length?this.invalid("["+this._type+"]{ "+t.join(", ")+" }"):{value:r}}return this.invalid("["+this._type+"]")}))}keys(e){return this._keys=e||{},this}parse(){return this.unshift((e=>{if(!a(e))try{e=JSON.parse(e)}catch(e){return this.invalid("["+this._type+"]")}const t=Object.keys(this._keys);return{value:t.length?R(t,e):e}}))}}class Q extends V{constructor(){super(),this._length=0,this._max=0,this._min=0,this._type="string",this.push((e=>l(e)?{value:e}:this.invalid("["+this._type+"]")))}between(e,t){return this.min(e),this.max(t)}date(){return this.push((e=>isNaN(new Date(e).getTime())?this.invalid("["+this._type+"].date"):{value:e}))}email(){return this.push((e=>/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(e)?{value:e}:this.invalid("["+this._type+"].email")))}length(e){return this._length=e,this.push((e=>e.length==this._length?{value:e}:this.invalid("["+this._type+"].length("+this._length+")")))}lowerCase(){return this.push((e=>({value:e.toLowerCase()})))}lowerCamelCase(){return this.push((e=>({value:E(e)})))}max(e){return this._max=e,this.push((e=>e.length<=this._max?{value:e}:this.invalid("["+this._type+"].max("+this._max+")")))}mask(e){return this.push((t=>({value:H(e,t)})))}min(e){return this._min=e,this.push((e=>e.length>=this._min?{value:e}:this.invalid("["+this._type+"].min("+this._min+")")))}parse(){return this.unshift((e=>({value:a(e)?JSON.stringify(e):i(e)?e.toString():e})))}required(){return this.push((e=>e.length?{value:e}:this.invalid("["+this._type+"].required")))}trim(){return this.push((e=>({value:e.trim()})))}upperCase(){return this.push((e=>({value:e.toUpperCase()})))}upperCamelCase(){return this.push((e=>({value:F(e)})))}}class X{static array(e){return(new W).items(e)}static boolean(){return new Z}static number(){return new K}static object(e){return(new G).keys(e)}static string(){return new Q}test(e,...t){return!l(X.validate(e,...t).error)}testAsync(e,...t){return b(this,void 0,void 0,(function*(){return!l((yield X.validateAsync(e,...t)).error)}))}static validate(e,...t){let r={value:e};for(let e=0;e<t.length;e++)if(r=t[e].validate(r.value),r.error)return{error:r.error};return r}static validateAsync(e,...t){return b(this,void 0,void 0,(function*(){let r={value:e};for(let e=0;e<t.length;e++)if(r=yield t[e].validateAsync(r.value),r.error)return{error:r.error};return r}))}}return e.EventEmitter=class{constructor(){this.events=new Map}on(e,t){const r=this.events.get(e);return r?r.push(t):this.events.set(e,[t]),{dispose:()=>this.off(e,t)}}once(e,t){const r=s=>{t(s),this.off(e,r)};return this.on(e,r),{dispose:()=>this.off(e,r)}}off(e,t){const r=this.events.get(e);if(t){if(r){const e=r.indexOf(t);e>=0&&r.splice(e,1)}}else this.events.set(e,[])}emit(e,t){const r=this.events.get(e);r&&r.forEach((e=>e(t)))}},e.Validation=X,e.ValidationBase=V,e.allowed=R,e.cache=()=>{const e=[],t=[];return r=>{let s=e.indexOf(r);return-1==s&&(e.push(r),t.push({}),s=t.length-1),t[s]}},e.camelCase=T,e.chunkArray=(e,t)=>{const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r},e.clamp=o,e.cutText=(e,t)=>{if(e.length>t){const r=e.substring(0,t).split(" ");return r.pop(),r.join(" ")+"..."}return e},e.dateFormat=(e,t)=>t.replace(/%[yYmdHMS]/g,(t=>x[t]?x[t](e):t.slice(1))),e.debounce=(e,t)=>{let r;const s=()=>{r&&clearTimeout(r)};return{cancel:s,run(...i){s(),r=setTimeout((()=>e(...i)),t)}}},e.decodeHTML=e=>e.replace(/&#(\d+);/g,((e,t)=>String.fromCharCode(t))),e.denied=(e,t)=>R(Object.keys(t).filter((t=>-1==e.indexOf(t))),t),e.each=(e,t,s)=>r(e)?k(e,t,s):a(e)?w(e,t,s):null,e.encodeHTML=e=>e.replace(/[\u00A0-\u9999<>\\&]/g,(e=>"&#"+e.charCodeAt(0)+";")),e.forEachAsync=(e,t,r)=>b(void 0,void 0,void 0,(function*(){yield Promise.allSettled(e.map(((s,i)=>t.call(r,s,i,e)))).catch(S)})),e.forEachIndex=k,e.forEachKey=w,e.forEachSeries=(e,t,r)=>b(void 0,void 0,void 0,(function*(){for(let s=0;s<e.length;s++)yield t.call(r,e[s],s,e).catch(S)})),e.forLoop=(e,t,r)=>{for(let s=1;s<=e&&!1!==t.call(r,s,e);s++);return e},e.hash=e=>(e=j(C,e,!1),{generate:t=>j(t,e,!1),reverse:t=>j(t,e,!0)}),e.hexToRgb=e=>{var t;return(null===(t=e.replace(/^#/,"").match(/.{1,2}/g))||void 0===t?void 0:t.map((e=>v(e))))||[]},e.isArray=r,e.isBoolean=s,e.isCharacter=e=>/^[\w]$/.test(e),e.isDef=i,e.isDigit=A,e.isFloat=e=>n(e)&&!!(e%1),e.isFunction=e=>"function"==h(e),e.isInteger=e=>n(e)&&!(e%1),e.isLetter=I,e.isNull=e=>null===e,e.isNumber=n,e.isObject=a,e.isString=l,e.isSymbol=M,e.isUndefined=u,e.lerp=(e,t,r)=>e+(t-e)*o(r,0,1),e.loop=(e,t)=>{let r=!1;const s=()=>b(void 0,void 0,void 0,(function*(){r&&(yield e(),setTimeout(s,t))}));return{start(){r||(r=!0,s())},stop(){r=!1}}},e.lowerCamelCase=E,e.map=(e,t,r)=>{let s="";const i=Object.keys(e);for(let n=0;n<i.length;n++)s=i[n],e[s]=t.call(r,e[s],s,e);return e},e.mask=H,e.maskMoney=(e,t,r)=>(r++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),B(e,t.length<r?("0".repeat(r)+t).slice(-1*r):t)),e.maskReverse=B,e.maskTest=(e,t)=>e.length==q(e,t).length,e.merge=z,e.msToString=e=>{const t=[];return P.forEach((r=>{const s=J[r],i=(e-e%s)/s;i&&(e-=i*s,t.push(i.toString()+r))})),t.join(" ")},e.noop=S,e.parseMs=e=>{const t=/(-?(?:\d+)?\.?\d+) *(ms|s|m|h|d|w|y)/gm;let r,s=0;for(;null!==(r=t.exec(e));)r.index===t.lastIndex&&t.lastIndex++,s+=parseFloat(r[1])*J[r[2]]||0;return s},e.parseSize=e=>{if(n(e))return e+"px";const t=(e=>/(-?(?:\d+)?\.?\d+) *(px|%|cm|mm|in|pt|pc|en|ex|ch|rem|vw|vh|vmin|vmax)*/g.exec(e))(e);return t?parseFloat(t[1])+(t[2]||"px"):"0px"},e.rangeArray=(e,t,r=1)=>Array.from({length:(t-e)/r+1},((t,s)=>e+s*r)),e.rgbToHex=(e,t,r)=>"#"+c(e.toString(16))+c(t.toString(16))+c(r.toString(16)),e.shadeColor=(e,t)=>"#"+e.replace(/^#/,"").replace(/../g,(e=>c(p(e,t)))),e.shuffleArray=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},e.simpleID=()=>m()+f(),e.sleep=e=>new Promise((t=>setTimeout(t,e))),e.stringReverse=L,e.toArray=e=>r(e)?e:i(e)?[e]:[],e.toBool=e=>"true"===e||"1"===e,e.type=h,e.uniqueID=()=>y()+y()+y()+y(),e.upperCamelCase=F,e.uuidv4=()=>g()+"-"+f()+"-4"+m()+"-"+f()+"-"+(g()+f()),e}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/utils.js",
3
- "version": "0.2.21",
3
+ "version": "0.2.22",
4
4
  "description": "JavaScript utility library for web and nodejs development",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "unpkg": "./dist/index.min.js",
@@ -45,17 +45,17 @@
45
45
  "homepage": "https://github.com/andrewcaires/npm/tree/main/utils.js#readme",
46
46
  "devDependencies": {
47
47
  "@jest/globals": "^29.7.0",
48
- "@rollup/plugin-commonjs": "^25.0.4",
49
- "@rollup/plugin-terser": "^0.4.3",
50
- "@rollup/plugin-typescript": "^11.1.3",
51
- "@types/jest": "^29.5.4",
52
- "@types/node": "^20.6.0",
53
- "@typescript-eslint/eslint-plugin": "^6.7.0",
54
- "@typescript-eslint/parser": "^6.7.0",
55
- "eslint": "^8.49.0",
48
+ "@rollup/plugin-commonjs": "^25.0.7",
49
+ "@rollup/plugin-terser": "^0.4.4",
50
+ "@rollup/plugin-typescript": "^11.1.5",
51
+ "@types/jest": "^29.5.6",
52
+ "@types/node": "^20.8.9",
53
+ "@typescript-eslint/eslint-plugin": "^6.9.0",
54
+ "@typescript-eslint/parser": "^6.9.0",
55
+ "eslint": "^8.52.0",
56
56
  "jest": "^29.7.0",
57
- "rollup": "^3.29.1",
58
- "rollup-plugin-dts": "^6.0.2",
57
+ "rollup": "^4.1.5",
58
+ "rollup-plugin-dts": "^6.1.0",
59
59
  "ts-jest": "^29.1.1",
60
60
  "ts-node-dev": "^2.0.0",
61
61
  "tslib": "^2.6.2"