@ztimson/utils 0.15.6 → 0.16.1

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/README.md ADDED
@@ -0,0 +1,91 @@
1
+ <!-- Header -->
2
+ <div id="top" align="center">
3
+ <br />
4
+
5
+ <!-- Logo -->
6
+ <img src="https://git.zakscode.com/repo-avatars/77dbab78e5fb3302dc9e751c4d6315a64df8d3a714d5cd5719b0dc39e6619119" alt="Logo" width="200" height="200">
7
+
8
+ <!-- Title -->
9
+ ### @ztimson/utils
10
+
11
+ <!-- Description -->
12
+ Javascript/Typescript Utilities
13
+
14
+ <!-- Repo badges -->
15
+ [![Version](https://img.shields.io/badge/dynamic/json.svg?label=Version&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/utils/tags&query=$[0].name)](https://git.zakscode.com/ztimson/utils/tags)
16
+ [![Pull Requests](https://img.shields.io/badge/dynamic/json.svg?label=Pull%20Requests&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/utils&query=open_pr_counter)](https://git.zakscode.com/ztimson/utils/pulls)
17
+ [![Issues](https://img.shields.io/badge/dynamic/json.svg?label=Issues&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/utils&query=open_issues_count)](https://git.zakscode.com/ztimson/utils/issues)
18
+
19
+ <!-- Links -->
20
+
21
+ ---
22
+ <div>
23
+ <a href="https://git.zakscode.com/ztimson/utils/wiki" target="_blank">Documentation</a>
24
+ • <a href="https://git.zakscode.com/ztimson/utils/releases" target="_blank">Release Notes</a>
25
+ • <a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
26
+ • <a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
27
+ </div>
28
+
29
+ ---
30
+ </div>
31
+
32
+ ## Table of Contents
33
+ - [@ztimson/utils](#top)
34
+ - [About](#about)
35
+ - [Built With](#built-with)
36
+ - [Setup](#setup)
37
+ - [Production](#production)
38
+ - [Development](#development)
39
+ - [Documentation](https://git.zakscode.com/ztimson/utils/wiki)
40
+ - [License](#license)
41
+
42
+ ## About
43
+
44
+ A collection of utilities to make life a little easier
45
+
46
+ ### Built With
47
+ [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?style=for-the-badge&logo=typescript&logoColor=white)](https://typescriptlang.org/)
48
+
49
+ ## Setup
50
+
51
+ <details>
52
+ <summary>
53
+ <h3 id="production" style="display: inline">
54
+ Production
55
+ </h3>
56
+ </summary>
57
+
58
+ #### Prerequisites
59
+ - [Node.js](https://nodejs.org/en/download)
60
+
61
+ #### Instructions
62
+ 1. Install persist: `npm i @ztimosn/utils`
63
+
64
+ </details>
65
+
66
+ <details>
67
+ <summary>
68
+ <h3 id="development" style="display: inline">
69
+ Development
70
+ </h3>
71
+ </summary>
72
+
73
+ #### Prerequisites
74
+ - [Node.js](https://nodejs.org/en/download)
75
+
76
+ #### Instructions
77
+ 1. Install the dependencies: `npm i`
78
+ 2. Build library: `npm build`
79
+ 3. Run unit tests: `npm test`
80
+
81
+ </details>
82
+
83
+ ## Documentation
84
+
85
+ [Available Here](https://git.zakscode.com/ztimson/utils/wiki)
86
+
87
+ ## License
88
+
89
+ Copyright © 2023 Zakary Timson | Available under MIT Licensing
90
+
91
+ See the [license](_media/LICENSE) for more information.
package/dist/array.d.ts CHANGED
@@ -1,4 +1,26 @@
1
+ /**
2
+ * Only add element to array if it isn't already included
3
+ *
4
+ * @example
5
+ * ```js
6
+ * const arr = addUnique([1, 2, 3], 3);
7
+ * console.log(arr); // Output: [1, 2, 3]
8
+ * ```
9
+ *
10
+ * @param {T[]} array Target array element will be added to
11
+ * @param {T} el Unique element to add
12
+ * @return {T[]} Array with element if it was unique
13
+ * @deprecated Use ASet to create unique arrays
14
+ */
1
15
  export declare function addUnique<T>(array: T[], el: T): T[];
16
+ /**
17
+ * Find all unique elements in arrays
18
+ *
19
+ * @param {any[]} a First array to compare
20
+ * @param {any[]} b Second array to compare
21
+ * @return {any[]} Unique elements
22
+ * @deprecated Use ASet to perform Set operations on arrays
23
+ */
2
24
  export declare function arrayDiff(a: any[], b: any[]): any[];
3
25
  /**
4
26
  * Provides a shorthand for sorting arrays of complex objects by a string property
@@ -13,6 +35,22 @@ export declare function arrayDiff(a: any[], b: any[]): any[];
13
35
  * @returns {(a, b) => (number)} - Function to handle sort (Meant to be passed to Array.prototype.sort or used in sortFn)
14
36
  */
15
37
  export declare function caseInsensitiveSort(prop: string): (a: any, b: any) => number;
38
+ /**
39
+ * Shorthand to find objects with a property value
40
+ *
41
+ * @example
42
+ * ```js
43
+ * const found = [
44
+ * {name: 'Batman'},
45
+ * {name: 'Superman'},
46
+ * ].filter(findByProp('name', 'Batman'));
47
+ * ```
48
+ *
49
+ * @param {string} prop Property to compare (Dot nation supported)
50
+ * @param value Value property must have
51
+ * @return {(v: any) => boolean} Function used by `filter` or `find`
52
+ */
53
+ export declare function findByProp(prop: string, value: any): (v: any) => boolean;
16
54
  /**
17
55
  * Recursively flatten nested arrays
18
56
  *
@@ -56,10 +94,17 @@ export declare function flattenArr(arr: any[], result?: any[]): any[];
56
94
  * @returns {(a, b) => (number)} - Function to handle sort (Meant to be passed to Array.prototype.sort)
57
95
  */
58
96
  export declare function sortByProp(prop: string, reverse?: boolean): (a: any, b: any) => number;
59
- export declare function findByProp(prop: string, value: any): (v: any) => boolean;
97
+ /**
98
+ * Make sure every element in array is unique
99
+ *
100
+ * @param {any[]} arr Array that will be filtered in place
101
+ * @return {any[]} Original array
102
+ * @deprecated Please use ASet to create a guaranteed unique array
103
+ */
60
104
  export declare function makeUnique(arr: any[]): any[];
61
105
  /**
62
- * Make sure value is an array, if it isn't wrap it in one.
106
+ * Make sure value is an array, if it isn't wrap it in one
107
+ *
63
108
  * @param {T[] | T} value Value that should be an array
64
109
  * @returns {T[]} Value in an array
65
110
  */
package/dist/csv.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Convert an object to a CSV string
3
+ *
4
+ * @param {any[]} target Array of objects to create CSV from
5
+ * @param {boolean} flatten Should nested object be flattened or treated as values
6
+ * @return {string} CSV string
7
+ */
8
+ export declare function csv(target: any[], flatten?: boolean): string;
package/dist/files.d.ts CHANGED
@@ -1,10 +1,42 @@
1
1
  import { PromiseProgress } from './promise-progress';
2
- export declare function download(href: any, name: string): void;
3
- export declare function downloadBlob(blob: Blob, name: string): void;
2
+ /**
3
+ * Download blob as a file
4
+ *
5
+ * @param {Blob} blob File as a blob
6
+ * @param {string} name Name blob will be downloaded as
7
+ */
8
+ export declare function downloadFile(blob: Blob | string | string[], name: string): void;
9
+ /**
10
+ * Download a file from a URL
11
+ *
12
+ * @param href URL that will be downloaded
13
+ * @param {string} name Override download name
14
+ */
15
+ export declare function downloadUrl(href: any, name?: string): void;
16
+ /**
17
+ * Open filebrowser & return selected file
18
+ *
19
+ * @param {{accept?: string, multiple?: boolean}} options accept - selectable mimetypes, multiple - Allow selecting more than 1 file
20
+ * @return {Promise<File[]>} Array of selected files
21
+ */
4
22
  export declare function fileBrowser(options?: {
5
23
  accept?: string;
6
24
  multiple?: boolean;
7
25
  }): Promise<File[]>;
26
+ /**
27
+ * Create timestamp intended for filenames from a date
28
+ *
29
+ * @param {string} name Name of file, `{{TIMESTAMP}}` will be replaced
30
+ * @param {Date | number | string} date Date to use for timestamp
31
+ * @return {string} Interpolated filename, or the raw timestamp if name was omitted
32
+ */
33
+ export declare function timestampFilename(name?: string, date?: Date | number | string): string;
34
+ /**
35
+ * Upload file to URL with progress callback using PromiseProgress
36
+ *
37
+ * @param {{url: string, files: File[], headers?: {[p: string]: string}, withCredentials?: boolean}} options
38
+ * @return {PromiseProgress<T>} Promise of request with `onProgress` callback
39
+ */
8
40
  export declare function uploadWithProgress<T>(options: {
9
41
  url: string;
10
42
  files: File[];
package/dist/index.cjs CHANGED
@@ -1,2 +1,3 @@
1
- (function(s,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(s=typeof globalThis<"u"?globalThis:s||self,g(s.utils={}))})(this,function(s){"use strict";var xt=Object.defineProperty;var Xt=(s,g,A)=>g in s?xt(s,g,{enumerable:!0,configurable:!0,writable:!0,value:A}):s[g]=A;var a=(s,g,A)=>(Xt(s,typeof g!="symbol"?g+"":g,A),A);function g(n,t=!1){if(n==null)throw new Error("Cannot clean a NULL value");return Array.isArray(n)?n=n.filter(e=>e!=null):Object.entries(n).forEach(([e,r])=>{(t&&r===void 0||!t&&r==null)&&delete n[e]}),n}function A(n){return JSON.parse(JSON.stringify(n))}function tt(n,...t){return t.forEach(e=>{for(const r in e)e[r]&&typeof e[r]=="object"&&!Array.isArray(e[r])?(n[r]||(n[r]={}),tt(n[r],e[r])):n[r]=e[r]}),n}function C(n,t,e){if(!(n==null||!t))return t.split(/[.[\]]/g).filter(r=>r.length).reduce((r,o,i,c)=>{if((o[0]=='"'||o[0]=="'")&&(o=o.slice(1,-1)),!(r!=null&&r.hasOwnProperty(o))){if(e==null)return;r[o]={}}return e!==void 0&&i==c.length-1?r[o]=e:r[o]},n)}function et(n,t,e={}){if(typeof n=="object"&&!Array.isArray(n)){for(const r of Object.keys(n)){const o=t?t+"."+r:r;typeof n[r]=="object"?et(n[r],o,e):e[o]=n[r]}return e}}function ft(n){const t=new FormData;return Object.entries(n).forEach(([e,r])=>t.append(e,r)),t}function $(n,t,e=!1){if(n==null)return e;if(Array.isArray(t))return t.findIndex((o,i)=>!$(n[i],t[i],e))==-1;const r=typeof t;return r!=typeof n?!1:r=="object"?Object.keys(t).find(o=>!$(n[o],t[o],e))==null:r=="function"?n.toString()==t.toString():n==t}function S(n,t){const e=typeof n,r=typeof t;return e!="object"||n==null||r!="object"||t==null?e=="function"&&r=="function"?n.toString()==t.toString():n===t:Object.keys(n).length!=Object.keys(t).length?!1:Object.keys(n).every(i=>S(n[i],t[i]))}function dt(n,t){t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(r=>{Object.defineProperty(n.prototype,r,Object.getOwnPropertyDescriptor(e.prototype,r)||Object.create(null))})})}function k(n){try{return JSON.parse(n)}catch{return n}}function ht(n,t){let e=[];return JSON.parse(JSON.stringify(n,(r,o)=>{if(typeof o=="object"&&o!==null){if(e.includes(o))return;e.push(o)}return o},t))}function yt(n){return Object.entries(n).map(([t,e])=>encodeURIComponent(t)+"="+encodeURIComponent(e)).join("&")}function mt(n,t){return n.indexOf(t)===-1&&n.push(t),n}function gt(n,t){return rt([...n.filter(e=>!t.includes(r=>S(e,r))),...t.filter(e=>!n.includes(r=>S(e,r)))])}function Et(n){return function(t,e){const r=C(t,n),o=C(e,n);return typeof r!="string"||typeof o!="string"?1:r.toLowerCase().localeCompare(o.toLowerCase())}}function nt(n,t=[]){return n.forEach(e=>Array.isArray(e)?nt(e,t):t.push(e)),t}function wt(n,t=!1){return function(e,r){const o=C(e,n),i=C(r,n);return typeof o=="number"&&typeof i=="number"?(t?-1:1)*(o-i):o>i?t?-1:1:o<i?t?1:-1:0}}function pt(n,t){return e=>S(e[n],t)}function rt(n){for(let t=n.length-1;t>=0;t--)n.slice(0,t).find(e=>S(e,n[t]))&&n.splice(t,1);return n}function Bt(n){return Array.isArray(n)?n:[n]}class R extends Array{get size(){return this.length}constructor(t=[]){super(),t!=null&&t.forEach&&t.forEach(e=>this.add(e))}add(t){this.has(t)||this.push(t)}delete(t){const e=this.indexOf(t);e!=-1&&this.slice(e,1)}difference(t){return new R(this.filter(e=>!t.has(e)))}has(t){return this.indexOf(t)!=-1}intersection(t){return new R(this.filter(e=>t.has(e)))}isDisjointFrom(t){return this.intersection(t).size==0}isSubsetOf(t){return this.findIndex(e=>!t.has(e))==-1}isSuperset(t){return t.findIndex(e=>!this.has(e))==-1}symmetricDifference(t){return new R([...this.difference(t),...t.difference(this)])}union(t){return new R([...this,...t])}}class b extends Promise{constructor(e){super((r,o)=>e(i=>r(i),i=>o(i),i=>this.progress=i));a(this,"listeners",[]);a(this,"_progress",0)}get progress(){return this._progress}set progress(e){e!=this._progress&&(this._progress=e,this.listeners.forEach(r=>r(e)))}static from(e){return e instanceof b?e:new b((r,o)=>e.then((...i)=>r(...i)).catch((...i)=>o(...i)))}from(e){const r=b.from(e);return this.onProgress(o=>r.progress=o),r}onProgress(e){return this.listeners.push(e),this}then(e,r){const o=super.then(e,r);return this.from(o)}catch(e){return this.from(super.catch(e))}finally(e){return this.from(super.finally(e))}}function ot(n,t){const e=document.createElement("a");e.href=n,e.download=t,document.body.appendChild(e),e.click(),document.body.removeChild(e)}function At(n,t){const e=URL.createObjectURL(n);ot(e,t),URL.revokeObjectURL(e)}function bt(n={}){return new Promise(t=>{const e=document.createElement("input");e.type="file",e.accept=n.accept||"*",e.style.display="none",e.multiple=!!n.multiple,e.onblur=e.onchange=async()=>{t(Array.from(e.files)),e.remove()},document.body.appendChild(e),e.click()})}function St(n){return new b((t,e,r)=>{const o=new XMLHttpRequest,i=new FormData;n.files.forEach(c=>i.append("file",c)),o.withCredentials=!!n.withCredentials,o.upload.addEventListener("progress",c=>c.lengthComputable?r(c.loaded/c.total):null),o.addEventListener("loadend",()=>t(k(o.responseText))),o.addEventListener("error",()=>e(k(o.responseText))),o.addEventListener("timeout",()=>e({error:"Request timed out"})),o.open("POST",n.url),Object.entries(n.headers||{}).forEach(([c,w])=>o.setRequestHeader(c,w)),o.send(i)})}class P{constructor(){a(this,"listeners",{})}static emit(t,...e){(this.listeners["*"]||[]).forEach(r=>r(t,...e)),(this.listeners[t.toString()]||[]).forEach(r=>r(...e))}static off(t,e){const r=t.toString();this.listeners[r]=(this.listeners[r]||[]).filter(o=>o===e)}static on(t,e){var o;const r=t.toString();return this.listeners[r]||(this.listeners[r]=[]),(o=this.listeners[r])==null||o.push(e),()=>this.off(t,e)}static once(t,e){return new Promise(r=>{const o=this.on(t,(...i)=>{r(i.length==1?i[0]:i),e&&e(...i),o()})})}emit(t,...e){(this.listeners["*"]||[]).forEach(r=>r(t,...e)),(this.listeners[t]||[]).forEach(r=>r(...e))}off(t,e){this.listeners[t]=(this.listeners[t]||[]).filter(r=>r===e)}on(t,e){var r;return this.listeners[t]||(this.listeners[t]=[]),(r=this.listeners[t])==null||r.push(e),()=>this.off(t,e)}once(t,e){return new Promise(r=>{const o=this.on(t,(...i)=>{r(i.length==1?i[0]:i),e&&e(...i),o()})})}}a(P,"listeners",{});class m extends Error{constructor(e,r){super(e);a(this,"_code");r!=null&&(this._code=r)}get code(){return this._code||this.constructor.code}set code(e){this._code=e}static from(e){const r=Number(e.statusCode)??Number(e.code),o=new this(e.message||e.toString());return Object.assign(o,{stack:e.stack,...e,code:r??void 0})}static instanceof(e){return e.constructor.code!=null}toString(){return this.message||super.toString()}}a(m,"code",500);class M extends m{constructor(t="Bad Request"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(M,"code",400);class U extends m{constructor(t="Unauthorized"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(U,"code",401);class j extends m{constructor(t="Payment Required"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(j,"code",402);class G extends m{constructor(t="Forbidden"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(G,"code",403);class q extends m{constructor(t="Not Found"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(q,"code",404);class v extends m{constructor(t="Method Not Allowed"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(v,"code",405);class F extends m{constructor(t="Not Acceptable"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(F,"code",406);class H extends m{constructor(t="Internal Server Error"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(H,"code",500);class Y extends m{constructor(t="Not Implemented"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(Y,"code",501);class W extends m{constructor(t="Bad Gateway"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(W,"code",502);class z extends m{constructor(t="Service Unavailable"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(z,"code",503);class J extends m{constructor(t="Gateway Timeout"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(J,"code",504);function Rt(n,t){if(n>=200&&n<300)return null;switch(n){case 400:return new M(t);case 401:return new U(t);case 402:return new j(t);case 403:return new G(t);case 404:return new q(t);case 405:return new v(t);case 406:return new F(t);case 500:return new H(t);case 501:return new Y(t);case 502:return new W(t);case 503:return new z(t);case 504:return new J(t);default:return new m(t,n)}}const p=class p{constructor(t={}){a(this,"interceptors",{});a(this,"headers",{});a(this,"url");this.url=t.url??null,this.headers=t.headers||{},t.interceptors&&t.interceptors.forEach(e=>p.addInterceptor(e))}static addInterceptor(t){const e=Object.keys(p.interceptors).length.toString();return p.interceptors[e]=t,()=>{p.interceptors[e]=null}}addInterceptor(t){const e=Object.keys(this.interceptors).length.toString();return this.interceptors[e]=t,()=>{this.interceptors[e]=null}}request(t={}){var o;if(!this.url&&!t.url)throw new Error("URL needs to be set");let e=((o=t.url)!=null&&o.startsWith("http")?t.url:(this.url||"")+(t.url||"")).replace(/([^:]\/)\/+/g,"$1");if(t.fragment&&(e.includes("#")?e.replace(/#.*(\?|\n)/g,(i,c)=>`#${t.fragment}${c}`):e+="#"+t.fragment),t.query){const i=Array.isArray(t.query)?t.query:Object.keys(t.query).map(c=>({key:c,value:t.query[c]}));e+=(e.includes("?")?"&":"?")+i.map(c=>`${c.key}=${c.value}`).join("&")}const r=g({"Content-Type":t.body?t.body instanceof FormData?"multipart/form-data":"application/json":void 0,...p.headers,...this.headers,...t.headers});return typeof t.body=="object"&&t.body!=null&&r["Content-Type"]=="application/json"&&(t.body=JSON.stringify(t.body)),new b((i,c,w)=>{fetch(e,{headers:r,method:t.method||(t.body?"POST":"GET"),body:t.body}).then(async u=>{var ut,lt;for(let l of[...Object.values(p.interceptors),...Object.values(this.interceptors)])await new Promise(D=>l(u,()=>D()));const I=u.headers.get("Content-Length"),Q=I?parseInt(I,10):0;let at=0;const _=(ut=u.body)==null?void 0:ut.getReader(),Zt=new ReadableStream({start(l){function D(){_==null||_.read().then(N=>{if(N.done)return l.close();at+=N.value.byteLength,w(at/Q),l.enqueue(N.value),D()}).catch(N=>l.error(N))}D()}});if(u.data=new Response(Zt),t.decode==null||t.decode){const l=(lt=u.headers.get("Content-Type"))==null?void 0:lt.toLowerCase();l!=null&&l.includes("form")?u.data=await u.data.formData():l!=null&&l.includes("json")?u.data=await u.data.json():l!=null&&l.includes("text")?u.data=await u.data.text():l!=null&&l.includes("application")&&(u.data=await u.data.blob())}u.ok?i(u):c(u)})})}};a(p,"interceptors",{}),a(p,"headers",{});let K=p;const O={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},L={BLACK:"\x1B[30m",RED:"\x1B[31m",GREEN:"\x1B[32m",YELLOW:"\x1B[33m",BLUE:"\x1B[34m",MAGENTA:"\x1B[35m",CYAN:"\x1B[36m",LIGHT_GREY:"\x1B[37m",GREY:"\x1B[90m",LIGHT_RED:"\x1B[91m",LIGHT_GREEN:"\x1B[92m",LIGHT_YELLOW:"\x1B[93m",LIGHT_BLUE:"\x1B[94m",LIGHT_MAGENTA:"\x1B[95m",LIGHT_CYAN:"\x1B[96m",WHITE:"\x1B[97m"},Ot={BLACK:"\x1B[40m",RED:"\x1B[41m",GREEN:"\x1B[42m",YELLOW:"\x1B[43m",BLUE:"\x1B[44m",MAGENTA:"\x1B[45m",CYAN:"\x1B[46m",WHITE:"\x1B[47m",GREY:"\x1B[100m"};var it=(n=>(n[n.ERROR=0]="ERROR",n[n.WARN=1]="WARN",n[n.INFO=2]="INFO",n[n.LOG=3]="LOG",n[n.DEBUG=4]="DEBUG",n))(it||{});const E=class E extends P{constructor(t){super(),this.namespace=t}pad(t,e,r,o=!1){const i=t.toString(),c=e-i.length;if(c<=0)return i;const w=Array(~~(c/r.length)).fill(r).join("");return o?i+w:w+i}format(...t){const e=new Date;return`${`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()} ${this.pad(e.getHours().toString(),2,"0")}:${this.pad(e.getMinutes().toString(),2,"0")}:${this.pad(e.getSeconds().toString(),2,"0")}.${this.pad(e.getMilliseconds().toString(),3,"0",!0)}`}${this.namespace?` [${this.namespace}]`:""} ${t.join(" ")}`}debug(...t){if(E.LOG_LEVEL<4)return;const e=this.format(...t);E.emit(4,e),console.debug(L.LIGHT_GREY+e+O.CLEAR)}log(...t){if(E.LOG_LEVEL<3)return;const e=this.format(...t);E.emit(3,e),console.log(O.CLEAR+e)}info(...t){if(E.LOG_LEVEL<2)return;const e=this.format(...t);E.emit(2,e),console.info(L.BLUE+e+O.CLEAR)}warn(...t){if(E.LOG_LEVEL<1)return;const e=this.format(...t);E.emit(1,e),console.warn(L.YELLOW+e+O.CLEAR)}error(...t){if(E.LOG_LEVEL<0)return;const e=this.format(...t);E.emit(0,e),console.error(L.RED+e+O.CLEAR)}};a(E,"LOG_LEVEL",4);let V=E;function Ct(n){const t=(w,u)=>u<1e-7?w:t(u,~~(w%u)),e=n.toString().length-2;let r=Math.pow(10,e),o=n*r;const i=t(o,r);o=~~(o/i),r=~~(r/i);const c=~~(o/r);return o-=c*r,`${c?c+" ":""}${~~o}/${~~r}`}function Lt(n){let t=n.split(" ");const e=t.length==2?Number(t[0]):0;return t=t.pop().split("/"),e+Number(t[0])/Number(t[1])}function Nt(n,t){return n.length-n.replaceAll(t,"").length}function Tt(n){return Array(n).fill(null).map(()=>Math.round(Math.random()*15).toString(16)).join("")}function It(n,t=2){if(n===0)return"0 Bytes";const e=1024,r=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],o=Math.floor(Math.log(n)/Math.log(e));return parseFloat((n/Math.pow(e,o)).toFixed(t))+" "+r[o]}const Z="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",x="0123456789",X="~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",Dt=Z+x+X;function $t(n){const t=/(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(n);if(!t)throw new Error(`Number cannot be parsed: ${n}`);return`${t[1]??""} (${t[2]}) ${t[3]}-${t[4]}`.trim()}function kt(n,t,e){return`${n.slice(0,e)}${t}${n.slice(e+1)}`}function Pt(n,t,e,r=!0){const o=n.toString(),i=t-o.length;if(i<=0)return o;const c=Array(~~(i/e.length)).fill(e).join("");return r?c+o:o+c}function Mt(n,t=Dt){return Array(n).fill(null).map(()=>{const e=~~(Math.random()*t.length);return t[e]}).join("")}function Ut(n,t=!1,e=!1,r=!1){if(!t&&!e&&!r)throw new Error("Must enable at least one: letters, numbers, symbols");return Array(n).fill(null).map(()=>{let o;do{const i=~~(Math.random()*3);t&&i==0?o=Z[~~(Math.random()*Z.length)]:e&&i==1?o=x[~~(Math.random()*x.length)]:r&&i==2&&(o=X[~~(Math.random()*X.length)])}while(!o);return o}).join("")}function jt(n,t){if(typeof t=="string"&&(t=new RegExp(t,"g")),!t.global)throw new TypeError("Regular expression must be global.");let e=[],r;for(;(r=t.exec(n))!==null;)e.push(r);return e}function ct(n){var t=Gt(vt(Ft(qt(n),8*n.length)));return t.toLowerCase()}function Gt(n){for(var t,e="0123456789ABCDEF",r="",o=0;o<n.length;o++)t=n.charCodeAt(o),r+=e.charAt(t>>>4&15)+e.charAt(15&t);return r}function qt(n){for(var t=Array(n.length>>2),e=0;e<t.length;e++)t[e]=0;for(e=0;e<8*n.length;e+=8)t[e>>5]|=(255&n.charCodeAt(e/8))<<e%32;return t}function vt(n){for(var t="",e=0;e<32*n.length;e+=8)t+=String.fromCharCode(n[e>>5]>>>e%32&255);return t}function Ft(n,t){n[t>>5]|=128<<t%32,n[14+(t+64>>>9<<4)]=t;for(var e=1732584193,r=-271733879,o=-1732584194,i=271733878,c=0;c<n.length;c+=16){var w=e,u=r,I=o,Q=i;r=y(r=y(r=y(r=y(r=h(r=h(r=h(r=h(r=d(r=d(r=d(r=d(r=f(r=f(r=f(r=f(r,o=f(o,i=f(i,e=f(e,r,o,i,n[c+0],7,-680876936),r,o,n[c+1],12,-389564586),e,r,n[c+2],17,606105819),i,e,n[c+3],22,-1044525330),o=f(o,i=f(i,e=f(e,r,o,i,n[c+4],7,-176418897),r,o,n[c+5],12,1200080426),e,r,n[c+6],17,-1473231341),i,e,n[c+7],22,-45705983),o=f(o,i=f(i,e=f(e,r,o,i,n[c+8],7,1770035416),r,o,n[c+9],12,-1958414417),e,r,n[c+10],17,-42063),i,e,n[c+11],22,-1990404162),o=f(o,i=f(i,e=f(e,r,o,i,n[c+12],7,1804603682),r,o,n[c+13],12,-40341101),e,r,n[c+14],17,-1502002290),i,e,n[c+15],22,1236535329),o=d(o,i=d(i,e=d(e,r,o,i,n[c+1],5,-165796510),r,o,n[c+6],9,-1069501632),e,r,n[c+11],14,643717713),i,e,n[c+0],20,-373897302),o=d(o,i=d(i,e=d(e,r,o,i,n[c+5],5,-701558691),r,o,n[c+10],9,38016083),e,r,n[c+15],14,-660478335),i,e,n[c+4],20,-405537848),o=d(o,i=d(i,e=d(e,r,o,i,n[c+9],5,568446438),r,o,n[c+14],9,-1019803690),e,r,n[c+3],14,-187363961),i,e,n[c+8],20,1163531501),o=d(o,i=d(i,e=d(e,r,o,i,n[c+13],5,-1444681467),r,o,n[c+2],9,-51403784),e,r,n[c+7],14,1735328473),i,e,n[c+12],20,-1926607734),o=h(o,i=h(i,e=h(e,r,o,i,n[c+5],4,-378558),r,o,n[c+8],11,-2022574463),e,r,n[c+11],16,1839030562),i,e,n[c+14],23,-35309556),o=h(o,i=h(i,e=h(e,r,o,i,n[c+1],4,-1530992060),r,o,n[c+4],11,1272893353),e,r,n[c+7],16,-155497632),i,e,n[c+10],23,-1094730640),o=h(o,i=h(i,e=h(e,r,o,i,n[c+13],4,681279174),r,o,n[c+0],11,-358537222),e,r,n[c+3],16,-722521979),i,e,n[c+6],23,76029189),o=h(o,i=h(i,e=h(e,r,o,i,n[c+9],4,-640364487),r,o,n[c+12],11,-421815835),e,r,n[c+15],16,530742520),i,e,n[c+2],23,-995338651),o=y(o,i=y(i,e=y(e,r,o,i,n[c+0],6,-198630844),r,o,n[c+7],10,1126891415),e,r,n[c+14],15,-1416354905),i,e,n[c+5],21,-57434055),o=y(o,i=y(i,e=y(e,r,o,i,n[c+12],6,1700485571),r,o,n[c+3],10,-1894986606),e,r,n[c+10],15,-1051523),i,e,n[c+1],21,-2054922799),o=y(o,i=y(i,e=y(e,r,o,i,n[c+8],6,1873313359),r,o,n[c+15],10,-30611744),e,r,n[c+6],15,-1560198380),i,e,n[c+13],21,1309151649),o=y(o,i=y(i,e=y(e,r,o,i,n[c+4],6,-145523070),r,o,n[c+11],10,-1120210379),e,r,n[c+2],15,718787259),i,e,n[c+9],21,-343485551),e=B(e,w),r=B(r,u),o=B(o,I),i=B(i,Q)}return Array(e,r,o,i)}function T(n,t,e,r,o,i){return B(Ht(B(B(t,n),B(r,i)),o),e)}function f(n,t,e,r,o,i,c){return T(t&e|~t&r,n,t,o,i,c)}function d(n,t,e,r,o,i,c){return T(t&r|e&~r,n,t,o,i,c)}function h(n,t,e,r,o,i,c){return T(t^e^r,n,t,o,i,c)}function y(n,t,e,r,o,i,c){return T(e^(t|~r),n,t,o,i,c)}function B(n,t){var e=(65535&n)+(65535&t);return(n>>16)+(t>>16)+(e>>16)<<16|65535&e}function Ht(n,t){return n<<t|n>>>32-t}function Yt(n){return/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(n)}function Wt(n,t="mp"){return n?`https://www.gravatar.com/avatar/${ct(n)}?d=${t}`:""}function zt(n){const t=new RegExp("(?:(?<protocol>[\\w\\d]+)\\:\\/\\/)?(?:(?<user>.+)\\@)?(?<host>(?<domain>[^:\\/\\?#@\\n]+)(?:\\:(?<port>\\d*))?)(?<path>\\/.*?)?(?:\\?(?<query>.*?))?(?:#(?<fragment>.*?))?$","gm").exec(n),e=(t==null?void 0:t.groups)??{},r=e.domain.split(".");if(e.port!=null&&(e.port=Number(e.port)),r.length>2&&(e.domain=r.splice(-2,2).join("."),e.subdomain=r.join(".")),e.query){const o=e.query.split("&"),i={};o.forEach(c=>{const[w,u]=c.split("=");i[w]=u}),e.query=i}return e}function Jt(n){const t=n instanceof Date?n:new Date(n);return new Intl.DateTimeFormat("en-us",{weekday:"long",month:"short",day:"numeric",hour:"numeric",minute:"numeric",hour12:!0}).format(t)}function st(n){return new Promise(t=>setTimeout(t,n))}async function Kt(n,t=100){for(;n();)await st(t)}function Vt(n){return(n instanceof Date?n.getTime():n)-new Date().getTime()}s.ASet=R,s.BadGatewayError=W,s.BadRequestError=M,s.CliBackground=Ot,s.CliEffects=O,s.CliForeground=L,s.CustomError=m,s.ForbiddenError=G,s.GatewayTimeoutError=J,s.Http=K,s.InternalServerError=H,s.JSONAttemptParse=k,s.JSONSanitized=ht,s.LOG_LEVEL=it,s.Logger=V,s.MethodNotAllowedError=v,s.NotAcceptableError=F,s.NotFoundError=q,s.NotImplementedError=Y,s.PaymentRequiredError=j,s.PromiseProgress=b,s.ServiceUnavailableError=z,s.TypedEmitter=P,s.UnauthorizedError=U,s.addUnique=mt,s.arrayDiff=gt,s.caseInsensitiveSort=Et,s.clean=g,s.countChars=Nt,s.createHex=Tt,s.dec2Frac=Ct,s.deepCopy=A,s.deepMerge=tt,s.dotNotation=C,s.download=ot,s.downloadBlob=At,s.errorFromCode=Rt,s.fileBrowser=bt,s.findByProp=pt,s.flattenArr=nt,s.flattenObj=et,s.formData=ft,s.formatBytes=It,s.formatDate=Jt,s.formatPhoneNumber=$t,s.fracToDec=Lt,s.gravatar=Wt,s.includes=$,s.insertAt=kt,s.isEqual=S,s.makeArray=Bt,s.makeUnique=rt,s.matchAll=jt,s.md5=ct,s.mixin=dt,s.pad=Pt,s.randomString=Mt,s.randomStringBuilder=Ut,s.sleep=st,s.sleepUntil=Kt,s.sortByProp=wt,s.timeUntil=Vt,s.uploadWithProgress=St,s.urlEncode=yt,s.urlParser=zt,s.validateEmail=Yt,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(s=typeof globalThis<"u"?globalThis:s||self,m(s.utils={}))})(this,function(s){"use strict";var xt=Object.defineProperty;var _t=(s,m,B)=>m in s?xt(s,m,{enumerable:!0,configurable:!0,writable:!0,value:B}):s[m]=B;var a=(s,m,B)=>(_t(s,typeof m!="symbol"?m+"":m,B),B);function m(n,t=!1){if(n==null)throw new Error("Cannot clean a NULL value");return Array.isArray(n)?n=n.filter(e=>e!=null):Object.entries(n).forEach(([e,r])=>{(t&&r===void 0||!t&&r==null)&&delete n[e]}),n}function B(n){return structuredClone(n)}function et(n,...t){return t.forEach(e=>{for(const r in e)e[r]&&typeof e[r]=="object"&&!Array.isArray(e[r])?(n[r]||(n[r]={}),et(n[r],e[r])):n[r]=e[r]}),n}function A(n,t,e){if(!(n==null||!t))return t.split(/[.[\]]/g).filter(r=>r.length).reduce((r,o,i,c)=>{if((o[0]=='"'||o[0]=="'")&&(o=o.slice(1,-1)),!(r!=null&&r.hasOwnProperty(o))){if(e==null)return;r[o]={}}return e!==void 0&&i==c.length-1?r[o]=e:r[o]},n)}function dt(n){return Object.entries(n).map(([t,e])=>encodeURIComponent(t)+"="+encodeURIComponent(e)).join("&")}function I(n,t,e={}){if(typeof n=="object"&&!Array.isArray(n)){for(const r of Object.keys(n)){const o=t?t+"."+r:r;typeof n[r]=="object"?I(n[r],o,e):e[o]=n[r]}return e}}function ht(n){const t=new FormData;return Object.entries(n).forEach(([e,r])=>t.append(e,r)),t}function M(n,t,e=!1){if(n==null)return e;if(Array.isArray(t))return t.findIndex((o,i)=>!M(n[i],t[i],e))==-1;const r=typeof t;return r!=typeof n?!1:r=="object"?Object.keys(t).find(o=>!M(n[o],t[o],e))==null:r=="function"?n.toString()==t.toString():n==t}function R(n,t){const e=typeof n,r=typeof t;return e!="object"||n==null||r!="object"||t==null?e=="function"&&r=="function"?n.toString()==t.toString():n===t:Object.keys(n).length!=Object.keys(t).length?!1:Object.keys(n).every(i=>R(n[i],t[i]))}function yt(n,t){t.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(r=>{Object.defineProperty(n.prototype,r,Object.getOwnPropertyDescriptor(e.prototype,r)||Object.create(null))})})}function j(n){try{return JSON.parse(n)}catch{return n}}function gt(n,t){let e=[];return JSON.stringify(n,(r,o)=>{if(typeof o=="object"&&o!==null){if(e.includes(o))return;e.push(o)}return o},t)}function mt(n,t){return n.indexOf(t)===-1&&n.push(t),n}function Et(n,t){return rt([...n.filter(e=>!t.includes(r=>R(e,r))),...t.filter(e=>!n.includes(r=>R(e,r)))])}function pt(n){return function(t,e){const r=A(t,n),o=A(e,n);return typeof r!="string"||typeof o!="string"?1:r.toLowerCase().localeCompare(o.toLowerCase())}}function wt(n,t){return e=>R(A(e,n),t)}function nt(n,t=[]){return n.forEach(e=>Array.isArray(e)?nt(e,t):t.push(e)),t}function St(n,t=!1){return function(e,r){const o=A(e,n),i=A(r,n);return typeof o=="number"&&typeof i=="number"?(t?-1:1)*(o-i):o>i?t?-1:1:o<i?t?1:-1:0}}function rt(n){for(let t=n.length-1;t>=0;t--)n.slice(0,t).find(e=>R(e,n[t]))&&n.splice(t,1);return n}function ot(n){return Array.isArray(n)?n:[n]}class O extends Array{get size(){return this.length}constructor(t=[]){super(),t!=null&&t.forEach&&t.forEach(e=>this.add(e))}add(t){this.has(t)||this.push(t)}delete(t){const e=this.indexOf(t);e!=-1&&this.slice(e,1)}difference(t){return new O(this.filter(e=>!t.has(e)))}has(t){return this.indexOf(t)!=-1}intersection(t){return new O(this.filter(e=>t.has(e)))}isDisjointFrom(t){return this.intersection(t).size==0}isSubsetOf(t){return this.findIndex(e=>!t.has(e))==-1}isSuperset(t){return t.findIndex(e=>!this.has(e))==-1}symmetricDifference(t){return new O([...this.difference(t),...t.difference(this)])}union(t){return new O([...this,...t])}}function Bt(n,t=!0){const e=n.reduce((r,o)=>(Object.keys(t?I(o):o).forEach(i=>{r.includes(i)||r.push(i)}),r),[]);return[e.join(","),...n.map(r=>e.map(o=>{const i=A(r,o),c=typeof i;return c=="string"&&i.includes(",")?`"${i}"`:c=="object"?`"${JSON.stringify(i)}"`:i}).join(","))].join(`
2
+ `)}class b extends Promise{constructor(e){super((r,o)=>e(i=>r(i),i=>o(i),i=>this.progress=i));a(this,"listeners",[]);a(this,"_progress",0)}get progress(){return this._progress}set progress(e){e!=this._progress&&(this._progress=e,this.listeners.forEach(r=>r(e)))}static from(e){return e instanceof b?e:new b((r,o)=>e.then((...i)=>r(...i)).catch((...i)=>o(...i)))}from(e){const r=b.from(e);return this.onProgress(o=>r.progress=o),r}onProgress(e){return this.listeners.push(e),this}then(e,r){const o=super.then(e,r);return this.from(o)}catch(e){return this.from(super.catch(e))}finally(e){return this.from(super.finally(e))}}function At(n,t){n instanceof Blob||(n=new Blob(ot(n)));const e=URL.createObjectURL(n);it(e,t),URL.revokeObjectURL(e)}function it(n,t){const e=document.createElement("a");e.href=n,e.download=t||n.split("/").pop(),document.body.appendChild(e),e.click(),document.body.removeChild(e)}function bt(n={}){return new Promise(t=>{const e=document.createElement("input");e.type="file",e.accept=n.accept||"*",e.style.display="none",e.multiple=!!n.multiple,e.onblur=e.onchange=async()=>{t(Array.from(e.files)),e.remove()},document.body.appendChild(e),e.click()})}function Rt(n,t=new Date){(typeof t=="number"||typeof t=="string")&&(t=new Date(t));const e=`${t.getFullYear()}-${(t.getMonth()+1).toString().padStart(2,"0")}-${t.getDate().toString().padStart(2,"0")}_${t.getHours().toString().padStart(2,"0")}-${t.getMinutes().toString().padStart(2,"0")}-${t.getSeconds().toString().padStart(2,"0")}`;return n?n.replace("{{TIMESTAMP}}",e):e}function Ot(n){return new b((t,e,r)=>{const o=new XMLHttpRequest,i=new FormData;n.files.forEach(c=>i.append("file",c)),o.withCredentials=!!n.withCredentials,o.upload.addEventListener("progress",c=>c.lengthComputable?r(c.loaded/c.total):null),o.addEventListener("loadend",()=>t(j(o.responseText))),o.addEventListener("error",()=>e(j(o.responseText))),o.addEventListener("timeout",()=>e({error:"Request timed out"})),o.open("POST",n.url),Object.entries(n.headers||{}).forEach(([c,p])=>o.setRequestHeader(c,p)),o.send(i)})}class U{constructor(){a(this,"listeners",{})}static emit(t,...e){(this.listeners["*"]||[]).forEach(r=>r(t,...e)),(this.listeners[t.toString()]||[]).forEach(r=>r(...e))}static off(t,e){const r=t.toString();this.listeners[r]=(this.listeners[r]||[]).filter(o=>o===e)}static on(t,e){var o;const r=t.toString();return this.listeners[r]||(this.listeners[r]=[]),(o=this.listeners[r])==null||o.push(e),()=>this.off(t,e)}static once(t,e){return new Promise(r=>{const o=this.on(t,(...i)=>{r(i.length==1?i[0]:i),e&&e(...i),o()})})}emit(t,...e){(this.listeners["*"]||[]).forEach(r=>r(t,...e)),(this.listeners[t]||[]).forEach(r=>r(...e))}off(t,e){this.listeners[t]=(this.listeners[t]||[]).filter(r=>r===e)}on(t,e){var r;return this.listeners[t]||(this.listeners[t]=[]),(r=this.listeners[t])==null||r.push(e),()=>this.off(t,e)}once(t,e){return new Promise(r=>{const o=this.on(t,(...i)=>{r(i.length==1?i[0]:i),e&&e(...i),o()})})}}a(U,"listeners",{});class g extends Error{constructor(e,r){super(e);a(this,"_code");r!=null&&(this._code=r)}get code(){return this._code||this.constructor.code}set code(e){this._code=e}static from(e){const r=Number(e.statusCode)??Number(e.code),o=new this(e.message||e.toString());return Object.assign(o,{stack:e.stack,...e,code:r??void 0})}static instanceof(e){return e.constructor.code!=null}toString(){return this.message||super.toString()}}a(g,"code",500);class k extends g{constructor(t="Bad Request"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(k,"code",400);class P extends g{constructor(t="Unauthorized"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(P,"code",401);class G extends g{constructor(t="Payment Required"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(G,"code",402);class F extends g{constructor(t="Forbidden"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(F,"code",403);class q extends g{constructor(t="Not Found"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(q,"code",404);class v extends g{constructor(t="Method Not Allowed"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(v,"code",405);class H extends g{constructor(t="Not Acceptable"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(H,"code",406);class Y extends g{constructor(t="Internal Server Error"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(Y,"code",500);class W extends g{constructor(t="Not Implemented"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(W,"code",501);class z extends g{constructor(t="Bad Gateway"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(z,"code",502);class J extends g{constructor(t="Service Unavailable"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(J,"code",503);class K extends g{constructor(t="Gateway Timeout"){super(t)}static instanceof(t){return t.constructor.code==this.code}}a(K,"code",504);function Ct(n,t){if(n>=200&&n<300)return null;switch(n){case 400:return new k(t);case 401:return new P(t);case 402:return new G(t);case 403:return new F(t);case 404:return new q(t);case 405:return new v(t);case 406:return new H(t);case 500:return new Y(t);case 501:return new W(t);case 502:return new z(t);case 503:return new J(t);case 504:return new K(t);default:return new g(t,n)}}const w=class w{constructor(t={}){a(this,"interceptors",{});a(this,"headers",{});a(this,"url");this.url=t.url??null,this.headers=t.headers||{},t.interceptors&&t.interceptors.forEach(e=>w.addInterceptor(e))}static addInterceptor(t){const e=Object.keys(w.interceptors).length.toString();return w.interceptors[e]=t,()=>{w.interceptors[e]=null}}addInterceptor(t){const e=Object.keys(this.interceptors).length.toString();return this.interceptors[e]=t,()=>{this.interceptors[e]=null}}request(t={}){var o;if(!this.url&&!t.url)throw new Error("URL needs to be set");let e=((o=t.url)!=null&&o.startsWith("http")?t.url:(this.url||"")+(t.url||"")).replace(/([^:]\/)\/+/g,"$1");if(t.fragment&&(e.includes("#")?e.replace(/#.*(\?|\n)/g,(i,c)=>`#${t.fragment}${c}`):e+="#"+t.fragment),t.query){const i=Array.isArray(t.query)?t.query:Object.keys(t.query).map(c=>({key:c,value:t.query[c]}));e+=(e.includes("?")?"&":"?")+i.map(c=>`${c.key}=${c.value}`).join("&")}const r=m({"Content-Type":t.body?t.body instanceof FormData?"multipart/form-data":"application/json":void 0,...w.headers,...this.headers,...t.headers});return typeof t.body=="object"&&t.body!=null&&r["Content-Type"]=="application/json"&&(t.body=JSON.stringify(t.body)),new b((i,c,p)=>{fetch(e,{headers:r,method:t.method||(t.body?"POST":"GET"),body:t.body}).then(async u=>{var lt,ft;for(let l of[...Object.values(w.interceptors),...Object.values(this.interceptors)])await new Promise(D=>l(u,()=>D()));const T=u.headers.get("Content-Length"),_=T?parseInt(T,10):0;let ut=0;const tt=(lt=u.body)==null?void 0:lt.getReader(),Xt=new ReadableStream({start(l){function D(){tt==null||tt.read().then(N=>{if(N.done)return l.close();ut+=N.value.byteLength,p(ut/_),l.enqueue(N.value),D()}).catch(N=>l.error(N))}D()}});if(u.data=new Response(Xt),t.decode==null||t.decode){const l=(ft=u.headers.get("Content-Type"))==null?void 0:ft.toLowerCase();l!=null&&l.includes("form")?u.data=await u.data.formData():l!=null&&l.includes("json")?u.data=await u.data.json():l!=null&&l.includes("text")?u.data=await u.data.text():l!=null&&l.includes("application")&&(u.data=await u.data.blob())}u.ok?i(u):c(u)})})}};a(w,"interceptors",{}),a(w,"headers",{});let V=w;const C={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},L={BLACK:"\x1B[30m",RED:"\x1B[31m",GREEN:"\x1B[32m",YELLOW:"\x1B[33m",BLUE:"\x1B[34m",MAGENTA:"\x1B[35m",CYAN:"\x1B[36m",LIGHT_GREY:"\x1B[37m",GREY:"\x1B[90m",LIGHT_RED:"\x1B[91m",LIGHT_GREEN:"\x1B[92m",LIGHT_YELLOW:"\x1B[93m",LIGHT_BLUE:"\x1B[94m",LIGHT_MAGENTA:"\x1B[95m",LIGHT_CYAN:"\x1B[96m",WHITE:"\x1B[97m"},Lt={BLACK:"\x1B[40m",RED:"\x1B[41m",GREEN:"\x1B[42m",YELLOW:"\x1B[43m",BLUE:"\x1B[44m",MAGENTA:"\x1B[45m",CYAN:"\x1B[46m",WHITE:"\x1B[47m",GREY:"\x1B[100m"};var ct=(n=>(n[n.ERROR=0]="ERROR",n[n.WARN=1]="WARN",n[n.INFO=2]="INFO",n[n.LOG=3]="LOG",n[n.DEBUG=4]="DEBUG",n))(ct||{});const E=class E extends U{constructor(t){super(),this.namespace=t}pad(t,e,r,o=!1){const i=t.toString(),c=e-i.length;if(c<=0)return i;const p=Array(~~(c/r.length)).fill(r).join("");return o?i+p:p+i}format(...t){const e=new Date;return`${`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()} ${this.pad(e.getHours().toString(),2,"0")}:${this.pad(e.getMinutes().toString(),2,"0")}:${this.pad(e.getSeconds().toString(),2,"0")}.${this.pad(e.getMilliseconds().toString(),3,"0",!0)}`}${this.namespace?` [${this.namespace}]`:""} ${t.join(" ")}`}debug(...t){if(E.LOG_LEVEL<4)return;const e=this.format(...t);E.emit(4,e),console.debug(L.LIGHT_GREY+e+C.CLEAR)}log(...t){if(E.LOG_LEVEL<3)return;const e=this.format(...t);E.emit(3,e),console.log(C.CLEAR+e)}info(...t){if(E.LOG_LEVEL<2)return;const e=this.format(...t);E.emit(2,e),console.info(L.BLUE+e+C.CLEAR)}warn(...t){if(E.LOG_LEVEL<1)return;const e=this.format(...t);E.emit(1,e),console.warn(L.YELLOW+e+C.CLEAR)}error(...t){if(E.LOG_LEVEL<0)return;const e=this.format(...t);E.emit(0,e),console.error(L.RED+e+C.CLEAR)}};a(E,"LOG_LEVEL",4);let Z=E;function Nt(n){const t=(p,u)=>u<1e-7?p:t(u,~~(p%u)),e=n.toString().length-2;let r=Math.pow(10,e),o=n*r;const i=t(o,r);o=~~(o/i),r=~~(r/i);const c=~~(o/r);return o-=c*r,`${c?c+" ":""}${~~o}/${~~r}`}function $t(n){let t=n.split(" ");const e=t.length==2?Number(t[0]):0;return t=t.pop().split("/"),e+Number(t[0])/Number(t[1])}const Q="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",X="0123456789",x="~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",Tt=Q+X+x;function Dt(n,t=2){if(n===0)return"0 Bytes";const e=1024,r=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],o=Math.floor(Math.log(n)/Math.log(e));return parseFloat((n/Math.pow(e,o)).toFixed(t))+" "+r[o]}function It(n){const t=/(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(n);if(!t)throw new Error(`Number cannot be parsed: ${n}`);return`${t[1]??""} (${t[2]}) ${t[3]}-${t[4]}`.trim()}function Mt(n,t,e){return`${n.slice(0,e)}${t}${n.slice(e+1)}`}function jt(n,t,e=" ",r=!0){return r?n.toString().padStart(t,e):n.toString().padEnd(t,e)}function Ut(n){return Array(n).fill(null).map(()=>Math.round(Math.random()*15).toString(16)).join("")}function kt(n,t=Tt){return Array(n).fill(null).map(()=>{const e=~~(Math.random()*t.length);return t[e]}).join("")}function Pt(n,t=!1,e=!1,r=!1){if(!t&&!e&&!r)throw new Error("Must enable at least one: letters, numbers, symbols");return Array(n).fill(null).map(()=>{let o;do{const i=~~(Math.random()*3);t&&i==0?o=Q[~~(Math.random()*Q.length)]:e&&i==1?o=X[~~(Math.random()*X.length)]:r&&i==2&&(o=x[~~(Math.random()*x.length)])}while(!o);return o}).join("")}function Gt(n,t){if(typeof t=="string"&&(t=new RegExp(t,"g")),!t.global)throw new TypeError("Regular expression must be global.");let e=[],r;for(;(r=t.exec(n))!==null;)e.push(r);return e}function Ft(n){const t=new RegExp("(?:(?<protocol>[\\w\\d]+)\\:\\/\\/)?(?:(?<user>.+)\\@)?(?<host>(?<domain>[^:\\/\\?#@\\n]+)(?:\\:(?<port>\\d*))?)(?<path>\\/.*?)?(?:\\?(?<query>.*?))?(?:#(?<fragment>.*?))?$","gm").exec(n),e=(t==null?void 0:t.groups)??{},r=e.domain.split(".");if(e.port!=null&&(e.port=Number(e.port)),r.length>2&&(e.domain=r.splice(-2,2).join("."),e.subdomain=r.join(".")),e.query){const o=e.query.split("&"),i={};o.forEach(c=>{const[p,u]=c.split("=");i[p]=u}),e.query=i}return e}function st(n){var t=qt(Ht(Yt(vt(n),8*n.length)));return t.toLowerCase()}function qt(n){for(var t,e="0123456789ABCDEF",r="",o=0;o<n.length;o++)t=n.charCodeAt(o),r+=e.charAt(t>>>4&15)+e.charAt(15&t);return r}function vt(n){for(var t=Array(n.length>>2),e=0;e<t.length;e++)t[e]=0;for(e=0;e<8*n.length;e+=8)t[e>>5]|=(255&n.charCodeAt(e/8))<<e%32;return t}function Ht(n){for(var t="",e=0;e<32*n.length;e+=8)t+=String.fromCharCode(n[e>>5]>>>e%32&255);return t}function Yt(n,t){n[t>>5]|=128<<t%32,n[14+(t+64>>>9<<4)]=t;for(var e=1732584193,r=-271733879,o=-1732584194,i=271733878,c=0;c<n.length;c+=16){var p=e,u=r,T=o,_=i;r=y(r=y(r=y(r=y(r=h(r=h(r=h(r=h(r=d(r=d(r=d(r=d(r=f(r=f(r=f(r=f(r,o=f(o,i=f(i,e=f(e,r,o,i,n[c+0],7,-680876936),r,o,n[c+1],12,-389564586),e,r,n[c+2],17,606105819),i,e,n[c+3],22,-1044525330),o=f(o,i=f(i,e=f(e,r,o,i,n[c+4],7,-176418897),r,o,n[c+5],12,1200080426),e,r,n[c+6],17,-1473231341),i,e,n[c+7],22,-45705983),o=f(o,i=f(i,e=f(e,r,o,i,n[c+8],7,1770035416),r,o,n[c+9],12,-1958414417),e,r,n[c+10],17,-42063),i,e,n[c+11],22,-1990404162),o=f(o,i=f(i,e=f(e,r,o,i,n[c+12],7,1804603682),r,o,n[c+13],12,-40341101),e,r,n[c+14],17,-1502002290),i,e,n[c+15],22,1236535329),o=d(o,i=d(i,e=d(e,r,o,i,n[c+1],5,-165796510),r,o,n[c+6],9,-1069501632),e,r,n[c+11],14,643717713),i,e,n[c+0],20,-373897302),o=d(o,i=d(i,e=d(e,r,o,i,n[c+5],5,-701558691),r,o,n[c+10],9,38016083),e,r,n[c+15],14,-660478335),i,e,n[c+4],20,-405537848),o=d(o,i=d(i,e=d(e,r,o,i,n[c+9],5,568446438),r,o,n[c+14],9,-1019803690),e,r,n[c+3],14,-187363961),i,e,n[c+8],20,1163531501),o=d(o,i=d(i,e=d(e,r,o,i,n[c+13],5,-1444681467),r,o,n[c+2],9,-51403784),e,r,n[c+7],14,1735328473),i,e,n[c+12],20,-1926607734),o=h(o,i=h(i,e=h(e,r,o,i,n[c+5],4,-378558),r,o,n[c+8],11,-2022574463),e,r,n[c+11],16,1839030562),i,e,n[c+14],23,-35309556),o=h(o,i=h(i,e=h(e,r,o,i,n[c+1],4,-1530992060),r,o,n[c+4],11,1272893353),e,r,n[c+7],16,-155497632),i,e,n[c+10],23,-1094730640),o=h(o,i=h(i,e=h(e,r,o,i,n[c+13],4,681279174),r,o,n[c+0],11,-358537222),e,r,n[c+3],16,-722521979),i,e,n[c+6],23,76029189),o=h(o,i=h(i,e=h(e,r,o,i,n[c+9],4,-640364487),r,o,n[c+12],11,-421815835),e,r,n[c+15],16,530742520),i,e,n[c+2],23,-995338651),o=y(o,i=y(i,e=y(e,r,o,i,n[c+0],6,-198630844),r,o,n[c+7],10,1126891415),e,r,n[c+14],15,-1416354905),i,e,n[c+5],21,-57434055),o=y(o,i=y(i,e=y(e,r,o,i,n[c+12],6,1700485571),r,o,n[c+3],10,-1894986606),e,r,n[c+10],15,-1051523),i,e,n[c+1],21,-2054922799),o=y(o,i=y(i,e=y(e,r,o,i,n[c+8],6,1873313359),r,o,n[c+15],10,-30611744),e,r,n[c+6],15,-1560198380),i,e,n[c+13],21,1309151649),o=y(o,i=y(i,e=y(e,r,o,i,n[c+4],6,-145523070),r,o,n[c+11],10,-1120210379),e,r,n[c+2],15,718787259),i,e,n[c+9],21,-343485551),e=S(e,p),r=S(r,u),o=S(o,T),i=S(i,_)}return Array(e,r,o,i)}function $(n,t,e,r,o,i){return S(Wt(S(S(t,n),S(r,i)),o),e)}function f(n,t,e,r,o,i,c){return $(t&e|~t&r,n,t,o,i,c)}function d(n,t,e,r,o,i,c){return $(t&r|e&~r,n,t,o,i,c)}function h(n,t,e,r,o,i,c){return $(t^e^r,n,t,o,i,c)}function y(n,t,e,r,o,i,c){return $(e^(t|~r),n,t,o,i,c)}function S(n,t){var e=(65535&n)+(65535&t);return(n>>16)+(t>>16)+(e>>16)<<16|65535&e}function Wt(n,t){return n<<t|n>>>32-t}function zt(n){return/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(n)}function Jt(n,t="mp"){return n?`https://www.gravatar.com/avatar/${st(n)}?d=${t}`:""}function Kt(n){(typeof n=="number"||typeof n=="string")&&(n=new Date(n));let t=n.getHours(),e="AM";return t>=12?(t>12&&(t-=12),e="PM"):t==0&&(t=12),`${n.getFullYear()}-${(n.getMonth()+1).toString().padStart(2,"0")}-${n.getDate().toString().padStart(2,"0")}, ${t}:${n.getMinutes().toString().padStart(2,"0")} ${e}`}function at(n){return new Promise(t=>setTimeout(t,n))}async function Vt(n,t=100){for(;n();)await at(t)}function Zt(n){return(n instanceof Date?n.getTime():n)-new Date().getTime()}function Qt(){return Object.keys({})}s.ASet=O,s.BadGatewayError=z,s.BadRequestError=k,s.CliBackground=Lt,s.CliEffects=C,s.CliForeground=L,s.CustomError=g,s.ForbiddenError=F,s.GatewayTimeoutError=K,s.Http=V,s.InternalServerError=Y,s.JSONAttemptParse=j,s.JSONSanitize=gt,s.LOG_LEVEL=ct,s.Logger=Z,s.MethodNotAllowedError=v,s.NotAcceptableError=H,s.NotFoundError=q,s.NotImplementedError=W,s.PaymentRequiredError=G,s.PromiseProgress=b,s.ServiceUnavailableError=J,s.TypedEmitter=U,s.UnauthorizedError=P,s.addUnique=mt,s.arrayDiff=Et,s.caseInsensitiveSort=pt,s.clean=m,s.csv=Bt,s.dec2Frac=Nt,s.deepCopy=B,s.deepMerge=et,s.dotNotation=A,s.downloadFile=At,s.downloadUrl=it,s.encodeQuery=dt,s.errorFromCode=Ct,s.fileBrowser=bt,s.findByProp=wt,s.flattenArr=nt,s.flattenObj=I,s.formData=ht,s.formatBytes=Dt,s.formatDate=Kt,s.formatPhoneNumber=It,s.fracToDec=$t,s.gravatar=Jt,s.includes=M,s.insertAt=Mt,s.isEqual=R,s.makeArray=ot,s.makeUnique=rt,s.matchAll=Gt,s.md5=st,s.mixin=yt,s.pad=jt,s.parseUrl=Ft,s.randomHex=Ut,s.randomString=kt,s.randomStringBuilder=Pt,s.sleep=at,s.sleepUntil=Vt,s.sortByProp=St,s.timeUntil=Zt,s.timestampFilename=Rt,s.tyoeKeys=Qt,s.uploadWithProgress=Ot,s.validateEmail=zt,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
2
3
  //# sourceMappingURL=index.cjs.map