@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
package/package.json
CHANGED
package/build/urlGet-BOGFUahf.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";const st=require("@flemist/abort-controller-fast"),L=require("@flemist/async-utils"),Ut=require("@flemist/time-controller");let Z=null;function be(){if(!Z){Z=new Array(256);for(let t=0;t<256;t++)Z[t]=t.toString(16).padStart(2,"0")}return Z}function jt(t){const e=be(),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 bt=null,Pt=null,tt=null,Lt=null;function we(){bt||(bt=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]),Pt=new Uint32Array(64),Lt=new TextEncoder,tt=new Uint8Array(65536))}function Kt(t){if(t==null)return null;we();const e=bt,r=Pt,n=Lt;let s=tt,i;if(typeof t=="string"){const g=t.length*3;s.length<g+128&&(s=tt=new Uint8Array(g+128));const d=n.encodeInto(t,s);i=s.subarray(0,d.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=tt=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],dt=(x>>>7|x<<25)^(x>>>18|x<<14)^x>>>3,Q=(N>>>17|N<<15)^(N>>>19|N<<13)^N>>>10;r[w]=r[w-16]+dt+r[w-7]+Q|0}let d=b,M=y,X=h,mt=l,T=m,Y=O,B=_,pt=S;for(let w=0;w<64;w+=4)for(let x=0;x<4;x++){const N=w+x,dt=(T>>>6|T<<26)^(T>>>11|T<<21)^(T>>>25|T<<7),Q=pt+dt+(B^T&(Y^B))+e[N]+r[N]|0,ge=((d>>>2|d<<30)^(d>>>13|d<<19)^(d>>>22|d<<10))+(d&M^X&(d^M))|0;pt=B,B=Y,Y=T,T=mt+Q|0,mt=X,X=M,M=d,d=Q+ge|0}b=b+d|0,y=y+M|0,h=h+X|0,l=l+mt|0,m=m+T|0,O=O+Y|0,_=_+B|0,S=S+pt|0}const $=new Uint8Array(32),K=[b,y,h,l,m,O,_,S];for(let g=0;g<8;g++){const d=K[g],M=g<<2;$[M]=d>>>24,$[M+1]=d>>>16&255,$[M+2]=d>>>8&255,$[M+3]=d&255}return $}function _e(t){const e=Kt(t);return e?jt(e):null}function Vt(t,e){return t==null?e:e==null?t:Math.min(t,e)}function Ft(t,e){return t==null?e:e==null?t:Math.max(t,e)}function xe(t,e,r){return Ft(Vt(t,e),r)}function Oe(t,e){return(t%e+e)%e}function Se(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 $e(){return Math.random()}function Ee(){return Math.random()*2**32>>>0}function vt(t){return t!=null?Se(t):$e}class it{_seed;_rnd;constructor(e){this._seed=e,this._rnd=vt(e)}get seed(){return this._seed}nextSeed(){return this.next()*2**32>>>0}nextRandom(){return new it(this.nextSeed())}next(){return this._rnd()}clone(){return new it(this._seed)}}function xt(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 Bt(t,e,r){return Math.floor(xt(t,e,r))}function Ae(t,e){return t.next()<(e??.5)}function Me(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=xt(t,n);for(let i=0;i<e;i++)if(s-=r(i),s<0)return i;return e-1}function Ot(t,e){if(e.length===0)throw new Error("[random][randomItem] items is empty");const r=Bt(t,e.length);return e[r]}function Te(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(Ot(t,e));return n}function Ie(t,e,r){let n=Object.values(e);return r&&(n=n.filter(r)),Ot(t,n)}const zt=1073741789,et=(zt>>2)-1;function Ce(t=et,e){if(t<=0)throw new Error(`[random][PseudoRandom] count(${t}) must be > 0`);if(t>et)throw new Error(`[random][PseudoRandom] count(${t}) must be <= ${et}`);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 Ne(){const t=Date.now();return z==null||t>z?(z=t,t):(z++,z)}async function De({url:t,timeout:e}={}){t||(t=typeof window<"u"?"/":"https://google.com");let r;try{const n=new st.AbortControllerFast;r=e?setTimeout(()=>{n.abort()},e):null;const s=await fetch(t,{method:"HEAD",signal:st.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 St(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 qt(t,e){t=St(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 ke=0;const yt=new WeakMap;function V(t){if(yt.has(t))return yt.get(t);const e=ke++;return yt.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 Nt(t,e){try{return t[e]}catch(r){return"Error: "+(r instanceof Error?r.message:String(r))}}function D(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=>D(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??""}#${V(t)}[${t.byteLength}]`;if(t instanceof RegExp)return q(String(t),a,e?.truncateOptions);if(t instanceof Date)return qt(t);if(t instanceof Object){if(n.has(t)||u!=null&&y>=u)return`${t.constructor===Object?"":t.constructor?.name??""}#${V(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+=`#${V(t)} `),l+="[";let m=0,O=!1;for(let _=0;_<t.length;_++){if(o!=null&&m>=o){O=!0;break}const S=[...r,String(_)],$=Nt(t,_);if(i!=null&&!i(S,$))continue;const K=D($,e,S,n);m>0&&(l+=","),s&&(l+=`
|
|
2
|
-
`),s&&(l+=`${h} `),f&&(l+=`${_}: `),l+=`${K}`,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+=`#${V(t)} `),h+="Map",h+=D(Array.from(t.entries()),e,r,n),h}if(t instanceof Set){let h="";return c&&(h+=`#${V(t)} `),h+="Set",h+=D(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+=`#${V(t)} `),m+="{";let O=0,_=!1;for(const S in t){if(o!=null&&O>=o){_=!0;break}const $=[...r,S],K=Nt(t,S);if(i!=null&&!i($,K))continue;const g=D(K,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 Wt(t,e){t=St(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 Re(t){return t==null?null:t.replace(/[&<>"']/g,e=>{switch(e){case"&":return"&";case"<":return"<";case">":return"&rt;";case'"':return""";default:return"'"}})}function Ue(t){return t==null?null:t?.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&")}function wt(t){if(t==null)return null;if(Array.isArray(t)){const e=t.length,r=[];for(let n=0;n<e;n++)r.push(wt(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]=wt(t[r]));return e}return t}function G(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(!G(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)&&!G(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)&&!G(e[r],null))return!1;return!0}return!1}function je(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(!G(n,e.get(r)))return!1;return!0}function Pe(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 _t(t){return!t||typeof t!="object"?t:Array.isArray(t)?t.map(_t):t&&Object.keys(t).sort().reduce((e,r)=>{const n=_t(t[r]);return n!=null&&(e[r]=n),e},{})}function Le(t,e){return Object.defineProperty(t,"name",{value:e,configurable:!0}),t}function Ke(t){const e=alert;return window.alert=r=>t(e,r),()=>{window.alert=e}}var F=(t=>(t.log="log",t.warn="warn",t.error="error",t.info="info",t.debug="debug",t.trace="trace",t.assert="assert",t))(F||{});const Dt=Object.values(F);function R(t){return function(){t.apply(console,arguments)}}const kt={log:R(console.log),warn:R(console.warn),error:R(console.error),info:R(console.info),debug:R(console.debug),trace:R(console.trace),assert:R(console.assert)};function $t(t){return Dt.forEach(e=>{console[e]=(...r)=>{t(kt,e,r)}}),()=>{Dt.forEach(e=>{console[e]=kt[e]})}}function Ve(t){return function(r){let n=null;const i=$t((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 L.isPromiseLike(o)?o.then(a=>(u(),a),a=>{throw u(),a}):(u(),o)}catch(o){throw u(),o}}}class Et{_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);L.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 Fe(t,e){return D(t,{maxDepth:5,maxItems:10,...e})}function ve(t){return t.map(e=>e&&typeof e=="object"?Fe(e):e)}function Be(t){return`${Wt(new Date)} [${t.level.toUpperCase()}] ${ve(t.args).join(" ")}`}let ot=null,gt=null;function Gt(){return gt||(gt=new Et({startStopNotifier:t=>(ot=t,()=>{ot=null})})),gt}function ze(){return $t((t,e,r)=>{e==="assert"&&r[0]===!0||(e===F.error||e===F.warn||e===F.assert)&&(ot&&ot({date:Date.now(),level:e,args:r}),t[e](...r))})}function qe(t){if(typeof window>"u")return L.EMPTY_FUNC;const{levels:e,predicate:r}=t;return Gt().subscribe(n=>{if(e&&!e.includes(n.level))return;const s=n.args.join(`
|
|
10
|
-
`);r&&!r({text:s,message:n})||alert(s)})}var At=(t=>(t[t.none=0]="none",t[t.error=1]="error",t[t.warn=2]="warn",t[t.debug=3]="debug",t))(At||{});function Ht(){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 We(t){return function(...e){const r=Ht();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 Jt(t){if(!t||t.timeout==null)return null;const e=new st.AbortControllerFast,r=t.timeController??Ut.timeControllerDefault;if(t.timeout){const n=r.setTimeout(()=>{e.abort(new st.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 Ge(t,e){const r=Jt(e);try{return await t(r?.signal??e?.abortSignal??null)}finally{r?.abort()}}class He{_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(L.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 Je{_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(L.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 Xe(t){const e=t.abortSignal??null,r=t.timeController??Ut.timeControllerDefault;let n=0;for(;;)try{return await t.func({abortSignal:e})}catch(s){if((t.logLevel==null||t.logLevel>=At.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 L.delay(i,e??void 0,r):await i(),e?.aborted))throw s}}function Ye({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 Qe(t){return t!=null&&typeof t=="object"&&typeof t.subscribe=="function"}class Ze{_subjects=new Map;_getLastEvent;constructor({getLastEvent:e}={}){this._getLastEvent=e}subscribe(e,r){let n=this._subjects.get(e);n||(n=new Et,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 tr(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 U extends Error{constructor(e){super(e)}}class p{_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 Xt(t,e){return D(t,{maxDepth:1,maxItems:5,...e})}function P(t){return t instanceof p}function at(t){return Xt(t)}function Mt(t,...e){if(t==null)return"";const r=Xt(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 ut(t){const{result:e,cause:r,nested:n,error:s}=t;if(s){if(!(s instanceof Error))throw new U(`[test][validateMatchResult] error must be an instance of Error, but it is: ${s}`);if(e!=null)throw new U(`[test][validateMatchResult] result must be null if error is set, but it is: ${e}`);if(r!=null)throw new U(`[test][validateMatchResult] cause must be null if error is set, but it is: ${r}`);if(n!=null)throw new U(`[test][validateMatchResult] nested must be null if error is set, but it is: ${n}`);return t}if(typeof e!="boolean")throw new U(`[test][validateMatchResult] result must be a boolean, but it is: ${e}`);if(typeof r!="string"&&r!=null)throw new U(`[test][validateMatchResult] cause must be a string or null, but it is: ${r}`);if(n!=null&&!(n instanceof Array))throw new U(`[test][validateMatchResult] nested must be an array or null, but it is: ${n}`);return t}function er(t,e,r){return ut({actual:t,expected:e,result:null,cause:null,nested:null,error:r})}function Yt(t,e,r){return ut({actual:t,expected:e,result:r,cause:null,nested:null,error:null})}function Qt(t,e,r){return typeof r=="boolean"?Yt(t,e,r):ut(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 E(t,e){try{if(P(e)){const r=e.match(t);return Qt(t,e,r)}return Yt(t,e,t===e)}catch(r){return er(t,e,r)}}const ct=10;class Zt extends p{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??ct,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=E(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=E(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"} ${at(this._args?.expected)}`}}class rr extends p{match(){return!0}nameDefault(){return"any"}}class nr extends p{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??ct;let u=0,o=0;for(let a=0;a<e.length;a++){const c=e[a],f=E(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 sr extends p{match(e){const{expected:r,convert:n}=this._args,s=E(n(e),r),i=[{result:s}];return{result:s.result,nested:i}}nameDefault(){return"convert"}}class te extends p{match(e){const{expected:r,nonStrict:n}=this._args;return n?e==r:e===r}nameDefault(){return`is(${at(this._args.expected)})`}}class ir extends p{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(${Mt(this._args)})`}}class or extends p{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??ct;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=E(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:Qt(c,void 0,"Unexpected key")}),o++,n=!1,o>=i)break}return{result:n,nested:s}}nameDefault(){return"object"+Mt(this._args)}}class ur extends p{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 ar extends p{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 cr extends p{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(${at(this._args.expected)})`}}class lt extends p{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(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 lr extends p{match(e){const r=this._args.matcher;return P(r)?r.match(e):r(e)}nameDefault(e){const r=this._args.name;return typeof r=="string"?r:r?r(e):"custom"}}class ee extends p{match(e){const r=this._args.expected,n=E(e,r);return{result:!n.result,nested:[{actualKey:null,result:n}]}}nameDefault(){return"not"}}class fr extends p{match(){return!1}nameDefault(){return"never"}}class hr extends p{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??ct;let u=0,o=0;for(const a in e){if(!Object.prototype.hasOwnProperty.call(e,a))continue;const c=[a,e[a]],f=E(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"+Mt(this._args)}}class mr extends p{_hasExpected=!1;_expected=void 0;get expected(){return this._expected}set expected(e){this._expected=e,this._hasExpected=!0}match(e){const r=E(e,this._expected),n=[{result:r}];return{result:r.result,nested:n}}nameDefault(){return"ref"}}function k(t){return new Zt({expected:t})}function pr(t){return new Zt({expected:t,matchType:"includes"})}function v(){return new rr}function dr(){return new mr}function yr(t){return new fr({name:t})}function gr(t,e){const r=new nr({expected:e});return t==null?r:A(oe(P(t)||typeof t=="number"?t:J(t)),r).name("array item")}function I(t,e,r){return new sr({name:t,convert:e,expected:r})}function re(t){return new te({expected:t,nonStrict:!0})}function ne(t){return new te({expected:t,nonStrict:!1})}function Tt(t){return new ir(t)}function J(t){return Tt({...t,float:!1})}function br(t){return Tt({...t,float:!0})}function C(t){return new or({expected:t})}function rt(t,e,r=null){if(t instanceof p||e&&(t=e(t,r),t instanceof p))return t;if(t==null)return H();if(Array.isArray(t)){const n=t.map((s,i)=>rt(s,e,i));return k(n)}if(t.constructor===Object){const n={};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=rt(t[s],e,s));return C(n)}return t instanceof L.ValueState?le({...t,value:rt(t.value,e,"value")}):ne(t)}function wr(t){return C(t).set({ignoreExtraKeys:!0})}function It(t){return new ur({pattern:t})}function _r(t){return new ar({expected:t})}function se(t){return I("typeof",e=>e===null?"null":typeof e,t)}function xr(t){return I("constructor",e=>e.constructor,t)}function nt(){return se("boolean")}function H(){return re(null)}function Or(){return ce(H())}function Sr(...t){return new lt({expecteds:t,type:"or",pipe:!1})}function $r(...t){return new lt({expecteds:t,type:"and",pipe:!1})}function ie(...t){return new lt({expecteds:t,type:"or",pipe:!0})}function A(...t){return new lt({expecteds:t,type:"and",pipe:!0})}function j(t,e){return e==null?ie(H(),t):e?t:H()}function oe(t){const e=typeof t=="number"||P(t)?t:J(t??{min:1});return A(k(),I("length",r=>r.length,e)).name("array length")}function Er(t){const e=typeof t=="number"||P(t)?t:J(t??{min:1});return A(It(),I("length",r=>r.length,e)).name("string length")}function Ar(t){return A(C(),t)}function Mr(t){return A(k(),t)}function Tr(t){return A(C(),I("keys",e=>Object.keys(e),t))}function Ir(t){return A(C(),I("values",e=>Object.values(e),t))}function Cr(t){return A(C(),I("entries",e=>Object.entries(e),t))}function ft(t){return new hr({expected:t})}function Nr(t){return ft(k([t,v()]))}function Dr(t){return ft(k([v(),t]))}function kr(t,e){return ft(k([t,e]))}function Rr(t){return A(C(),I("keys not null",e=>Object.keys(e).filter(r=>e[r]!=null),t))}function ue(t){return new cr({expected:t})}function Ur(t){return ue(Object.values(t))}function Ct(t,e){return new lr({matcher:e,name:t})}const jr=Math.ceil(Date.now()-10*365.25*24*60*60*1e3),Pr=Math.ceil(Date.now()+10*365.25*24*60*60*1e3);function W(t){return J({...t,min:t?.min??jr,max:t?.max??Pr}).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 A(k([e.optional?j(W()):W(),r.optional?j(W()):W()]),Ct("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 Lr(t){return ae({...t,common:{min:new Date(2020,0,1).getTime(),max:Date.now()+900*1e3,...t?.common}}).name("range date")}function ce(t){return new ee({expected:t})}function Kr(){return It(/^[\da-f-]{36}|[\da-f]{32}$/i).name("uuid")}function le(t){return C({[Symbol.toStringTag]:j(v()),loading:j(nt()),hasValue:j(nt()),value:v(),hasError:j(nt()),error:v(),...t})}function Vr(t){return t!=null&&typeof t=="string"&&(t=new TextEncoder().encode(t).buffer),Ct("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 Fr(t,e){const r=fe(t.result,e);return r?{actualKey:t.actualKey,expectedKey:t.expectedKey,result:r}:null}function fe(t,e){if(e?!t.result:t.result)return null;t.expected instanceof ee&&(e=!e);let r=null;return t.nested&&t.nested.forEach(n=>{const s=Fr(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 vr(t,e){const r=he(t.result,e+" ");return`${e}${t.actualKey==null?"| ":t.actualKey+": "}${r}`}function he(t,e){if(t.result)return t.expected.toString();let r="";t.nested&&(r=t.nested.map(s=>vr(s,e)).join(`
|
|
13
|
-
`));let n=t.cause||"";return r?(n||(n=P(t.expected)?t.expected.toString(t.actual):""),`${n}
|
|
14
|
-
${r}`):`${n}
|
|
15
|
-
${e}expected: ${P(t.expected)?t.expected.toString(t.actual):t.expected}
|
|
16
|
-
${e}actual: ${at(t.actual)}`}class Br extends Error{constructor(e){super(e)}}function zr(t){return function(r,n){const s=E(t,r);if(s.error)throw s.error;const i=fe(s,!1);if(!i)return;const u=he(i,"");console.log(`[test][check] CheckError:
|
|
17
|
-
`+u);const o=new Br(u);throw n?.(o),o}}function Rt(t){return t.replace(/\W/g,"").toLowerCase()}function me(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 pe(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 de(t){if(t==null)return null;t=t.trim();const e=parseInt(t,10);return isNaN(e)?null:e}function ye(t){if(t==null)return null;t=t.trim();const e=parseFloat(t);return isNaN(e)?null:e}function ht(t,e){const r=me(e),n=Rt(t);for(const[s,i]of r.entries())if(Rt(s)===n)return i;return null}function qr(t,e){return pe(ht(t,e))}function Wr(t,e){return de(ht(t,e))}function Gr(t,e){return ye(ht(t,e))}exports.ConsoleMessageLevel=F;exports.Lazy=He;exports.LazyWithId=Je;exports.LogLevel=At;exports.Random=it;exports.Subject=Et;exports.SubjectWithId=Ze;exports.UNIQUE_PSEUDO_RANDOM_MAX_COUNT=et;exports.alertConsole=qe;exports.alertReplace=Ke;exports.check=zr;exports.consoleIntercept=ze;exports.consoleMessageToString=Be;exports.consoleReplace=$t;exports.convertTimeZone=St;exports.createTaskDelayRetry=Ye;exports.createUniquePseudoRandom=Ce;exports.dateNowUnique=Ne;exports.deepCloneJsonLike=wt;exports.deepEqualJsonLike=G;exports.deepEqualJsonLikeMap=je;exports.equalArray=Pe;exports.escapeHtml=Re;exports.escapeRegExp=Ue;exports.fixStackTrace=We;exports.formatAny=D;exports.formatDate=qt;exports.formatDateFileName=Wt;exports.getConsoleMessages=Gt;exports.getDateInet=De;exports.getNormalizedObject=_t;exports.getRandomFunc=vt;exports.getRandomSeed=Ee;exports.getStackTrace=Ht;exports.isObservable=Qe;exports.match=E;exports.matchAnd=$r;exports.matchAndPipe=A;exports.matchAny=v;exports.matchArray=k;exports.matchArrayBuffer=Vr;exports.matchArrayIncludes=pr;exports.matchArrayItem=gr;exports.matchArrayLength=oe;exports.matchArrayWith=Mr;exports.matchBoolean=nt;exports.matchConstructor=xr;exports.matchConvert=I;exports.matchCustom=Ct;exports.matchDeep=rt;exports.matchEnum=Ur;exports.matchFloat=br;exports.matchIn=ue;exports.matchInstanceOf=_r;exports.matchInt=J;exports.matchIntDate=W;exports.matchIs=ne;exports.matchIsNonStrict=re;exports.matchNever=yr;exports.matchNot=ce;exports.matchNotNullish=Or;exports.matchNullish=H;exports.matchNumber=Tt;exports.matchObject=C;exports.matchObjectEntries=Cr;exports.matchObjectEntry=ft;exports.matchObjectKey=Nr;exports.matchObjectKeyValue=kr;exports.matchObjectKeys=Tr;exports.matchObjectKeysNotNull=Rr;exports.matchObjectPartial=wr;exports.matchObjectValue=Dr;exports.matchObjectValues=Ir;exports.matchObjectWith=Ar;exports.matchOptional=j;exports.matchOr=Sr;exports.matchOrPipe=ie;exports.matchRange=ae;exports.matchRangeDate=Lr;exports.matchRef=dr;exports.matchString=It;exports.matchStringLength=Er;exports.matchTypeOf=se;exports.matchUuid=Kr;exports.matchValueState=le;exports.max=Ft;exports.min=Vt;exports.minMax=xe;exports.numberMod=Oe;exports.randomBoolean=Ae;exports.randomEnum=Ie;exports.randomFloat=xt;exports.randomIndexWeighted=Me;exports.randomInt=Bt;exports.randomItem=Ot;exports.randomItems=Te;exports.setFuncName=Le;exports.sha256=_e;exports.sha256Buffer=Kt;exports.timeoutAbortController=Jt;exports.toHex=jt;exports.truncateString=q;exports.urlGetBoolean=qr;exports.urlGetFloat=Gr;exports.urlGetInt=Wr;exports.urlGetParams=me;exports.urlGetString=ht;exports.urlParamToBoolean=pe;exports.urlParamToFloat=ye;exports.urlParamToInt=de;exports.waitObservable=tr;exports.withConsoleReplace=Ve;exports.withRetry=Xe;exports.withTimeout=Ge;
|