(function(i,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(i=typeof globalThis<"u"?globalThis:i||self,f(i.momentum={}))})(this,function(i){"use strict";var Et=Object.defineProperty;var yt=(i,f,m)=>f in i?Et(i,f,{enumerable:!0,configurable:!0,writable:!0,value:m}):i[f]=m;var d=(i,f,m)=>(yt(i,typeof f!="symbol"?f+"":f,m),m);function f(t,n=!1){if(t==null)throw new Error("Cannot clean a NULL value");return Array.isArray(t)?t=t.filter(e=>e!=null):Object.entries(t).forEach(([e,r])=>{(r===void 0||n||r===null)&&delete t[e]}),t}function m(t){return JSON.parse(JSON.stringify(t))}function C(t,n,e){if(!(t==null||!n))return n.split(/[.[\]]/g).filter(r=>r.length).reduce((r,o,c,s)=>{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&&c==s.length-1?r[o]=e:r[o]},t)}function R(t,n,e=!1){if(t==null)return e;if(Array.isArray(n))return n.findIndex((o,c)=>!R(t[c],n[c],e))==-1;const r=typeof n;return r!=typeof t?!1:r=="object"?Object.keys(n).find(o=>!R(t[o],n[o],e))==null:r=="function"?t.toString()==n.toString():t==n}function w(t,n){const e=typeof t,r=typeof n;return e!="object"||t==null||r!="object"||n==null?e=="function"&&r=="function"?t.toString()==n.toString():t===n:Object.keys(t).length!=Object.keys(n).length?!1:Object.keys(t).every(c=>w(t[c],n[c]))}function q(t,n){return t.indexOf(n)===-1&&t.push(n),t}function P(t,n){return k([...t.filter(e=>!n.includes(r=>w(e,r))),...n.filter(e=>!t.includes(r=>w(e,r)))])}function Y(t){return function(n,e){const r=C(n,t),o=C(e,t);return typeof r!="string"||typeof o!="string"?1:r.toLowerCase().localeCompare(o.toLowerCase())}}function j(t,n=[]){return t.forEach(e=>Array.isArray(e)?j(e,n):n.push(e)),n}function G(t,n=!1){return function(e,r){const o=C(e,t),c=C(r,t);return typeof o=="number"&&typeof c=="number"?(n?-1:1)*(o-c):o>c?n?-1:1:ow(e[t],n)}function k(t){for(let n=t.length-1;n>=0;n--)t.slice(0,n).find(e=>w(e,t[n]))&&t.splice(n,1);return t}function x(t){return Array.isArray(t)?t:[t]}class H{constructor(){d(this,"listeners",{})}emit(n){Object.values(this.listeners).forEach(e=>e(n))}listen(n,e){const r=e||n,o=typeof n=="string"?n:`_${Object.keys(this.listeners).length.toString()}`;return this.listeners[o]=r,()=>delete this.listeners[o]}once(n){const e=this.listen(r=>{n(r),e()})}}const g=class g{constructor(n,e={}){d(this,"interceptors",{});this.baseUrl=n,this.headers=e}static addInterceptor(n,e){const r=e||n,o=typeof n=="string"?n:`_${Object.keys(g.interceptors).length.toString()}`;return g.interceptors[o]=r,()=>delete g.interceptors[o]}addInterceptor(n,e){const r=e||n,o=typeof n=="string"?n:`_${Object.keys(this.interceptors).length.toString()}`;return this.interceptors[o]=r,()=>delete this.interceptors[o]}getInterceptors(){return[...Object.values(g.interceptors),...Object.values(this.interceptors)]}fetch(n,e,r={}){const o={"Content-Type":e&&!(e instanceof FormData)?"application/json":void 0,...g.headers,...this.headers,...r.headers};return Object.keys(o).forEach(c=>{o[c]||delete o[c]}),fetch(`${this.baseUrl}${n||""}`.replace(/([^:]\/)\/+/g,"$1"),{headers:o,method:r.method||(e?"POST":"GET"),body:o["Content-Type"].startsWith("application/json")&&e?JSON.stringify(e):e}).then(async c=>{for(let s of this.getInterceptors())await new Promise(S=>s(c,()=>S(null)));return c.headers["Content-Type"]&&c.headers.get("Content-Type").startsWith("application/json")?await c.json():c.headers["Content-Type"]&&c.headers.get("Content-Type").startsWith("text/plain")?await c.text():c})}delete(n,e){return this.fetch(n,null,{method:"delete",...e})}get(n,e){return this.fetch(n,null,{method:"get",...e})}patch(n,e,r){return this.fetch(e,n,{method:"patch",...r})}post(n,e,r){return this.fetch(e,n,{method:"post",...r})}put(n,e,r){return this.fetch(e,n,{method:"put",...r})}new(n,e){const r=new g(`${this.baseUrl}${n}`,{...this.headers,...e});return Object.entries(this.interceptors).map(([o,c])=>r.addInterceptor(o,c)),r}};d(g,"interceptors",{}),d(g,"headers",{});let T=g;T.addInterceptor((t,n)=>{if(t.status==200)return n();throw t.status==400?new I(t.statusText):t.status==401?new N(t.statusText):t.status==403?new $(t.statusText):t.status==404?new v(t.statusText):t.status==500?new O(t.statusText):new E(t.statusText,t.status)});class E extends Error{constructor(e,r){super(e);d(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()}}d(E,"code",500);class I extends E{constructor(n="Bad Request"){super(n)}static instanceof(n){return n.constructor.code==this.code}}d(I,"code",400);class N extends E{constructor(n="Unauthorized"){super(n)}static instanceof(n){return n.constructor.code==this.code}}d(N,"code",401);class $ extends E{constructor(n="Forbidden"){super(n)}static instanceof(n){return n.constructor.code==this.code}}d($,"code",403);class v extends E{constructor(n="Not Found"){super(n)}static instanceof(n){return n.constructor.code==this.code}}d(v,"code",404);class O extends E{constructor(n="Internal Server Error"){super(n)}static instanceof(n){return n.constructor.code==this.code}}d(O,"code",500);const A={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},B={BLACK:"\x1B[30m",RED:"\x1B[31m",GREEN:"\x1B[32m",YELLOW:"\x1B[33m",BLUE:"\x1B[34m",MAGENTA:"\x1B[35m",CYAN:"\x1B[36m",WHITE:"\x1B[37m",GREY:"\x1B[90m"},V={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"};class z{constructor(n){this.namespace=n}format(...n){return`${new Date().toISOString()} [${this.namespace}] ${n.join(" ")}`}debug(...n){console.log(B.MAGENTA+this.format(...n)+A.CLEAR)}error(...n){console.log(B.RED+this.format(...n)+A.CLEAR)}info(...n){console.log(B.CYAN+this.format(...n)+A.CLEAR)}log(...n){console.log(A.CLEAR+this.format(...n))}warn(...n){console.log(B.YELLOW+this.format(...n)+A.CLEAR)}verbose(...n){console.log(B.WHITE+this.format(...n)+A.CLEAR)}}function F(t,n){return t.length-t.replaceAll(n,"").length}function J(t){return Array(t).fill(null).map(()=>Math.round(Math.random()*15).toString(16)).join("")}const b="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",D="0123456789",U="~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",K=b+D+U;function Z(t){const n=/(\+?1)?.*?(\d{3}).*?(\d{3}).*?(\d{4})/g.exec(t);if(!n)throw new Error(`Number cannot be parsed: ${t}`);return`${n[1]??""} (${n[2]}) ${n[3]}-${n[4]}`.trim()}function Q(t,n,e){return`${t.slice(0,e)}${n}${t.slice(e+1)}`}function X(t,n=K){return Array(t).fill(null).map(()=>{const e=~~(Math.random()*n.length);return n[e]}).join("")}function _(t,n=!1,e=!1,r=!1){if(!n&&!e&&!r)throw new Error("Must enable at least one: letters, numbers, symbols");return Array(t).fill(null).map(()=>{let o;do{const c=~~(Math.random()*3);n&&c==0?o=b[~~(Math.random()*b.length)]:e&&c==1?o=D[~~(Math.random()*D.length)]:r&&c==2&&(o=U[~~(Math.random()*U.length)])}while(!o);return o}).join("")}function tt(t,n){if(typeof n=="string"&&(n=new RegExp(n,"g")),!n.global)throw new TypeError("Regular expression must be global.");let e=[],r;for(;(r=n.exec(t))!==null;)e.push(r);return e}function M(t){var n=et(rt(ot(nt(t),8*t.length)));return n.toLowerCase()}function et(t){for(var n,e="0123456789ABCDEF",r="",o=0;o>>4&15)+e.charAt(15&n);return r}function nt(t){for(var n=Array(t.length>>2),e=0;e>5]|=(255&t.charCodeAt(e/8))<>5]>>>e%32&255);return n}function ot(t,n){t[n>>5]|=128<>>9<<4)]=n;for(var e=1732584193,r=-271733879,o=-1732584194,c=271733878,s=0;s>16)+(n>>16)+(e>>16)<<16|65535&e}function ct(t,n){return t<>>32-n}function st(t){return/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(t)}function it(t){return Object.entries(t).map(([n,e])=>encodeURIComponent(n)+"="+encodeURIComponent(e)).join("&")}function ut(t){return t?`https://www.gravatar.com/avatar/${M(t)}`:""}function at(t){const n=new RegExp("(?:(?[\\w\\d]+)\\:\\/\\/)?(?:(?.+)\\@)?(?(?[^:\\/\\?#@\\n]+)(?:\\:(?\\d*))?)(?\\/.*?)?(?:\\?(?.*?))?(?:#(?.*?))?$","gm").exec(t),e=(n==null?void 0:n.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("&"),c={};o.forEach(s=>{const[L,S]=s.split("=");c[L]=S}),e.query=c}return e}function lt(t){return(t instanceof Date?t.getTime():t)-new Date().getTime()}function ht(t){return new Promise(n=>setTimeout(n,t))}function ft(t){const n=t instanceof Date?t:new Date(t);return new Intl.DateTimeFormat("en-us",{weekday:"long",month:"short",day:"numeric",hour:"numeric",minute:"numeric",hour12:!0}).format(n)}i.BadRequestError=I,i.CliBackground=V,i.CliEffects=A,i.CliForeground=B,i.CustomError=E,i.Emitter=H,i.ForbiddenError=$,i.InternalServerError=O,i.Logger=z,i.NotFoundError=v,i.UnauthorizedError=N,i.XHR=T,i.addUnique=q,i.arrayDiff=P,i.caseInsensitiveSort=Y,i.clean=f,i.countChars=F,i.createHex=J,i.deepCopy=m,i.dotNotation=C,i.findByProp=W,i.flattenArr=j,i.formEncode=it,i.formatDate=ft,i.formatPhoneNumber=Z,i.gravatar=ut,i.includes=R,i.insertAt=Q,i.isEqual=w,i.makeArray=x,i.makeUnique=k,i.matchAll=tt,i.md5=M,i.randomString=X,i.randomStringBuilder=_,i.sleep=ht,i.sortByProp=G,i.timeUntil=lt,i.urlParser=at,i.validateEmail=st,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});