@flemist/simple-utils 2.1.3 → 2.1.4
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/build/browser/index.cjs +1 -1
- package/build/browser/index.mjs +148 -115
- package/build/common/index.cjs +1 -1
- package/build/common/index.mjs +148 -115
- package/build/common/string/format/index.d.ts +1 -0
- package/build/common/test/match/index.d.ts +6 -2
- package/build/common/test/match/matchers/index.d.ts +17 -0
- package/build/node/index.cjs +7 -7
- package/build/node/index.mjs +510 -477
- package/build/urlGet-CerQ1cKh.js +17 -0
- package/build/{urlGet-BCW9jvAm.mjs → urlGet-DZEwtNXt.mjs} +614 -561
- package/package.json +1 -1
- package/build/urlGet-BOGFUahf.js +0 -17
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";const ct=require("@flemist/abort-controller-fast"),U=require("@flemist/async-utils"),zt=require("@flemist/time-controller");let st=null;function Ue(){if(!st){st=new Array(256);for(let t=0;t<256;t++)st[t]=t.toString(16).padStart(2,"0")}return st}function qt(t){const e=Ue(),r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let n="";for(let s=0,i=r.length;s<i;s++)n+=e[r[s]];return n}let _t=null,Wt=null,it=null,Gt=null;function je(){_t||(_t=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Wt=new Uint32Array(64),Gt=new TextEncoder,it=new Uint8Array(65536))}function Ht(t){if(t==null)return null;je();const e=_t,r=Wt,n=Gt;let s=it,i;if(typeof t=="string"){const g=t.length*3;s.length<g+128&&(s=it=new Uint8Array(g+128));const p=n.encodeInto(t,s);i=s.subarray(0,p.written)}else if(t instanceof Uint8Array)i=t;else if(ArrayBuffer.isView(t))i=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);else throw new Error(`[sha256Buffer] Unsupported content type: ${typeof t}`);const u=i.length,o=u+72>>>6<<6;s.length<o&&(s=it=new Uint8Array(o)),i!==s&&s.set(i),s[u]=128;for(let g=u+1;g<o;g++)s[g]=0;const a=u*8,c=a/4294967296|0,f=a|0;s[o-8]=c>>>24,s[o-7]=c>>>16,s[o-6]=c>>>8,s[o-5]=c,s[o-4]=f>>>24,s[o-3]=f>>>16,s[o-2]=f>>>8,s[o-1]=f;let b=1779033703,y=-1150833019,h=1013904242,l=-1521486534,m=1359893119,O=-1694144372,_=528734635,S=1541459225;for(let g=0;g<o;g+=64){for(let w=0;w<16;w++){const x=g+(w<<2);r[w]=s[x]<<24|s[x+1]<<16|s[x+2]<<8|s[x+3]}for(let w=16;w<64;w++){const x=r[w-15],N=r[w-2],gt=(x>>>7|x<<25)^(x>>>18|x<<14)^x>>>3,nt=(N>>>17|N<<15)^(N>>>19|N<<13)^N>>>10;r[w]=r[w-16]+gt+r[w-7]+nt|0}let p=b,A=y,et=h,pt=l,T=m,rt=O,B=_,yt=S;for(let w=0;w<64;w+=4)for(let x=0;x<4;x++){const N=w+x,gt=(T>>>6|T<<26)^(T>>>11|T<<21)^(T>>>25|T<<7),nt=yt+gt+(B^T&(rt^B))+e[N]+r[N]|0,De=((p>>>2|p<<30)^(p>>>13|p<<19)^(p>>>22|p<<10))+(p&A^et&(p^A))|0;yt=B,B=rt,rt=T,T=pt+nt|0,pt=et,et=A,A=p,p=nt+De|0}b=b+p|0,y=y+A|0,h=h+et|0,l=l+pt|0,m=m+T|0,O=O+rt|0,_=_+B|0,S=S+yt|0}const E=new Uint8Array(32),F=[b,y,h,l,m,O,_,S];for(let g=0;g<8;g++){const p=F[g],A=g<<2;E[A]=p>>>24,E[A+1]=p>>>16&255,E[A+2]=p>>>8&255,E[A+3]=p&255}return E}function Pe(t){const e=Ht(t);return e?qt(e):null}function Jt(t,e){return t==null?e:e==null?t:Math.min(t,e)}function Xt(t,e){return t==null?e:e==null?t:Math.max(t,e)}function Le(t,e,r){return Xt(Jt(t,e),r)}function Ke(t,e){return(t%e+e)%e}function Fe(t){return function(){let r=t+=1831565813;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),(r^r>>>14)/4294967296+.5}}function ve(){return Math.random()}function Ve(){return Math.random()*2**32>>>0}function Yt(t){return t!=null?Fe(t):ve}class lt{_seed;_rnd;constructor(e){this._seed=e,this._rnd=Yt(e)}get seed(){return this._seed}nextSeed(){return this.next()*2**32>>>0}nextRandom(){return new lt(this.nextSeed())}next(){return this._rnd()}clone(){return new lt(this._seed)}}function St(t,e,r){if(r==null&&(r=e,e=0),r<=e)throw new Error(`[random][randomFloat] toExclusive (${r}) must be greater than from (${e})`);return t.next()*(r-e)+e}function Qt(t,e,r){return Math.floor(St(t,e,r))}function Be(t,e){return t.next()<(e??.5)}function ze(t,e,r){if(Array.isArray(e)){const i=e;e=i.length,r=u=>i[u]}if(!r)throw new Error("[random][randomIndexWeighted] getWeight is required");let n=0;for(let i=0;i<e;i++)n+=r(i);if(n===0)return-1;let s=St(t,n);for(let i=0;i<e;i++)if(s-=r(i),s<0)return i;return e-1}function Et(t,e){if(e.length===0)throw new Error("[random][randomItem] items is empty");const r=Qt(t,e.length);return e[r]}function qe(t,e,r){if(e.length===0)throw new Error("[random][randomItems] items is empty");const n=[];for(let s=0;s<r;s++)n.push(Et(t,e));return n}function We(t,e,r){let n=Object.values(e);return r&&(n=n.filter(r)),Et(t,n)}const Zt=1073741789,ot=(Zt>>2)-1;function Ge(t=ot,e){if(t<=0)throw new Error(`[random][PseudoRandom] count(${t}) must be > 0`);if(t>ot)throw new Error(`[random][PseudoRandom] count(${t}) must be <= ${ot}`);if(e==null&&(e=Math.floor(Math.random()*t)),e>=t)throw new Error(`[random][PseudoRandom] startFrom(${e}) must be < count(${t})`);let r=e;return function(){return r=(r+Zt)%t,r}}let z=null;function He(){const t=Date.now();return z==null||t>z?(z=t,t):(z++,z)}async function Je({url:t,timeout:e}={}){t||(t=typeof window<"u"?"/":"https://google.com");let r;try{const n=new ct.AbortControllerFast;r=e?setTimeout(()=>{n.abort()},e):null;const s=await fetch(t,{method:"HEAD",signal:ct.toAbortSignal(n.signal)}),i=s.headers.get("date");if(!i)throw new Error(`[Now][getDateInet] No date header in response: ${s.status} ${t}`);return new Date(i).getTime()}finally{r&&clearTimeout(r)}}function $t(t,e,r){const n=e==null?t:new Date(t.toLocaleString("en-US",{timeZone:e})),s=r==null?t:new Date(t.toLocaleString("en-US",{timeZone:r}));return new Date(t.getTime()+s.getTime()-n.getTime())}function te(t,e){t=$t(t,"UTC",e);const r=t.getUTCFullYear().toString().padStart(4,"0"),n=(t.getUTCMonth()+1).toString().padStart(2,"0"),s=t.getUTCDate().toString().padStart(2,"0"),i=t.getUTCHours().toString().padStart(2,"0"),u=t.getUTCMinutes().toString().padStart(2,"0"),o=t.getUTCSeconds().toString().padStart(2,"0");return`${r}-${n}-${s} ${i}:${u}:${o}`}let Xe=0;const bt=new WeakMap;function L(t){if(bt.has(t))return bt.get(t);const e=Xe++;return bt.set(t,e),e}function q(t,e,r){if(t==null)return null;if(e==null||t.length<=e)return t;const n=r?.appendEllipsis?"…":"",s=n.length+(r?.appendTruncatedLength?String(t.length).length+2:0),i=Math.max(0,e-s),u=r?.appendTruncatedLength?`(${t.length-i})`:"";return i<=0?u+n:r?.fromStart?u+n+t.slice(t.length-i):t.slice(0,i)+n+u}function Ft(t,e){try{return t[e]}catch(r){return"Error: "+(r instanceof Error?r.message:String(r))}}function k(t,e,r,n){const{pretty:s,filter:i,maxDepth:u,maxItems:o,maxStringLength:a,showObjectId:c,showArrayIndex:f,customToString:b}=e??{};if(r==null&&(r=[]),n==null&&(n=new Set),b){const h=b(t,r,l=>k(l,e,r,n));if(h!=null)return q(h,a,e?.truncateOptions)}const y=r.length;if(typeof t=="string")return t=q(t,a,e?.truncateOptions),n.size>0&&(t=JSON.stringify(t)),t;if(t==null||typeof t!="object")return String(t);if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return`${t.constructor?.name??""}#${L(t)}[${t.byteLength}]`;if(t instanceof RegExp)return q(String(t),a,e?.truncateOptions);if(t instanceof Date)return te(t);if(t instanceof Object){if(n.has(t)||u!=null&&y>=u)return`${t.constructor===Object?"":t.constructor?.name??""}#${L(t)}`;n.add(t)}if(t instanceof Error)return q(t.stack||t.message||String(t),a,e?.truncateOptions);if(Array.isArray(t)){const h=s?" ".repeat(y):"";let l="";c&&(l+=`#${L(t)} `),l+="[";let m=0,O=!1;for(let _=0;_<t.length;_++){if(o!=null&&m>=o){O=!0;break}const S=[...r,String(_)],E=Ft(t,_);if(i!=null&&!i(S,E))continue;const F=k(E,e,S,n);m>0&&(l+=","),s&&(l+=`
|
|
2
|
+
`),s&&(l+=`${h} `),f&&(l+=`${_}: `),l+=`${F}`,m++}return O?(m>0&&(l+=","),s?(l+=`
|
|
3
|
+
`,l+=`${h} ...
|
|
4
|
+
`):l+="...",l+=h,l+="]"):(m>0&&s&&(l+=`
|
|
5
|
+
${h}`),l+="]"),l}if(t instanceof Map){let h="";return c&&(h+=`#${L(t)} `),h+="Map",h+=k(Array.from(t.entries()),e,r,n),h}if(t instanceof Set){let h="";return c&&(h+=`#${L(t)} `),h+="Set",h+=k(Array.from(t.values()),e,r,n),h}{const h=t.constructor===Object?"":t.constructor?.name??"",l=s?" ".repeat(y):"";let m=h?`${h} `:"";c&&(m+=`#${L(t)} `),m+="{";let O=0,_=!1;for(const S in t){if(o!=null&&O>=o){_=!0;break}const E=[...r,S],F=Ft(t,S);if(i!=null&&!i(E,F))continue;const g=k(F,e,E,n);O>0&&(m+=","),s&&(m+=`
|
|
6
|
+
`),s&&(m+=`${l} `),m+=`${S}: ${g}`,O++}return _&&(O>0&&(m+=","),s?(m+=`
|
|
7
|
+
`,m+=`${l} ...
|
|
8
|
+
`):m+="...",m+=l),O>0&&s&&!_&&(m+=`
|
|
9
|
+
${l}`),m+="}",m}}function ee(t,e){t=$t(t,"UTC",e);const r=t.getUTCFullYear().toString().padStart(4,"0"),n=(t.getUTCMonth()+1).toString().padStart(2,"0"),s=t.getUTCDate().toString().padStart(2,"0"),i=t.getUTCHours().toString().padStart(2,"0"),u=t.getUTCMinutes().toString().padStart(2,"0"),o=t.getUTCSeconds().toString().padStart(2,"0");return`${r}-${n}-${s}_${i}-${u}-${o}`}function Ye(t){return t==null?null:t.replace(/[&<>"']/g,e=>{switch(e){case"&":return"&";case"<":return"<";case">":return"&rt;";case'"':return""";default:return"'"}})}function Qe(t){return t==null?null:t?.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&")}function xt(t){if(t==null)return null;if(Array.isArray(t)){const e=t.length,r=[];for(let n=0;n<e;n++)r.push(xt(t[n]));return r}if(typeof t=="object"){if(t.constructor&&t.constructor!==Object)return t;const e={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=xt(t[r]));return e}return t}function H(t,e){if(t===e)return!0;if(t==null)return e==null;if(e==null)return!1;if(Array.isArray(t)){if(!Array.isArray(e))return!1;const r=t.length;if(r!==e.length)return!1;for(let n=0;n<r;n++)if(!H(t[n],e[n]))return!1;return!0}if(typeof t=="object"){if(typeof e!="object"||t.constructor&&t.constructor!==Object||e.constructor&&e.constructor!==Object)return!1;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&!H(t[r],Object.prototype.hasOwnProperty.call(e,r)?e[r]:null))return!1;for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&!Object.prototype.hasOwnProperty.call(t,r)&&!H(e[r],null))return!1;return!0}return!1}function Ze(t,e){if(t==null||e==null)return t==null==(e==null);if(t.size!==e.size)return!1;for(const[r,n]of t)if(!H(n,e.get(r)))return!1;return!0}function tr(t,e){const r=t.length;if(r!==e.length)return!1;for(let n=0;n<r;n++)if(t[n]!==e[n])return!1;return!0}function Ot(t){return!t||typeof t!="object"?t:Array.isArray(t)?t.map(Ot):t&&Object.keys(t).sort().reduce((e,r)=>{const n=Ot(t[r]);return n!=null&&(e[r]=n),e},{})}function er(t,e){return Object.defineProperty(t,"name",{value:e,configurable:!0}),t}function rr(t){const e=alert;return window.alert=r=>t(e,r),()=>{window.alert=e}}var v=(t=>(t.log="log",t.warn="warn",t.error="error",t.info="info",t.debug="debug",t.trace="trace",t.assert="assert",t))(v||{});const vt=Object.values(v);function P(t){return function(){t.apply(console,arguments)}}const Vt={log:P(console.log),warn:P(console.warn),error:P(console.error),info:P(console.info),debug:P(console.debug),trace:P(console.trace),assert:P(console.assert)};function Mt(t){return vt.forEach(e=>{console[e]=(...r)=>{t(Vt,e,r)}}),()=>{vt.forEach(e=>{console[e]=Vt[e]})}}function nr(t){return function(r){let n=null;const i=Mt((o,a,c)=>{try{t(o,a,c)}catch(f){throw n||(n=f),f}}),u=()=>{if(i(),n)throw n};try{const o=r();return U.isPromiseLike(o)?o.then(a=>(u(),a),a=>{throw u(),a}):(u(),o)}catch(o){throw u(),o}}}class At{_listeners=new Map;_listenersAdd=new Map;_startStopNotifier;_emit;_update;_unsubscribeNotifier=null;_emitLast;_hasLast;_last=void 0;_emitting=!1;_subscribing=!1;_actionOnCycle;constructor({emitLastEvent:e,startStopNotifier:r,hasLast:n,last:s,actionOnCycle:i}={}){this._startStopNotifier=r??null,this._emit=r?u=>this.emit(u):null,this._update=r?u=>this.update(u):null,this._emitLast=e??!1,this._hasLast=n??!1,this._last=s,this._actionOnCycle=i??!1}get hasLast(){return this._hasLast}get last(){return this._last}get hasListeners(){return this._listeners.size>0}subscribe(e){const r={};if(this._emitting?this._listenersAdd.set(r,e):this._listeners.set(r,e),this._subscribing&&this._actionOnCycle==="throw")throw new Error("[Rx][Subject] Circular subscription detected");if((this._hasLast||this._subscribing&&this._actionOnCycle==="emitLast")&&e(this._last),this._startStopNotifier&&this._listeners.size+this._listenersAdd.size===1)try{this._subscribing=!0,this._unsubscribeNotifier=this._startStopNotifier(this._emit,this._update)??null}finally{this._subscribing=!1}return()=>{if(this._listeners.delete(r),this._listenersAdd.delete(r),this._startStopNotifier&&this._listeners.size===0&&this._listenersAdd.size===0){const n=this._unsubscribeNotifier;this._unsubscribeNotifier=null,n?.()}}}emit(e){if(this._emitting){if(this._actionOnCycle==="throw")throw new Error("[Rx][Subject] Circular emit detected");this._actionOnCycle==="emitLast"&&(this._last=e,this._hasLast=!0);return}const r=()=>{this._listenersAdd.size>0&&(this._listenersAdd.forEach((n,s)=>{this._listeners.set(s,n)}),this._listenersAdd.clear()),this._emitting=!1};try{this._emitting=!0,this._emitLast&&(this._last=e,this._hasLast=!0);let n;if(this._listeners.forEach(s=>{const i=s(e);U.isPromiseLike(i)&&(n||(n=[]),n.push(i))}),n)return Promise.all(n).then(r,s=>{throw r(),s});r()}catch(n){throw r(),n}}update(e){if(!this._emitLast)throw new Error("[Rx][Subject] update available only for subjects with emitLastEvent");const r=e(this._last);return this.emit(r)}}function sr(t,e){return k(t,{maxDepth:5,maxItems:10,...e})}function ir(t){return t.map(e=>e&&typeof e=="object"?sr(e):e)}function or(t){return`${ee(new Date)} [${t.level.toUpperCase()}] ${ir(t.args).join(" ")}`}let ft=null,wt=null;function re(){return wt||(wt=new At({startStopNotifier:t=>(ft=t,()=>{ft=null})})),wt}function ur(){return Mt((t,e,r)=>{e==="assert"&&r[0]===!0||(e===v.error||e===v.warn||e===v.assert)&&(ft&&ft({date:Date.now(),level:e,args:r}),t[e](...r))})}function ar(t){if(typeof window>"u")return U.EMPTY_FUNC;const{levels:e,predicate:r}=t;return re().subscribe(n=>{if(e&&!e.includes(n.level))return;const s=n.args.join(`
|
|
10
|
+
`);r&&!r({text:s,message:n})||alert(s)})}var Tt=(t=>(t[t.none=0]="none",t[t.error=1]="error",t[t.warn=2]="warn",t[t.debug=3]="debug",t))(Tt||{});function ne(){let t=new Error().stack;if(t!=null){const e=t.indexOf(`
|
|
11
|
+
`);e!=null&&e>=0&&(t=t.substring(e+1))}return t??""}function cr(t){return function(...e){const r=ne();try{return t.apply(this,e)}catch(n){throw n instanceof Error||(n=new Error(String(n))),n.stack=n.stack?n.stack+`
|
|
12
|
+
`+r:r,n}}}function se(t){if(!t||t.timeout==null)return null;const e=new ct.AbortControllerFast,r=t.timeController??zt.timeControllerDefault;if(t.timeout){const n=r.setTimeout(()=>{e.abort(new ct.AbortError(`[timeoutAbortController] Timeout error: ${t.timeout}ms`))},t.timeout);e.signal.subscribe(()=>{clearTimeout(n)})}return t.abortSignal?.subscribe(n=>{e.abort(n)}),e}async function lr(t,e){const r=se(e);try{return await t(r?.signal??e?.abortSignal??null)}finally{r?.abort()}}class fr{_options;_hasValue=!1;_promiseOrValue=null;constructor(e){this._options=e}run(){if(!this._hasValue){let e=this._options.func();const r=s=>(this._options.persist?this._promiseOrValue=s:(this._promiseOrValue=null,this._hasValue=!1),s),n=s=>{throw this._options.persist||(this._promiseOrValue=null,this._hasValue=!1),s};if(U.isPromiseLike(e))e=e.then(r,n);else if(!this._options.persist)return e;this._promiseOrValue=e,this._hasValue=!0}return this._promiseOrValue}set(e){if(!this._options.persist)throw new Error("[Lazy][set] Cannot set value when persist is false");this._hasValue=!0,this._promiseOrValue=e}}class hr{_options;_promiseOrValues=new Map;constructor(e){this._options=e}run(e){if(this._promiseOrValues.has(e))return this._promiseOrValues.get(e);let r=this._options.func(e);const n=i=>(this._options.persist?this._promiseOrValues.set(e,i):this._promiseOrValues.delete(e),i),s=i=>{throw this._options.persist||this._promiseOrValues.delete(e),i};if(U.isPromiseLike(r))r=r.then(n,s);else if(!this._options.persist)return r;return this._promiseOrValues.set(e,r),r}set(e,r){if(!this._options.persist)throw new Error("[LazyWithId][set] Cannot set value when persist is false");this._promiseOrValues.set(e,r)}}async function mr(t){const e=t.abortSignal??null,r=t.timeController??zt.timeControllerDefault;let n=0;for(;;)try{return await t.func({abortSignal:e})}catch(s){if((t.logLevel==null||t.logLevel>=Tt.error)&&console.error("[withRetry] error",s),e?.aborted)throw s;const i=t.delay({error:s,retryCount:n++,abortSignal:e});if(i==null||(typeof i=="number"?await U.delay(i,e??void 0,r):await i(),e?.aborted))throw s}}function dr({maxRetries:t,delays:e,isRetriableError:r}){return function({retryCount:s,error:i}){if(s==null||t!=null&&s>=t)return null;if(r==null||r(i)){if(Array.isArray(e))return e[Math.min(s,e.length-1)];{const u=e.mult??2;return Math.min(e.min*u**s,e.max)}}return null}}function pr(t){return t!=null&&typeof t=="object"&&typeof t.subscribe=="function"}class yr{_subjects=new Map;_getLastEvent;constructor({getLastEvent:e}={}){this._getLastEvent=e}subscribe(e,r){let n=this._subjects.get(e);n||(n=new At,this._subjects.set(e,n));const s=n.subscribe(r);if(this._getLastEvent){const i=this._getLastEvent(e);r(i)}return()=>{s(),n?.hasListeners||this._subjects.delete(e)}}emit(e,r){const n=this._subjects.get(e);if(n)return n.emit(r)}forEach(e){this._subjects.forEach(e)}observable(e){return{subscribe:r=>this.subscribe(e,r)}}emitter(e){return{emit:r=>this.emit(e,r)}}subject(e){return{subscribe:r=>this.subscribe(e,r),emit:r=>this.emit(e,r)}}}function gr(t,e,r){return new Promise(n=>{let s=!1,i;function u(f){a?.(),i?.(),s=!0,n(f)}function o(f){a?.(),i?.(),s=!0,n(Promise.reject(f))}const a=r?.subscribe(o);let c=!0;i=t.subscribe(f=>{(!e||e(f,c))&&u(f),c=!1}),s&&i?.()})}class R extends Error{constructor(e){super(e)}}class d{_args;constructor(e){this._args=e&&{...e}}set(e){return this._args={...this._args??{},...e},this}name(e){return this.set({name:e})}toString(e){const r=this._args?.name;return r?typeof r=="string"?r:r(e):this.nameDefault(e)}}function ie(t,e){return k(t,{maxDepth:1,maxItems:5,...e})}function D(t){return t instanceof d}function Y(t){return ie(t)}function ht(t,...e){if(t==null)return"";const r=ie(t,{filter:(n,s)=>{if(n.length===0)return!0;if(n.length!==1)return!1;const i=n[0];return!(i==="name"||i==="expected"||s==null||s===!1||e.includes(i))}});return/^(#\d+\s*)\{}$/.test(r)?"":`(${r})`}function J(t){const{result:e,cause:r,nested:n,error:s}=t;if(s){if(!(s instanceof Error))throw new R(`[test][validateMatchResult] error must be an instance of Error, but it is: ${s}`);if(e!=null)throw new R(`[test][validateMatchResult] result must be null if error is set, but it is: ${e}`);if(r!=null)throw new R(`[test][validateMatchResult] cause must be null if error is set, but it is: ${r}`);if(n!=null)throw new R(`[test][validateMatchResult] nested must be null if error is set, but it is: ${n}`);return t}if(typeof e!="boolean")throw new R(`[test][validateMatchResult] result must be a boolean, but it is: ${e}`);if(typeof r!="string"&&r!=null)throw new R(`[test][validateMatchResult] cause must be a string or null, but it is: ${r}`);if(n!=null&&!(n instanceof Array))throw new R(`[test][validateMatchResult] nested must be an array or null, but it is: ${n}`);return t}function oe(t,e,r){return J({actual:t,expected:e,result:null,cause:null,nested:null,error:r})}function It(t,e,r){return J({actual:t,expected:e,result:r,cause:null,nested:null,error:null})}function Ct(t,e,r){return typeof r=="boolean"?It(t,e,r):J(typeof r=="string"?{actual:t,expected:e,result:!1,cause:r,nested:null,error:null}:{actual:t,expected:e,result:r.result,cause:r.cause??null,nested:r.nested??null,error:null})}function $(t,e){try{if(D(e)){const r=e.match(t);return Ct(t,e,r)}return It(t,e,t===e)}catch(r){return oe(t,e,r)}}class Nt extends d{match(e){const r=this._args.expected,n=$(e,r);return{result:!n.result,nested:[{actualKey:null,result:n}]}}nameDefault(){return"not"}}function ue(t,e){const r=Rt(t.result,e);return r?{actualKey:t.actualKey,expectedKey:t.expectedKey,result:r}:null}function Rt(t,e){if(e?!t.result:t.result)return null;t.expected instanceof Nt&&(e=!e);let r=null;return t.nested&&t.nested.forEach(n=>{const s=ue(n,e);s&&(r||(r=[]),r.push(s))}),{actual:t.actual,expected:t.expected,result:t.result,cause:t.cause,nested:r,error:t.error}}function ae(t,e){const r=kt(t.result,e+" ");return`${e}${t.actualKey==null?"| ":t.actualKey+": "}${r}`}function kt(t,e){if(t.result)return t.expected.toString();let r="";t.nested&&(r=t.nested.map(s=>ae(s,e)).join(`
|
|
13
|
+
`));let n=t.cause||"";return r?(n||(n=D(t.expected)?t.expected.toString(t.actual):""),`${n}
|
|
14
|
+
${r}`):`${n}
|
|
15
|
+
${e}expected: ${D(t.expected)?t.expected.toString(t.actual):t.expected}
|
|
16
|
+
${e}actual: ${Y(t.actual)}`}class Dt extends Error{constructor(e){super(e)}}function W(t){return function(r,n){const s=$(t,r);if(s.error)throw s.error;const i=Rt(s,!1);if(!i)return;const u=kt(i,"");console.log(`[test][check] CheckError:
|
|
17
|
+
`+u);const o=new Dt(u);throw n?.(o),o}}function br(t){return function(r,n){let s;try{s=t()}catch(i){W(i)(n);return}return U.isPromiseLike(s)?s.then(i=>(W(i)(r),i)).catch(i=>{if(i instanceof Dt)throw i;try{W(i)(n)}catch(u){throw console.error("[test][check] error",u),i}}):(W(s)(r),s)}}const Q=10;class Ut extends d{match(e){if(e==null)return`Expected array, got "${e}"`;if(typeof e!="object")return`Expected array, got "${typeof e}"`;if(!(e instanceof Array))return"Expected array";const r=this._args?.expected;if(r==null)return!0;const n=this._args?.maxReportItems??Q,s=this._args?.matchType||"equals";if(s==="equals"){if(e.length!==r.length)return`Expected array length to be ${r.length}, got ${e.length}`;let i=!0,u=0,o=0;const a=[];for(let c=0;c<r.length;c++){const f=e[c],b=r[c],y=$(f,b);if(y.result?(u<n&&a.push({actualKey:c,expectedKey:c,result:y}),u++):(o<n&&a.push({actualKey:c,expectedKey:c,result:y}),o++,i=!1),!i&&u>=n&&o>=n)break}return{result:i,nested:a}}if(s==="includes"){let i=!0;const u=[];let o=0,a=0;for(let c=0;c<r.length;c++){const f=r[c];let b=!1;for(let y=0;y<e.length;y++){const h=e[y],l=$(h,f);if(l.result){b=!0,o<n&&u.push({actualKey:y,expectedKey:c,result:l}),o++;break}}if(b||(i=!1,a<n&&u.push({expectedKey:c,result:{result:!1,actual:void 0,expected:f}}),a++),!i&&o>=n&&a>=n)break}return{result:i,nested:u}}return`Unknown matchType "${s}"`}nameDefault(){return`array ${this._args?.matchType||"equals"} ${Y(this._args?.expected)}`}}class ce extends d{match(){return!0}nameDefault(){return"any"}}class le extends d{match(e){if(typeof e!="object")return`Expected array, got "${typeof e}"`;if(!(e instanceof Array))return"Expected array";const r=this._args.expected;let n=!0;const s=[],i=this._args?.maxReportItems??Q;let u=0,o=0;for(let a=0;a<e.length;a++){const c=e[a],f=$(c,r);if(f.result?(u<i&&s.push({actualKey:a,expectedKey:a,result:f}),u++):(o<i&&s.push({actualKey:a,expectedKey:a,result:f}),o++,n=!1),!n&&u>=i&&o>=i)break}return{result:n,nested:s}}nameDefault(){return"array item"}}class fe extends d{match(e){const{expected:r,convert:n}=this._args,s=$(n(e),r),i=[{result:s}];return{result:s.result,nested:i}}nameDefault(){return"convert"}}class jt extends d{match(e){const{expected:r,nonStrict:n}=this._args;return n?e==r:e===r}nameDefault(){return`is(${Y(this._args.expected)})`}}class he extends d{match(e){if(e==null)return`Expected number, got "${e}"`;if(typeof e!="number")return`Expected number, got "${typeof e}"`;if(this._args==null)return Number.isFinite(e)?!0:"Expected finite number";if(!this._args.allowNaN&&Number.isNaN(e))return"Expected not NaN";if(!this._args.allowInfinity&&!Number.isFinite(e))return"Expected not Infinity";const{min:r,max:n,float:s}=this._args;return!s&&!Number.isInteger(e)?`Expected integer, got "${e}"`:r!=null&&e<r?`Expected number to be >= ${r}, got ${e}`:n!=null&&e>n?`Expected number to be <= ${n}, got ${e}`:!0}nameDefault(){return`number(${ht(this._args)})`}}class me extends d{match(e){if(e==null)return`Expected object, got "${e}"`;if(Array.isArray(e))return"Expected object, got array";if(typeof e!="object")return`Expected object, got "${typeof e}"`;const r=this._args?.expected;if(r==null)return!0;let n=!0;const s=[],i=this._args?.maxReportItems??Q;let u=0,o=0;for(const a in r){if(!Object.prototype.hasOwnProperty.call(r,a))continue;const c=e[a],f=r[a],b=$(c,f);if(b.result?(u<i&&s.push({actualKey:a,expectedKey:a,result:b}),u++):(o<i&&s.push({actualKey:a,expectedKey:a,result:b}),o++,n=!1),!n&&u>=i&&o>=i)break}if(!this._args?.ignoreExtraKeys)for(const a in e){if(!Object.prototype.hasOwnProperty.call(e,a)||Object.prototype.hasOwnProperty.call(r,a))continue;const c=e[a];if(o<i&&s.push({actualKey:a,expectedKey:a,result:Ct(c,void 0,"Unexpected key")}),o++,n=!1,o>=i)break}return{result:n,nested:s}}nameDefault(){return"object"+ht(this._args)}}class de extends d{match(e){if(e==null)return`Expected string, got ${e}`;if(typeof e!="string")return`Expected string, got "${typeof e}"`;if(this._args==null)return!0;const{pattern:r}=this._args;if(r!=null){if(typeof r=="function")return r(e);if(!r.test(e))return!1}return!0}nameDefault(){return this._args?.pattern?`string(${this._args.pattern})`:"string"}}class pe extends d{match(e){const r=this._args.expected;return e instanceof r?!0:`Expected instance of "${r}", got "${e}"`}nameDefault(){return`instanceOf(${this._args.expected.name})`}}class ye extends d{constructor(e){super({...e,expected:e.expected instanceof Set?e.expected:new Set(e.expected)})}match(e){return!!this._args.expected.has(e)}nameDefault(){return`in(${Y(this._args.expected)})`}}class Z extends d{match(e){const{type:r,expecteds:n,pipe:s}=this._args;let i=r==="and";const u=[];for(let o=0;o<n.length;o++){const a=n[o],c=$(e,a);if(u.push({actualKey:`<${r} ${o}>`,expectedKey:`<${r} ${o}>`,result:c}),r==="or"){if(c.result&&(i=!0,s))break}else if(r==="and"){if(!c.result&&(i=!1,s))break}else throw new Error(`[test][MatcherFew] Unknown type "${r}"`)}return{result:n.length===0||i,nested:u}}nameDefault(){return this._args.type}}class ge extends d{match(e){const r=this._args.matcher;return D(r)?r.match(e):r(e)}nameDefault(e){const r=this._args.name;return typeof r=="string"?r:r?r(e):"custom"}}class be extends d{match(){return!1}nameDefault(){return"never"}}class we extends d{match(e){if(e==null)return`Expected object, got "${e}"`;if(Array.isArray(e))return"Expected object, got array";if(typeof e!="object")return`Expected object, got "${typeof e}"`;const r=this._args?.expected;if(r==null)return!0;let n=!0;const s=[],i=this._args?.maxReportItems??Q;let u=0,o=0;for(const a in e){if(!Object.prototype.hasOwnProperty.call(e,a))continue;const c=[a,e[a]],f=$(c,r);if(f.result?(u<i&&s.push({actualKey:a,expectedKey:a,result:f}),u++):(o<i&&s.push({actualKey:a,expectedKey:a,result:f}),o++,n=!1),!n&&u>=i&&o>=i)break}return{result:n,nested:s}}nameDefault(){return"object entries"+ht(this._args)}}class _e extends d{_hasExpected=!1;_expected=void 0;get expected(){return this._expected}set expected(e){this._expected=e,this._hasExpected=!0}match(e){const r=$(e,this._expected),n=[{result:r}];return{result:r.result,nested:n}}nameDefault(){return"ref"}}function j(t){return new Ut({expected:t})}function wr(t){return new Ut({expected:t,matchType:"includes"})}function V(){return new ce}function _r(){return new _e}function xr(t){return new be({name:t})}function Or(t,e){const r=new le({expected:e});return t==null?r:M($e(D(t)||typeof t=="number"?t:tt(t)),r).name("array item")}function I(t,e,r){return new fe({name:t,convert:e,expected:r})}function xe(t){return new jt({expected:t,nonStrict:!0})}function Oe(t){return new jt({expected:t,nonStrict:!1})}function Pt(t){return new he(t)}function tt(t){return Pt({...t,float:!1})}function Sr(t){return Pt({...t,float:!0})}function C(t){return new me({expected:t})}function ut(t,e,r=null){if(t instanceof d||e&&(t=e(t,r),t instanceof d))return t;if(t==null)return X();if(Array.isArray(t)){const n=t.map((s,i)=>ut(s,e,i));return j(n)}if(t.constructor===Object){const n={};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=ut(t[s],e,s));return C(n)}return t instanceof U.ValueState?Ie({...t,value:ut(t.value,e,"value")}):Oe(t)}function Er(t){return C(t).set({ignoreExtraKeys:!0})}function Lt(t){return new de({pattern:t})}function $r(t){return new pe({expected:t})}function Se(t){return I("typeof",e=>e===null?"null":typeof e,t)}function Mr(t){return I("constructor",e=>e.constructor,t)}function at(){return Se("boolean")}function X(){return xe(null)}function Ar(){return Te(X())}function Tr(...t){return new Z({expecteds:t,type:"or",pipe:!1})}function Ir(...t){return new Z({expecteds:t,type:"and",pipe:!1})}function Ee(...t){return new Z({expecteds:t,type:"or",pipe:!0})}function M(...t){return new Z({expecteds:t,type:"and",pipe:!0})}function K(t,e){return e==null?Ee(X(),t):e?t:X()}function $e(t){const e=typeof t=="number"||D(t)?t:tt(t??{min:1});return M(j(),I("length",r=>r.length,e)).name("array length")}function Cr(t){const e=typeof t=="number"||D(t)?t:tt(t??{min:1});return M(Lt(),I("length",r=>r.length,e)).name("string length")}function Nr(t){return M(C(),t)}function Rr(t){return M(j(),t)}function kr(t){return M(C(),I("keys",e=>Object.keys(e),t))}function Dr(t){return M(C(),I("values",e=>Object.values(e),t))}function Ur(t){return M(C(),I("entries",e=>Object.entries(e),t))}function mt(t){return new we({expected:t})}function jr(t){return mt(j([t,V()]))}function Pr(t){return mt(j([V(),t]))}function Lr(t,e){return mt(j([t,e]))}function Kr(t){return M(C(),I("keys not null",e=>Object.keys(e).filter(r=>e[r]!=null),t))}function Me(t){return new ye({expected:t})}function Fr(t){return Me(Object.values(t))}function Kt(t,e){return new ge({matcher:e,name:t})}const vr=Math.ceil(Date.now()-10*365.25*24*60*60*1e3),Vr=Math.ceil(Date.now()+10*365.25*24*60*60*1e3);function G(t){return tt({...t,min:t?.min??vr,max:t?.max??Vr}).name("int date")}function Ae(t){const e={min:t?.from?.min??t?.common?.min,max:t?.from?.max??t?.common?.max,float:t?.from?.float??t?.common?.float,optional:t?.from?.optional??t?.common?.optional},r={min:t?.to?.min??t?.common?.min,max:t?.to?.max??t?.common?.max,float:t?.to?.float??t?.common?.float,optional:t?.to?.optional??t?.common?.optional};return M(j([e.optional?K(G()):G(),r.optional?K(G()):G()]),Kt("min <= max",n=>n[0]!=null&&n[1]!=null&&n[0]>n[1]?`Expected range to be [min, max], got [${n.join(", ")}]`:!0)).name("range")}function Br(t){return Ae({...t,common:{min:new Date(2020,0,1).getTime(),max:Date.now()+900*1e3,...t?.common}}).name("range date")}function Te(t){return new Nt({expected:t})}function zr(){return Lt(/^[\da-f-]{36}|[\da-f]{32}$/i).name("uuid")}function Ie(t){return C({[Symbol.toStringTag]:K(V()),loading:K(at()),hasValue:K(at()),value:V(),hasError:K(at()),error:V(),...t})}function qr(t){return t!=null&&typeof t=="string"&&(t=new TextEncoder().encode(t).buffer),Kt("array buffer",e=>{if(e==null||typeof e!="object"||typeof e.byteLength!="number")return`Expected array buffer, got "${e}"`;if(t==null)return!0;if(e.byteLength!==t.byteLength)return`Expected array buffer length to be ${t.byteLength}, got ${e.byteLength}`;for(let r=0,n=t.byteLength;r<n;r++)if(e[r]!==t[r])return`Expected array buffer[${r}] to be ${t[r]}, got ${e[r]}`;return!0})}function Bt(t){return t.replace(/\W/g,"").toLowerCase()}function Ce(t){return t instanceof URL?t.searchParams:t instanceof URLSearchParams?t:typeof t=="string"?new URL(t).searchParams:typeof window<"u"?new URL(window.location.href).searchParams:new URLSearchParams}function Ne(t){return t==null?null:(t=t.toLowerCase().trim(),t==="true"||t==="1"||t==="yes"?!0:t==="false"||t==="0"||t==="no"?!1:null)}function Re(t){if(t==null)return null;t=t.trim();const e=parseInt(t,10);return isNaN(e)?null:e}function ke(t){if(t==null)return null;t=t.trim();const e=parseFloat(t);return isNaN(e)?null:e}function dt(t,e){const r=Ce(e),n=Bt(t);for(const[s,i]of r.entries())if(Bt(s)===n)return i;return null}function Wr(t,e){return Ne(dt(t,e))}function Gr(t,e){return Re(dt(t,e))}function Hr(t,e){return ke(dt(t,e))}exports.CheckError=Dt;exports.ConsoleMessageLevel=v;exports.Lazy=fr;exports.LazyWithId=hr;exports.LogLevel=Tt;exports.MAX_REPORT_ITEMS_DEFAULT=Q;exports.MatchInternalError=R;exports.Matcher=d;exports.MatcherAny=ce;exports.MatcherArray=Ut;exports.MatcherArrayItem=le;exports.MatcherConvert=fe;exports.MatcherCustom=ge;exports.MatcherFew=Z;exports.MatcherIn=ye;exports.MatcherInstanceOf=pe;exports.MatcherIs=jt;exports.MatcherNever=be;exports.MatcherNot=Nt;exports.MatcherNumber=he;exports.MatcherObject=me;exports.MatcherObjectEntry=we;exports.MatcherRef=_e;exports.MatcherString=de;exports.Random=lt;exports.Subject=At;exports.SubjectWithId=yr;exports.UNIQUE_PSEUDO_RANDOM_MAX_COUNT=ot;exports.alertConsole=ar;exports.alertReplace=rr;exports.argsToString=ht;exports.check=W;exports.checkFunc=br;exports.consoleIntercept=ur;exports.consoleMessageToString=or;exports.consoleReplace=Mt;exports.convertTimeZone=$t;exports.createMatchResult=Ct;exports.createMatchResultBoolean=It;exports.createMatchResultError=oe;exports.createTaskDelayRetry=dr;exports.createUniquePseudoRandom=Ge;exports.dateNowUnique=He;exports.deepCloneJsonLike=xt;exports.deepEqualJsonLike=H;exports.deepEqualJsonLikeMap=Ze;exports.equalArray=tr;exports.escapeHtml=Ye;exports.escapeRegExp=Qe;exports.expectedToString=Y;exports.filterMatchResult=Rt;exports.filterMatchResultNested=ue;exports.fixStackTrace=cr;exports.formatAny=k;exports.formatDate=te;exports.formatDateFileName=ee;exports.getConsoleMessages=re;exports.getDateInet=Je;exports.getNormalizedObject=Ot;exports.getObjectId=L;exports.getRandomFunc=Yt;exports.getRandomSeed=Ve;exports.getStackTrace=ne;exports.isMatcher=D;exports.isObservable=pr;exports.match=$;exports.matchAnd=Ir;exports.matchAndPipe=M;exports.matchAny=V;exports.matchArray=j;exports.matchArrayBuffer=qr;exports.matchArrayIncludes=wr;exports.matchArrayItem=Or;exports.matchArrayLength=$e;exports.matchArrayWith=Rr;exports.matchBoolean=at;exports.matchConstructor=Mr;exports.matchConvert=I;exports.matchCustom=Kt;exports.matchDeep=ut;exports.matchEnum=Fr;exports.matchFloat=Sr;exports.matchIn=Me;exports.matchInstanceOf=$r;exports.matchInt=tt;exports.matchIntDate=G;exports.matchIs=Oe;exports.matchIsNonStrict=xe;exports.matchNever=xr;exports.matchNot=Te;exports.matchNotNullish=Ar;exports.matchNullish=X;exports.matchNumber=Pt;exports.matchObject=C;exports.matchObjectEntries=Ur;exports.matchObjectEntry=mt;exports.matchObjectKey=jr;exports.matchObjectKeyValue=Lr;exports.matchObjectKeys=kr;exports.matchObjectKeysNotNull=Kr;exports.matchObjectPartial=Er;exports.matchObjectValue=Pr;exports.matchObjectValues=Dr;exports.matchObjectWith=Nr;exports.matchOptional=K;exports.matchOr=Tr;exports.matchOrPipe=Ee;exports.matchRange=Ae;exports.matchRangeDate=Br;exports.matchRef=_r;exports.matchResultNestedToString=ae;exports.matchResultToString=kt;exports.matchString=Lt;exports.matchStringLength=Cr;exports.matchTypeOf=Se;exports.matchUuid=zr;exports.matchValueState=Ie;exports.max=Xt;exports.min=Jt;exports.minMax=Le;exports.numberMod=Ke;exports.randomBoolean=Be;exports.randomEnum=We;exports.randomFloat=St;exports.randomIndexWeighted=ze;exports.randomInt=Qt;exports.randomItem=Et;exports.randomItems=qe;exports.setFuncName=er;exports.sha256=Pe;exports.sha256Buffer=Ht;exports.timeoutAbortController=se;exports.toHex=qt;exports.truncateString=q;exports.urlGetBoolean=Wr;exports.urlGetFloat=Hr;exports.urlGetInt=Gr;exports.urlGetParams=Ce;exports.urlGetString=dt;exports.urlParamToBoolean=Ne;exports.urlParamToFloat=ke;exports.urlParamToInt=Re;exports.validateMatchResult=J;exports.waitObservable=gr;exports.withConsoleReplace=nr;exports.withRetry=mr;exports.withTimeout=lr;
|