@flemist/simple-utils 1.0.3 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/simple-utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "Simple simple utils",
5
5
  "sideEffects": false,
6
6
  "types": "build/common/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  "require": "./build/node/index.cjs"
35
35
  }
36
36
  },
37
+ "packageManager": "pnpm@10.18.3",
37
38
  "engines": {
38
39
  "node": ">=20"
39
40
  },
@@ -62,6 +63,38 @@
62
63
  "publishConfig": {
63
64
  "access": "public"
64
65
  },
66
+ "scripts": {
67
+ "========================= install =========================": "",
68
+ "_prepublishOnly": "run-p audit lint build test:all && npm login",
69
+ "prepare": "node .husky/install.mjs",
70
+ "install:playwright": "pnpm exec playwright install --with-deps",
71
+ "========================= deploy =========================": "",
72
+ "build": "vite build",
73
+ "========================= lint =========================": "",
74
+ "audit": "pnpm audit --prod",
75
+ "lint:es": "eslint .",
76
+ "lint:es:fix": "eslint --fix .",
77
+ "lint": "run-p lint:es",
78
+ "lint:fix": "run-s lint:es:fix",
79
+ "lint-staged": "lint-staged",
80
+ "check:types": "tsc --noEmit",
81
+ "check": "run-p audit check:types lint",
82
+ "========================= test =========================": "",
83
+ "test:node": "vitest --run --config vite.projects.ts --project node --bail 3",
84
+ "test:browser": "vitest --run --config vite.projects.ts --project browser --bail 3",
85
+ "test:chrome": "vitest --run --config vite.projects.ts --project browser --browser chromium --bail 3",
86
+ "test:all": "vitest --run --config vite.projects.ts --bail 3",
87
+ "test": "run-s test:node test:browser",
88
+ "========================= dev =========================": "",
89
+ "kill-node": "taskkill /F /IM node.exe",
90
+ "kill-java": "taskkill /F /IM java.exe",
91
+ "kill-chrome": "taskkill /F /IM chrome.exe",
92
+ "========================= mcp =========================": "",
93
+ "mcp:playwright": "mcp-server-playwright --port 8002 --host local.host --isolated",
94
+ "mcp:tools": "mcp-project-tools",
95
+ "========================= other =========================": "",
96
+ "dep:fix": "tsx tools/dep-fix.ts"
97
+ },
65
98
  "devDependencies": {
66
99
  "@eslint/compat": "1.2.4",
67
100
  "@eslint/eslintrc": "3.2.0",
@@ -101,37 +134,7 @@
101
134
  "@flemist/priority-queue": "^1.0.1",
102
135
  "@flemist/time-controller": "^1.0.4",
103
136
  "@flemist/time-limits": "^2.0.4",
104
- "picomatch": "^4.0.3",
137
+ "picomatch": "^4.0.4",
105
138
  "tslib": ">=2.8.1"
106
- },
107
- "scripts": {
108
- "========================= install =========================": "",
109
- "install:playwright": "pnpm exec playwright install --with-deps",
110
- "========================= deploy =========================": "",
111
- "build": "vite build",
112
- "========================= lint =========================": "",
113
- "audit": "pnpm audit --prod",
114
- "lint:es": "eslint .",
115
- "lint:es:fix": "eslint --fix .",
116
- "lint": "run-p lint:es",
117
- "lint:fix": "run-s lint:es:fix",
118
- "lint-staged": "lint-staged",
119
- "check:types": "tsc --noEmit",
120
- "check": "run-p audit check:types lint",
121
- "========================= test =========================": "",
122
- "test:node": "vitest --run --config vite.projects.ts --project node --bail 3",
123
- "test:browser": "vitest --run --config vite.projects.ts --project browser --bail 3",
124
- "test:chrome": "vitest --run --config vite.projects.ts --project browser --browser chromium --bail 3",
125
- "test:all": "vitest --run --config vite.projects.ts --bail 3",
126
- "test": "run-s test:node test:browser",
127
- "========================= dev =========================": "",
128
- "kill-node": "taskkill /F /IM node.exe",
129
- "kill-java": "taskkill /F /IM java.exe",
130
- "kill-chrome": "taskkill /F /IM chrome.exe",
131
- "========================= mcp =========================": "",
132
- "mcp:playwright": "mcp-server-playwright --port 8002 --host local.host --isolated",
133
- "========================= other =========================": "",
134
- "mcp:tools": "mcp-project-tools",
135
- "dep:fix": "tsx tools/dep-fix.ts"
136
139
  }
137
- }
140
+ }
@@ -1,11 +0,0 @@
1
- "use strict";const F=require("@flemist/abort-controller-fast"),Z=require("@flemist/async-utils"),$t=require("@flemist/time-controller");let L=null;function At(){if(!L){L=new Array(256);for(let t=0;t<256;t++)L[t]=t.toString(16).padStart(2,"0")}return L}function it(t){const e=At(),r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let n="";for(let o=0,i=r.length;o<i;o++)n+=e[r[o]];return n}let X=null,st=null,q=null,ut=null;function Tt(){X||(X=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]),st=new Uint32Array(64),ut=new TextEncoder,q=new Uint8Array(65536))}function lt(t){if(t==null)return null;Tt();const e=X,r=st,n=ut;let o=q,i;if(typeof t=="string"){const h=t.length*3;o.length<h+128&&(o=q=new Uint8Array(h+128));const c=n.encodeInto(t,o);i=o.subarray(0,c.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 m=i.length,a=m+72>>>6<<6;o.length<a&&(o=q=new Uint8Array(a)),i!==o&&o.set(i),o[m]=128;for(let h=m+1;h<a;h++)o[h]=0;const A=m*8,C=A/4294967296|0,T=A|0;o[a-8]=C>>>24,o[a-7]=C>>>16,o[a-6]=C>>>8,o[a-5]=C,o[a-4]=T>>>24,o[a-3]=T>>>16,o[a-2]=T>>>8,o[a-1]=T;let U=1779033703,u=-1150833019,s=1013904242,l=-1521486534,y=1359893119,d=-1694144372,g=528734635,w=1541459225;for(let h=0;h<a;h+=64){for(let f=0;f<16;f++){const p=h+(f<<2);r[f]=o[p]<<24|o[p+1]<<16|o[p+2]<<8|o[p+3]}for(let f=16;f<64;f++){const p=r[f-15],$=r[f-2],b=(p>>>7|p<<25)^(p>>>18|p<<14)^p>>>3,D=($>>>17|$<<15)^($>>>19|$<<13)^$>>>10;r[f]=r[f-16]+b+r[f-7]+D|0}let c=U,_=u,N=s,H=l,O=y,P=d,k=g,W=w;for(let f=0;f<64;f+=4)for(let p=0;p<4;p++){const $=f+p,b=(O>>>6|O<<26)^(O>>>11|O<<21)^(O>>>25|O<<7),D=W+b+(k^O&(P^k))+e[$]+r[$]|0,Ut=((c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10))+(c&_^N&(c^_))|0;W=k,k=P,P=O,O=H+D|0,H=N,N=_,_=c,c=D+Ut|0}U=U+c|0,u=u+_|0,s=s+N|0,l=l+H|0,y=y+O|0,d=d+P|0,g=g+k|0,w=w+W|0}const S=new Uint8Array(32),G=[U,u,s,l,y,d,g,w];for(let h=0;h<8;h++){const c=G[h],_=h<<2;S[_]=c>>>24,S[_+1]=c>>>16&255,S[_+2]=c>>>8&255,S[_+3]=c&255}return S}function Et(t){const e=lt(t);return e?it(e):null}function at(t,e){return t==null?e:e==null?t:Math.min(t,e)}function ct(t,e){return t==null?e:e==null?t:Math.max(t,e)}function Ct(t,e,r){return ct(at(t,e),r)}function Rt(t,e){return(t%e+e)%e}function It(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 kt(){return Math.random()}function xt(){return Math.random()*2**32>>>0}function ft(t){return t!=null?It(t):kt}class V{_seed;_rnd;constructor(e){this._seed=e,this._rnd=ft(e)}get seed(){return this._seed}nextSeed(){return this.next()*2**32>>>0}nextRandom(){return new V(this.nextSeed())}next(){return this._rnd()}clone(){return new V(this._seed)}}function K(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 ht(t,e,r){return Math.floor(K(t,e,r))}function Mt(t,e){return t.next()<(e??.5)}function Nt(t,e,r){if(Array.isArray(e)){const i=e;e=i.length,r=m=>i[m]}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 o=K(t,n);for(let i=0;i<e;i++)if(o-=r(i),o<0)return i;return e-1}function v(t,e){if(e.length===0)throw new Error("[random][randomItem] items is empty");const r=ht(t,e.length);return e[r]}function Pt(t,e,r){if(e.length===0)throw new Error("[random][randomItems] items is empty");const n=[];for(let o=0;o<r;o++)n.push(v(t,e));return n}function Dt(t,e,r){let n=Object.values(e);return r&&(n=n.filter(r)),v(t,n)}const mt=1073741789,B=(mt>>2)-1;function Lt(t=B,e){if(t<=0)throw new Error(`[random][PseudoRandom] count(${t}) must be > 0`);if(t>B)throw new Error(`[random][PseudoRandom] count(${t}) must be <= ${B}`);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+mt)%t,r}}let x=null;function qt(){const t=Date.now();return x==null||t>x?(x=t,t):(x++,x)}async function Bt({url:t,timeout:e}={}){t||(t=typeof window<"u"?"/":"https://google.com");let r;try{const n=new F.AbortControllerFast;r=e?setTimeout(()=>{n.abort()},e):null;const o=await fetch(t,{method:"HEAD",signal:F.toAbortSignal(n.signal)}),i=o.headers.get("date");if(!i)throw new Error(`[Now][getDateInet] No date header in response: ${o.status} ${t}`);return new Date(i).getTime()}finally{r&&clearTimeout(r)}}function j(t,e,r){const n=e==null?t:new Date(t.toLocaleString("en-US",{timeZone:e})),o=r==null?t:new Date(t.toLocaleString("en-US",{timeZone:r}));return new Date(t.getTime()+o.getTime()-n.getTime())}function dt(t,e){t=j(t,"UTC",e);const r=t.getUTCFullYear().toString().padStart(4,"0"),n=(t.getUTCMonth()+1).toString().padStart(2,"0"),o=t.getUTCDate().toString().padStart(2,"0"),i=t.getUTCHours().toString().padStart(2,"0"),m=t.getUTCMinutes().toString().padStart(2,"0"),a=t.getUTCSeconds().toString().padStart(2,"0");return`${r}-${n}-${o} ${i}:${m}:${a}`}let Ft=0;const J=new WeakMap;function R(t){if(J.has(t))return J.get(t);const e=Ft++;return J.set(t,e),e}function et(t,e){try{return t[e]}catch(r){return"Error: "+(r instanceof Error?r.message:String(r))}}function I(t,e={},r=[],n=new Set){const{pretty:o,filter:i,maxDepth:m,maxItems:a,showObjectId:A,showArrayIndex:C,customToString:T}=e;if(T){const u=T(t,s=>I(s,e,r,n));if(u!=null)return u}const U=r.length;if(typeof t=="string")return JSON.stringify(t);if(t==null||typeof t!="object")return String(t);if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return`${t.constructor?.name??""}#${R(t)}[${t.byteLength}]`;if(t instanceof RegExp)return String(t);if(t instanceof Date)return dt(t);if(t instanceof Object){if(n.has(t)||m!=null&&U>=m)return`${t.constructor===Object?"":t.constructor?.name??""}#${R(t)}`;n.add(t)}if(t instanceof Error)return t.stack||t.message||String(t);if(Array.isArray(t)){const u=o?" ".repeat(U):"";let s="";A&&(s+=`#${R(t)} `),s+="[";let l=0,y=!1;for(let d=0;d<t.length;d++){if(a!=null&&l>=a){y=!0;break}const g=[...r,String(d)],w=et(t,d);if(i!=null&&!i(g,w))continue;const S=I(w,e,g,n);l>0&&(s+=","),o&&(s+=`
2
- `),o&&(s+=`${u} `),C&&(s+=`${d}: `),s+=`${S}`,l++}return y?(l>0&&(s+=","),o?(s+=`
3
- `,s+=`${u} ...
4
- `):s+="...",s+=u,s+="]"):(l>0&&o&&(s+=`
5
- ${u}`),s+="]"),s}if(t instanceof Map){let u="";return A&&(u+=`#${R(t)} `),u+="Map",u+=I(Array.from(t.entries()),e,r,n),u}if(t instanceof Set){let u="";return A&&(u+=`#${R(t)} `),u+="Set",u+=I(Array.from(t.values()),e,r,n),u}{const u=t.constructor===Object?"":t.constructor?.name??"",s=o?" ".repeat(U):"";let l=u?`${u} `:"";A&&(l+=`#${R(t)} `),l+="{";let y=0,d=!1;for(const g in t){if(a!=null&&y>=a){d=!0;break}const w=[...r,g],S=et(t,g);if(i!=null&&!i(w,S))continue;const G=I(S,e,w,n);y>0&&(l+=","),o&&(l+=`
6
- `),o&&(l+=`${s} `),l+=`${g}: ${G}`,y++}return d&&(y>0&&(l+=","),o?(l+=`
7
- `,l+=`${s} ...
8
- `):l+="...",l+=s),y>0&&o&&!d&&(l+=`
9
- ${s}`),l+="}",l}}function Vt(t,e){t=j(t,"UTC",e);const r=t.getUTCFullYear().toString().padStart(4,"0"),n=(t.getUTCMonth()+1).toString().padStart(2,"0"),o=t.getUTCDate().toString().padStart(2,"0"),i=t.getUTCHours().toString().padStart(2,"0"),m=t.getUTCMinutes().toString().padStart(2,"0"),a=t.getUTCSeconds().toString().padStart(2,"0");return`${r}-${n}-${o}_${i}-${m}-${a}`}function zt(t){return t==null?null:t.replace(/[&<>"']/g,e=>{switch(e){case"&":return"&amp;";case"<":return"&lt;";case">":return"&rt;";case'"':return"&quot;";default:return"&#039;"}})}function Gt(t){return t==null?null:t?.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&")}function Y(t){if(t==null)return null;if(Array.isArray(t)){const e=t.length,r=[];for(let n=0;n<e;n++)r.push(Y(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]=Y(t[r]));return e}return t}function M(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(!M(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)&&!M(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)&&!M(e[r],null))return!1;return!0}return!1}function Ht(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(!M(n,e.get(r)))return!1;return!0}function Wt(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 Q(t){return!t||typeof t!="object"?t:Array.isArray(t)?t.map(Q):t&&Object.keys(t).sort().reduce((e,r)=>{const n=Q(t[r]);return n!=null&&(e[r]=n),e},{})}function bt(t){const e=alert;return window.alert=r=>t(e,r),()=>{window.alert=e}}var tt=(t=>(t.log="log",t.warn="warn",t.error="error",t.info="info",t.debug="debug",t.trace="trace",t.assert="assert",t))(tt||{});const rt=Object.values(tt);function E(t){return function(){t.apply(console,arguments)}}const nt={log:E(console.log),warn:E(console.warn),error:E(console.error),info:E(console.info),debug:E(console.debug),trace:E(console.trace),assert:E(console.assert)};function pt(t){return rt.forEach(e=>{console[e]=(...r)=>{t(nt,e,r)}}),()=>{rt.forEach(e=>{console[e]=nt[e]})}}function Jt(t){return function(r){const n=pt(t);try{const o=r();return Z.isPromiseLike(o)?o.then(i=>(n(),i),i=>{throw n(),i}):o}finally{n()}}}function yt(){let t=new Error().stack;if(t!=null){const e=t.indexOf(`
10
- `);e!=null&&e>=0&&(t=t.substring(e+1))}return t??""}function Xt(t){return function(...e){const r=yt();try{return t.apply(this,e)}catch(n){throw n instanceof Error||(n=new Error(String(n))),n.stack=n.stack?n.stack+`
11
- `+r:r,n}}}function gt(t){if(!t||t.timeout==null)return null;const e=new F.AbortControllerFast,r=t.timeController??$t.timeControllerDefault;if(t.timeout){const n=r.setTimeout(()=>{e.abort(new F.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 Yt(t,e){const r=gt(e);try{return await t(r?.signal??e?.abortSignal??null)}finally{r?.abort()}}class Qt{_options;_hasValue=!1;_promiseOrValue=null;constructor(e){this._options=e}run(){if(!this._hasValue){let e=this._options.func();const r=o=>(this._options.persist?this._promiseOrValue=o:(this._promiseOrValue=null,this._hasValue=!1),o),n=o=>{throw this._options.persist||(this._promiseOrValue=null,this._hasValue=!1),o};if(Z.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 Zt{_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),o=i=>{throw this._options.persist||this._promiseOrValues.delete(e),i};if(Z.isPromiseLike(r))r=r.then(n,o);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)}}function ot(t){return t.replace(/\W/g,"").toLowerCase()}function wt(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 St(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 _t(t){if(t==null)return null;t=t.trim();const e=parseInt(t,10);return isNaN(e)?null:e}function Ot(t){if(t==null)return null;t=t.trim();const e=parseFloat(t);return isNaN(e)?null:e}function z(t,e){const r=wt(e),n=ot(t);for(const[o,i]of r.entries())if(ot(o)===n)return i;return null}function Kt(t,e){return St(z(t,e))}function vt(t,e){return _t(z(t,e))}function jt(t,e){return Ot(z(t,e))}exports.ConsoleMessageLevel=tt;exports.Lazy=Qt;exports.LazyWithId=Zt;exports.Random=V;exports.UNIQUE_PSEUDO_RANDOM_MAX_COUNT=B;exports.alertReplace=bt;exports.consoleReplace=pt;exports.convertTimeZone=j;exports.createUniquePseudoRandom=Lt;exports.dateNowUnique=qt;exports.deepCloneJsonLike=Y;exports.deepEqualJsonLike=M;exports.deepEqualJsonLikeMap=Ht;exports.equalArray=Wt;exports.escapeHtml=zt;exports.escapeRegExp=Gt;exports.fixStackTrace=Xt;exports.formatAny=I;exports.formatDate=dt;exports.formatDateFileName=Vt;exports.getDateInet=Bt;exports.getNormalizedObject=Q;exports.getRandomFunc=ft;exports.getRandomSeed=xt;exports.getStackTrace=yt;exports.max=ct;exports.min=at;exports.minMax=Ct;exports.numberMod=Rt;exports.randomBoolean=Mt;exports.randomEnum=Dt;exports.randomFloat=K;exports.randomIndexWeighted=Nt;exports.randomInt=ht;exports.randomItem=v;exports.randomItems=Pt;exports.sha256=Et;exports.sha256Buffer=lt;exports.timeoutAbortController=gt;exports.toHex=it;exports.urlGetBoolean=Kt;exports.urlGetFloat=jt;exports.urlGetInt=vt;exports.urlGetParams=wt;exports.urlGetString=z;exports.urlParamToBoolean=St;exports.urlParamToFloat=Ot;exports.urlParamToInt=_t;exports.withConsoleReplace=Jt;exports.withTimeout=Yt;