@pivanov/utils 0.0.3 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -335
- package/dist/cjs/assertion/index.js +7 -0
- package/dist/cjs/cache/index.js +7 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/object/index.js +7 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/promise/index.js +7 -0
- package/dist/cjs/string/index.js +7 -0
- package/dist/cjs/tools/index.js +7 -0
- package/dist/cjs/types/index.js +7 -0
- package/dist/esm/assertion/index.js +7 -0
- package/dist/esm/cache/index.js +7 -0
- package/dist/esm/chunk-3ymwkv74.js +8 -0
- package/dist/esm/chunk-jtvcg9xg.js +6 -0
- package/dist/esm/chunk-m1ymbxy0.js +8 -0
- package/dist/esm/chunk-m7vtwv05.js +8 -0
- package/dist/esm/chunk-vtcj34cd.js +8 -0
- package/dist/esm/chunk-y84wjyfx.js +7 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/object/index.js +7 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/promise/index.js +7 -0
- package/dist/esm/string/index.js +7 -0
- package/dist/esm/tools/index.js +7 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/types/assertion/index.d.ts +145 -0
- package/dist/types/cache/index.d.ts +16 -0
- package/dist/types/cache/internal.d.ts +12 -0
- package/dist/types/cache/response.d.ts +91 -0
- package/dist/types/cache/storage.d.ts +75 -0
- package/dist/types/cache/support.d.ts +14 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/object/index.d.ts +118 -0
- package/dist/types/promise/index.d.ts +81 -0
- package/dist/types/string/index.d.ts +127 -0
- package/dist/types/tools/deepClone.d.ts +2 -0
- package/dist/types/tools/dom.d.ts +82 -0
- package/dist/types/tools/eventBus/eventBus.d.ts +37 -0
- package/dist/types/tools/eventBus/index.d.ts +3 -0
- package/dist/types/tools/eventBus/types.d.ts +47 -0
- package/dist/types/tools/eventBus/useEventBus.d.ts +3 -0
- package/dist/types/tools/index.d.ts +5 -0
- package/dist/types/tools/isEqual.d.ts +21 -0
- package/dist/types/types/index.d.ts +61 -0
- package/package.json +74 -35
- package/dist/index.d.ts +0 -691
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var{defineProperty:L,getOwnPropertyNames:Z,getOwnPropertyDescriptor:_}=Object,$=Object.prototype.hasOwnProperty;function z(q){return this[q]}var U=(q)=>{var F=(T??=new WeakMap).get(q),G;if(F)return F;if(F=L({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var H of Z(q))if(!$.call(F,H))L(F,H,{get:z.bind(q,H),enumerable:!(G=_(q,H))||G.enumerable})}return T.set(q,F),F},T;var A=(q)=>q;function B(q,F){this[q]=A.bind(null,F)}var W=(q,F)=>{for(var G in F)L(q,G,{get:F[G],enumerable:!0,configurable:!0,set:B.bind(F,G)})};var p={};W(p,{isUndefined:()=>f,isString:()=>N,isSet:()=>g,isRegExp:()=>E,isRecord:()=>R,isPromise:()=>h,isPrimitive:()=>m,isObject:()=>K,isNumber:()=>D,isNull:()=>O,isNil:()=>S,isMap:()=>d,isFunction:()=>P,isError:()=>V,isEmpty:()=>n,isDefined:()=>w,isDate:()=>M,isBoolean:()=>C,isArray:()=>x});module.exports=U(p);var C=(q)=>{return typeof q==="boolean"},D=(q)=>{return typeof q==="number"},N=(q)=>{return typeof q==="string"},P=(q)=>{return typeof q==="function"},K=(q)=>{if(q===null||typeof q!=="object")return!1;let F=Object.getPrototypeOf(q);return F===Object.prototype||F===null},R=(q)=>{return typeof q==="object"&&q!==null},f=(q)=>{return q===void 0},O=(q)=>{return q===null},S=(q)=>{return q===null||q===void 0},w=(q)=>{return q!==void 0},x=(q)=>{return Array.isArray(q)},M=(q)=>{return q instanceof Date},E=(q)=>{return q instanceof RegExp},V=(q)=>{return q instanceof Error},h=(q)=>{return q!==null&&(typeof q==="object"||typeof q==="function")&&typeof q.then==="function"},d=(q)=>{return q instanceof Map},g=(q)=>{return q instanceof Set},m=(q)=>{if(q===null||q===void 0)return!0;let F=typeof q;return F==="string"||F==="number"||F==="boolean"||F==="bigint"||F==="symbol"},n=(q)=>{if(q===null||q===void 0)return!0;if(typeof q==="string"||Array.isArray(q))return q.length===0;if(q instanceof Map||q instanceof Set)return q.size===0;if(typeof q==="object")return Object.keys(q).length===0;return!1};var u={};W(u,{pickBy:()=>X,pick:()=>i,omitBy:()=>j,omit:()=>k,merge:()=>a,mapValues:()=>y,mapKeys:()=>b,keysOf:()=>r,invert:()=>o,hasOwn:()=>s,groupBy:()=>c,fromEntries:()=>l,entriesOf:()=>v,deepMerge:()=>Y});module.exports=U(u);var k=(q,F)=>{let G={...q};for(let H of F)delete G[H];return G},i=(q,F)=>{let G={};for(let H of F)if(H in q)G[H]=q[H];return G},X=(q,F)=>{let G={};for(let H of Object.keys(q))if(F(q[H],H))G[H]=q[H];return G},j=(q,F)=>{return X(q,(G,H)=>!F(G,H))},y=(q,F)=>{let G={};for(let H of Object.keys(q))G[H]=F(q[H],H);return G},b=(q,F)=>{let G={};for(let H of Object.keys(q))G[F(q[H],H)]=q[H];return G},c=(q,F)=>{let G={};return q.forEach((H,J)=>{let I=F(H,J);if(G[I])G[I].push(H);else G[I]=[H]}),G},o=(q)=>{let F={};for(let G of Object.keys(q))F[q[G]]=G;return F},s=(q,F)=>{return Object.hasOwn(q,F)},r=(q)=>{return Object.keys(q)},v=(q)=>{return Object.entries(q)},l=(q)=>{return Object.fromEntries(q)},a=(q,...F)=>{return Object.assign({},q,...F)},Y=(q,...F)=>{let G={...q};for(let H of F){if(H===void 0)continue;for(let J of Object.keys(H)){let I=H[J],Q=G[J];if(K(I))G[J]=Y(K(Q)?Q:{},I);else G[J]=I}}return G};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var{defineProperty:J,getOwnPropertyNames:Q,getOwnPropertyDescriptor:S}=Object,T=Object.prototype.hasOwnProperty;function U(q){return this[q]}var V=(q)=>{var z=(O??=new WeakMap).get(q),C;if(z)return z;if(z=J({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var B of Q(q))if(!T.call(z,B))J(z,B,{get:U.bind(q,B),enumerable:!(C=S(q,B))||C.enumerable})}return O.set(q,z),z},O;var W=(q)=>q;function X(q,z){this[q]=W.bind(null,z)}var Y=(q,z)=>{for(var C in z)J(q,C,{get:z[C],enumerable:!0,configurable:!0,set:X.bind(z,C)})};var M={};Y(M,{timeout:()=>Z,sleep:()=>P,retry:()=>_,parallelLimit:()=>L,defer:()=>$});module.exports=V(M);var P=(q,z)=>{return new Promise((C,B)=>{if(z?.aborted){B(z.reason);return}let D=setTimeout(()=>{z?.removeEventListener("abort",G),C()},q),G=()=>{clearTimeout(D),B(z?.reason)};z?.addEventListener("abort",G,{once:!0})})},Z=(q,z,C)=>{return new Promise((B,D)=>{let G=setTimeout(()=>{D(C??Error(`Operation timed out after ${z}ms`))},z);q.then((H)=>{clearTimeout(G),B(H)},(H)=>{clearTimeout(G),D(H)})})},_=async(q,z={})=>{let{attempts:C=3,backoff:B=0,signal:D,shouldRetry:G}=z,H;for(let F=1;F<=C;F++){if(D?.aborted)throw D.reason;try{return await q(F)}catch(K){if(H=K,F>=C)break;if(G&&!G(K,F))break;let N=typeof B==="function"?B(F):B;if(N>0)await P(N,D)}}throw H},$=()=>{let q,z;return{promise:new Promise((B,D)=>{q=B,z=D}),resolve:q,reject:z}},L=async(q,z,C)=>{if(z<1)throw Error("parallelLimit: concurrency must be >= 1");let B=Array(q.length),D=0,G=async()=>{while(!0){let F=D++;if(F>=q.length)return;B[F]=await C(q[F],F)}},H=Array.from({length:Math.min(z,q.length)},G);return await Promise.all(H),B};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var{defineProperty:u,getOwnPropertyNames:z,getOwnPropertyDescriptor:B}=Object,D=Object.prototype.hasOwnProperty;function F(d){return this[d]}var G=(d)=>{var f=(v??=new WeakMap).get(d),j;if(f)return f;if(f=u({},"__esModule",{value:!0}),d&&typeof d==="object"||typeof d==="function"){for(var q of z(d))if(!D.call(f,q))u(f,q,{get:F.bind(d,q),enumerable:!(j=B(d,q))||j.enumerable})}return v.set(d,f),f},v;var I=(d)=>d;function J(d,f){this[d]=I.bind(null,f)}var K=(d,f)=>{for(var j in f)u(d,j,{get:f[j],enumerable:!0,configurable:!0,set:J.bind(f,j)})};var H={};K(H,{words:()=>y,uncapitalize:()=>Y,truncate:()=>Z,titleCase:()=>V,snakeCase:()=>U,slugify:()=>W,pascalCase:()=>O,lines:()=>C,kebabCase:()=>R,escapeRegExp:()=>o,escapeHtml:()=>k,capitalizeFirstLetter:()=>Q,capitalize:()=>X,camelCase:()=>N});module.exports=G(H);var N=(d)=>{return d.trim().toLowerCase().replace(/^[-_\s]+/,"").replace(/[-_\s]+(.)?/g,(f,j)=>j?j.toUpperCase():"")},O=(d)=>{return d.split(/(?=[0-9])|(?<=[0-9])|[^a-zA-Z0-9]+/g).filter(Boolean).map((f)=>f.toLowerCase()).map((f)=>`${f.charAt(0).toUpperCase()}${f.slice(1)}`).join("")},Q=(d)=>d.charAt(0).toUpperCase()+d.slice(1),R=(d)=>{if(d==null)return d;return d.normalize("NFKD").replace(/\p{Diacritic}/gu,"").replace(/[^\w\s-]/g," ").replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z][a-z])/g,"$1-$2").replace(/[-_\s]+/g,"-").toLowerCase().replace(/^-+|-+$/g,"").trim()},U=(d)=>{if(d==null)return d;return d.normalize("NFKD").replace(/\p{Diacritic}/gu,"").replace(/[^\w\s-]/g," ").replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z])([A-Z][a-z])/g,"$1_$2").replace(/[-_\s]+/g,"_").toLowerCase().replace(/^_+|_+$/g,"").trim()},V=(d)=>{return d.normalize("NFKD").replace(/[^\w\s-]/g," ").split(/[-_\s]+/).filter(Boolean).map((f)=>f.charAt(0).toUpperCase()+f.slice(1).toLowerCase()).join(" ")},W=(d)=>{return d.normalize("NFKD").toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[-\s_]+/g,"-").replace(/^-+|-+$/g,"")},X=(d)=>{return d.charAt(0).toUpperCase()+d.slice(1)},Y=(d)=>{return d.charAt(0).toLowerCase()+d.slice(1)},Z=(d,f,j="…")=>{if(d.length<=f)return d;if(f<=j.length)return j.slice(0,f);return d.slice(0,f-j.length)+j},$={"&":"&","<":"<",">":">",'"':""","'":"'"},k=(d)=>{return d.replace(/[&<>"']/g,(f)=>$[f])},o=(d)=>{return d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},y=(d)=>{return d.split(/[-_\s]+/).filter(Boolean)},C=(d)=>{return d.split(/\r\n|\r|\n/)};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var{defineProperty:D,getOwnPropertyNames:n,getOwnPropertyDescriptor:o}=Object,t=Object.prototype.hasOwnProperty;function s(J){return this[J]}var a=(J)=>{var Q=(j??=new WeakMap).get(J),X;if(Q)return Q;if(Q=D({},"__esModule",{value:!0}),J&&typeof J==="object"||typeof J==="function"){for(var Y of n(J))if(!t.call(Q,Y))D(Q,Y,{get:s.bind(J,Y),enumerable:!(X=o(J,Y))||X.enumerable})}return j.set(J,Q),Q},j;var e=(J)=>J;function JJ(J,Q){this[J]=e.bind(null,Q)}var QJ=(J,Q)=>{for(var X in Q)D(J,X,{get:Q[X],enumerable:!0,configurable:!0,set:JJ.bind(Q,X)})};var CJ={};QJ(CJ,{useEventBus:()=>vJ,stringifyBigIntValues:()=>p,storageSetItemWithTTL:()=>AJ,storageSetItem:()=>h,storageRemoveItem:()=>b,storageGetItemWithTTL:()=>OJ,storageGetItem:()=>l,storageGetAllKeys:()=>EJ,storageExists:()=>IJ,storageClearBySuffix:()=>HJ,storageClearByPrefixOrSuffix:()=>f,storageClearByPrefix:()=>WJ,storageClear:()=>RJ,storageCalculateSize:()=>SJ,setStyleProperties:()=>zJ,isInViewport:()=>wJ,isEqual:()=>gJ,isCacheStorageSupported:()=>x,isBrowser:()=>PJ,deepClone:()=>TJ,checkVisibility:()=>KJ,calculateRenderedTextWidth:()=>qJ,cacheResponseKeys:()=>GJ,cachePutResponse:()=>XJ,cacheNames:()=>FJ,cacheMatchResponse:()=>YJ,cacheHasResponse:()=>_J,cacheExists:()=>BJ,cacheDeleteResponse:()=>ZJ,cacheDelete:()=>UJ,cacheClear:()=>$J,busSubscribe:()=>w,busOnce:()=>NJ,busDispatch:()=>fJ,__resetTextMeasurementCache:()=>LJ});module.exports=a(CJ);var x=()=>{return typeof caches<"u"};var K=()=>{if(!x())throw Error("[@pivanov/utils/cache] Cache Storage is not available in this environment.");return caches},R=(J)=>{return K().open(J)},P=(J)=>{if(J.startsWith("http://")||J.startsWith("https://"))return J;return`https://cache.internal/${J}`};var XJ=async(J,Q,X)=>{if(X.bodyUsed)throw TypeError("[@pivanov/utils/cache] cachePutResponse received a Response whose body has already been consumed.");await(await R(J)).put(Q,X.clone())},YJ=async(J,Q,X)=>{return(await R(J)).match(Q,X)},ZJ=async(J,Q,X)=>{return(await R(J)).delete(Q,X)},_J=async(J,Q,X)=>{return await(await R(J)).match(Q,X)!==void 0},GJ=async(J)=>{return(await(await R(J)).keys()).map((Y)=>Y.url)},$J=async(J)=>{let Q=await R(J),X=await Q.keys();await Promise.all(X.map((Y)=>Q.delete(Y)))},FJ=async()=>{return K().keys()},BJ=async(J)=>{return K().has(J)},UJ=async(J)=>{return K().delete(J)};var p=(J,Q)=>{return typeof Q==="bigint"?Q.toString():Q},h=async(J,Q,X)=>{let Y=await R(J),G=JSON.stringify(X,p),B=new Response(G,{headers:{"Content-Type":"application/json"}}),$=P(Q);await Y.put(new Request($),B)},l=async(J,Q)=>{let X=await R(J),Y=P(Q),G=await X.match(new Request(Y));if(!G)return null;let B=await G.text();return JSON.parse(B)},MJ=(J)=>{return typeof J==="object"&&J!==null&&J.__ttl===!0&&typeof J.exp==="number"},AJ=async(J,Q,X,Y)=>{let G={__ttl:!0,v:X,exp:Date.now()+Y};await h(J,Q,G)},OJ=async(J,Q)=>{let X=await l(J,Q);if(!MJ(X))return null;if(Date.now()>=X.exp)return await b(J,Q),null;return X.v},b=async(J,Q)=>{let X=await R(J),Y=P(Q);return X.delete(new Request(Y))},RJ=async(J)=>{let Q=await R(J),X=await Q.keys();for(let Y of X)await Q.delete(Y)},f=async(J,Q,X=!0)=>{let Y=await R(J),G=await Y.keys();for(let B of G){let $=B.url.split("/"),W=$[$.length-1]||"";if(X&&W.startsWith(Q)||!X&&W.endsWith(Q))await Y.delete(B)}},WJ=async(J,Q)=>{await f(J,Q,!0)},HJ=async(J,Q)=>{await f(J,Q,!1)},IJ=async(J,Q)=>{let X=await R(J),Y=P(Q);return await X.match(new Request(Y))!==void 0},EJ=async(J)=>{return(await(await R(J)).keys()).map((Y)=>{let G=Y.url.split("/");return G[G.length-1]||""})},SJ=async(J,Q)=>{let X=await R(J);if(Q){let B=P(Q),$=await X.match(new Request(B));if($)return(await $.clone().arrayBuffer()).byteLength;return 0}let Y=await X.keys(),G=0;for(let B of Y){let $=await X.match(B);if($){let W=await $.clone().arrayBuffer();G+=W.byteLength}}return G};var TJ=(J)=>{return M(J,new WeakMap)},M=(J,Q)=>{if(J===null||typeof J!=="object")return J;let X=Q.get(J);if(X)return X;if(Array.isArray(J)){let Z=J.length;if(Z<32){let _=Array(Z);Q.set(J,_);for(let U=0;U<Z;U++)if(U in J)_[U]=M(J[U],Q);return _}let F=Array(Z);if(Q.set(J,F),Object.keys(J).length===Z){let _=0,U=Z%8,O=Z-U;while(_<O)F[_]=M(J[_],Q),F[_+1]=M(J[_+1],Q),F[_+2]=M(J[_+2],Q),F[_+3]=M(J[_+3],Q),F[_+4]=M(J[_+4],Q),F[_+5]=M(J[_+5],Q),F[_+6]=M(J[_+6],Q),F[_+7]=M(J[_+7],Q),_+=8;while(_<Z)F[_]=M(J[_],Q),_++}else for(let _=0;_<Z;_++)if(_ in J)F[_]=M(J[_],Q);return F}if(J instanceof Date||J instanceof RegExp)return new J.constructor(J);if(typeof Buffer<"u")try{if(Buffer.isBuffer(J))return Buffer.from(J)}catch(Z){if(Z instanceof Error)throw Z}if(ArrayBuffer.isView(J)){let Z=J.constructor;if("buffer"in J){let _=J,U=_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);return new Z(U)}return new Z(new ArrayBuffer(J.byteLength))}if(J instanceof ArrayBuffer)return J.slice(0);if(J&&typeof J==="object"&&"buffer"in J&&"byteLength"in J){let Z=J;if(typeof Buffer>"u"){let _=new Uint8Array(Z.buffer,Z.byteOffset||0,Z.byteLength),U=new Uint8Array(_.length);return U.set(_),U}return{buffer:Z.buffer instanceof ArrayBuffer?Z.buffer.slice(0):new ArrayBuffer(Z.byteLength),byteLength:Z.byteLength,byteOffset:Z.byteOffset||0,length:Z.length||Z.byteLength,BYTES_PER_ELEMENT:Z.BYTES_PER_ELEMENT||1}}if(J instanceof Set){let Z=new Set;Q.set(J,Z);let F=Array.from(J),_=F.length;for(let U=0;U<_;U++)Z.add(M(F[U],Q));return Z}if(J instanceof Map){let Z=new Map;Q.set(J,Z);let F=Array.from(J),_=F.length;for(let U=0;U<_;U++){let[O,S]=F[U];Z.set(O,M(S,Q))}return Z}if(Object.getPrototypeOf(J)===Object.prototype){let Z={};Q.set(J,Z);let F=Object.getOwnPropertySymbols(J),_=F.length;if(_>0)for(let A=0;A<_;A++){let H=F[A],I=Object.getOwnPropertyDescriptor(J,H);if(I?.enumerable)Object.defineProperty(Z,H,I)}let U=Object.getOwnPropertyDescriptors(J),O=Object.keys(J),S=O.length,v=!1;for(let A=0;A<S;A++){let H=U[O[A]];if(H.get||H.set){v=!0;break}}if(v)for(let A=0;A<S;A++){let H=O[A],I=U[H];if(I.enumerable)if(I.get||I.set)Object.defineProperty(Z,H,I);else{let T=M(I.value,Q);Object.defineProperty(Z,H,{...I,value:T})}}else{let A=0,H=S%8,I=S-H;while(A<I){let T=O[A],g=O[A+1],C=O[A+2],d=O[A+3],m=O[A+4],u=O[A+5],k=O[A+6],y=O[A+7],E=J;Z[T]=M(E[T],Q),Z[g]=M(E[g],Q),Z[C]=M(E[C],Q),Z[d]=M(E[d],Q),Z[m]=M(E[m],Q),Z[u]=M(E[u],Q),Z[k]=M(E[k],Q),Z[y]=M(E[y],Q),A+=8}while(A<S){let T=O[A++];Z[T]=M(J[T],Q)}}return Z}let Y=Object.getPrototypeOf(J),G=Object.create(Y);Q.set(J,G);let B=Object.getOwnPropertyDescriptors(J),$=Object.keys(B),W=$.length;for(let Z=0;Z<W;Z++){let F=$[Z],_=B[F];if(!_.enumerable)continue;if(_.get||_.set)Object.defineProperty(G,F,_);else{let U=M(_.value,Q);Object.defineProperty(G,F,{..._,value:U})}}let L=Object.getOwnPropertySymbols(J),q=L.length;for(let Z=0;Z<q;Z++){let F=L[Z],_=Object.getOwnPropertyDescriptor(J,F);if(!_?.enumerable)continue;Object.defineProperty(G,F,_)}return G};var PJ=()=>{return typeof window<"u"&&typeof document<"u"},zJ=(J,Q)=>{if(!J)return;for(let[X,Y]of Object.entries(Q))J.style.setProperty(X,Y)},KJ=(J,Q={})=>{let{checkViewport:X=!0,checkDisplay:Y=!0,checkVisibility:G=!0,checkOpacity:B=!0}=Q;if(!J.isConnected)return!1;if(Y||G||B){let $=window.getComputedStyle(J);if(Y&&$.display==="none")return!1;if(G&&$.visibility!==""&&$.visibility!=="visible")return!1;if(B&&$.opacity!==""){let W=Number.parseFloat($.opacity);if(!Number.isNaN(W)&&W===0)return!1}}if(X){let $=J.getBoundingClientRect();if($.width!==0||$.height!==0){let W=window.innerHeight||document.documentElement.clientHeight,L=window.innerWidth||document.documentElement.clientWidth,q=$.bottom<=0||$.top>=W,Z=$.right<=0||$.left>=L;if(q||Z)return!1}}return!0};var N,z,VJ=()=>{if(z!==void 0)return z;if(typeof document>"u")return z=null,null;return N=document.createElement("canvas"),z=N.getContext("2d"),z},LJ=()=>{N=void 0,z=void 0},wJ=(J,Q={})=>{let{vertical:X=!0,horizontal:Y=!0}=Q,G=J.getBoundingClientRect();if(G.width===0&&G.height===0)return!0;let B=window.innerHeight||document.documentElement.clientHeight,$=window.innerWidth||document.documentElement.clientWidth;if(X&&(G.bottom<=0||G.top>=B))return!1;if(Y&&(G.right<=0||G.left>=$))return!1;return!0},qJ=(J,Q,X=!1,Y='Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"')=>{let G=VJ();if(!G)return 0;let B=X?J.toUpperCase():J;return G.font=`${Q}px ${Y}`,G.measureText(B).width};var DJ=(J,Q="\uD83D\uDE80")=>{let X=0,Y=J+Q;for(let G=0;G<Y.length;G++){let B=Y.charCodeAt(G);X=(X<<5)-X+B,X|=0}return(X>>>0).toString(16)},c=(J)=>{return`${DJ(J)}::${J}`},xJ=(J,Q)=>{return(X)=>{if(!(X instanceof CustomEvent))return;try{J(X.detail)}catch(Y){if(Q)Q(Y);else console.error("Event listener error:",Y)}}},fJ=(J,Q)=>{if(!J)return;let X=c(J);window.dispatchEvent(new CustomEvent(X,{detail:Q,bubbles:!0,cancelable:!1}))},w=(J,Q,X={})=>{if(!J||typeof Q!=="function")return()=>{};let Y=xJ(Q,X.onError),G=c(J);return window.addEventListener(G,Y),()=>window.removeEventListener(G,Y)},NJ=(J,Q,X={})=>{if(!J||typeof Q!=="function")return()=>{};let Y=w(J,(G)=>{Y(),Q(G)},X);return Y};var i=require("react");var vJ=(J,Q,X=[])=>{i.useEffect(()=>{if(!J||typeof Q!=="function")return;return w(J,Q)},[J,Q,...X])};var gJ=(J,Q)=>{return V(J,Q,new WeakMap)},V=(J,Q,X)=>{if(Object.is(J,Q))return!0;if(J instanceof Date&&Q instanceof Date)return J.getTime()===Q.getTime();if(J instanceof RegExp&&Q instanceof RegExp)return J.source===Q.source&&J.flags===Q.flags;if(J instanceof Error&&Q instanceof Error)return J.name===Q.name&&J.message===Q.message;if(J instanceof ArrayBuffer&&Q instanceof ArrayBuffer){if(J.byteLength!==Q.byteLength)return!1;return r(new Uint8Array(J),new Uint8Array(Q))}if(ArrayBuffer.isView(J)&&ArrayBuffer.isView(Q)){if(J.constructor!==Q.constructor)return!1;if(J.byteLength!==Q.byteLength)return!1;let Y=new Uint8Array(J.buffer,J.byteOffset,J.byteLength),G=new Uint8Array(Q.buffer,Q.byteOffset,Q.byteLength);return r(Y,G)}if(typeof J==="object"&&J!==null&&typeof Q==="object"&&Q!==null){let Y=X.get(J);if(Y?.has(Q))return!0;if(Y)Y.add(Q);else X.set(J,new WeakSet([Q]))}if(Array.isArray(J)&&Array.isArray(Q)){if(J.length!==Q.length)return!1;for(let Y=0;Y<J.length;Y++)if(!V(J[Y],Q[Y],X))return!1;return!0}if(J instanceof Set&&Q instanceof Set){if(J.size!==Q.size)return!1;let Y=Array.from(Q);for(let G of J){let B=Y.findIndex(($)=>V(G,$,X));if(B===-1)return!1;Y.splice(B,1)}return!0}if(J instanceof Map&&Q instanceof Map){if(J.size!==Q.size)return!1;for(let[Y,G]of J)if(!Q.has(Y)||!V(G,Q.get(Y),X))return!1;return!0}if(J!==null&&typeof J==="object"&&Q!==null&&typeof Q==="object"){let Y=J,G=Q,B=Object.keys(Y);if(B.length!==Object.keys(G).length)return!1;for(let $ of B)if(!V(Y[$],G[$],X))return!1;return!0}return!1},r=(J,Q)=>{for(let X=0;X<J.length;X++)if(J[X]!==Q[X])return!1;return!0};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var{defineProperty:H,getOwnPropertyNames:K,getOwnPropertyDescriptor:L}=Object,M=Object.prototype.hasOwnProperty;function N(k){return this[k]}var O=(k)=>{var q=(J??=new WeakMap).get(k),z;if(q)return q;if(q=H({},"__esModule",{value:!0}),k&&typeof k==="object"||typeof k==="function"){for(var G of K(k))if(!M.call(q,G))H(q,G,{get:N.bind(k,G),enumerable:!(z=L(k,G))||z.enumerable})}return J.set(k,q),q},J;var Q=(k)=>k;function R(k,q){this[k]=Q.bind(null,q)}var T=(k,q)=>{for(var z in q)H(k,z,{get:q[z],enumerable:!0,configurable:!0,set:R.bind(q,z)})};var S={};module.exports=O(S);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
import{A as m,B as n,C as o,D as p,E as q,F as r,G as s,o as a,p as b,q as c,r as d,s as e,t as f,u as g,v as h,w as i,x as j,y as k,z as l}from"../chunk-vtcj34cd.js";export{g as isUndefined,c as isString,q as isSet,m as isRegExp,f as isRecord,o as isPromise,r as isPrimitive,e as isObject,b as isNumber,h as isNull,i as isNil,p as isMap,d as isFunction,n as isError,s as isEmpty,j as isDefined,l as isDate,a as isBoolean,k as isArray};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var Q=()=>{return typeof caches<"u"};var O=()=>{if(!Q())throw Error("[@pivanov/utils/cache] Cache Storage is not available in this environment.");return caches},A=(b)=>{return O().open(b)},F=(b)=>{if(b.startsWith("http://")||b.startsWith("https://"))return b;return`https://cache.internal/${b}`};var U=async(b,d,w)=>{if(w.bodyUsed)throw TypeError("[@pivanov/utils/cache] cachePutResponse received a Response whose body has already been consumed.");await(await A(b)).put(d,w.clone())},$=async(b,d,w)=>{return(await A(b)).match(d,w)},L=async(b,d,w)=>{return(await A(b)).delete(d,w)},B=async(b,d,w)=>{return await(await A(b)).match(d,w)!==void 0},I=async(b)=>{return(await(await A(b)).keys()).map((R)=>R.url)},V=async(b)=>{let d=await A(b),w=await d.keys();await Promise.all(w.map((R)=>d.delete(R)))},f=async()=>{return O().keys()},g=async(b)=>{return O().has(b)},x=async(b)=>{return O().delete(b)};var X=(b,d)=>{return typeof d==="bigint"?d.toString():d},Y=async(b,d,w)=>{let R=await A(b),T=JSON.stringify(w,X),J=new Response(T,{headers:{"Content-Type":"application/json"}}),j=F(d);await R.put(new Request(j),J)},Z=async(b,d)=>{let w=await A(b),R=F(d),T=await w.match(new Request(R));if(!T)return null;let J=await T.text();return JSON.parse(J)},_=(b)=>{return typeof b==="object"&&b!==null&&b.__ttl===!0&&typeof b.exp==="number"},v=async(b,d,w,R)=>{let T={__ttl:!0,v:w,exp:Date.now()+R};await Y(b,d,T)},K=async(b,d)=>{let w=await Z(b,d);if(!_(w))return null;if(Date.now()>=w.exp)return await D(b,d),null;return w.v},D=async(b,d)=>{let w=await A(b),R=F(d);return w.delete(new Request(R))},i=async(b)=>{let d=await A(b),w=await d.keys();for(let R of w)await d.delete(R)},W=async(b,d,w=!0)=>{let R=await A(b),T=await R.keys();for(let J of T){let j=J.url.split("/"),H=j[j.length-1]||"";if(w&&H.startsWith(d)||!w&&H.endsWith(d))await R.delete(J)}},n=async(b,d)=>{await W(b,d,!0)},p=async(b,d)=>{await W(b,d,!1)},q=async(b,d)=>{let w=await A(b),R=F(d);return await w.match(new Request(R))!==void 0},o=async(b)=>{return(await(await A(b)).keys()).map((R)=>{let T=R.url.split("/");return T[T.length-1]||""})},C=async(b,d)=>{let w=await A(b);if(d){let J=F(d),j=await w.match(new Request(J));if(j)return(await j.clone().arrayBuffer()).byteLength;return 0}let R=await w.keys(),T=0;for(let J of R){let j=await w.match(J);if(j){let H=await j.clone().arrayBuffer();T+=H.byteLength}}return T};export{X as stringifyBigIntValues,v as storageSetItemWithTTL,Y as storageSetItem,D as storageRemoveItem,K as storageGetItemWithTTL,Z as storageGetItem,o as storageGetAllKeys,q as storageExists,p as storageClearBySuffix,W as storageClearByPrefixOrSuffix,n as storageClearByPrefix,i as storageClear,C as storageCalculateSize,Q as isCacheStorageSupported,I as cacheResponseKeys,U as cachePutResponse,f as cacheNames,$ as cacheMatchResponse,B as cacheHasResponse,g as cacheExists,L as cacheDeleteResponse,x as cacheDelete,V as cacheClear};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var N=(z,q)=>{return new Promise((G,B)=>{if(q?.aborted){B(q.reason);return}let C=setTimeout(()=>{q?.removeEventListener("abort",F),G()},z),F=()=>{clearTimeout(C),B(q?.reason)};q?.addEventListener("abort",F,{once:!0})})},O=(z,q,G)=>{return new Promise((B,C)=>{let F=setTimeout(()=>{C(G??Error(`Operation timed out after ${q}ms`))},q);z.then((H)=>{clearTimeout(F),B(H)},(H)=>{clearTimeout(F),C(H)})})},P=async(z,q={})=>{let{attempts:G=3,backoff:B=0,signal:C,shouldRetry:F}=q,H;for(let D=1;D<=G;D++){if(C?.aborted)throw C.reason;try{return await z(D)}catch(J){if(H=J,D>=G)break;if(F&&!F(J,D))break;let K=typeof B==="function"?B(D):B;if(K>0)await N(K,C)}}throw H},Q=()=>{let z,q;return{promise:new Promise((B,C)=>{z=B,q=C}),resolve:z,reject:q}},S=async(z,q,G)=>{if(q<1)throw Error("parallelLimit: concurrency must be >= 1");let B=Array(z.length),C=0,F=async()=>{while(!0){let D=C++;if(D>=z.length)return;B[D]=await G(z[D],D)}},H=Array.from({length:Math.min(q,z.length)},F);return await Promise.all(H),B};
|
|
8
|
+
export{N as H,O as I,P as J,Q as K,S as L};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
import{s as F}from"./chunk-vtcj34cd.js";var K=(f,A)=>{let q={...f};for(let z of A)delete q[z];return q},L=(f,A)=>{let q={};for(let z of A)if(z in f)q[z]=f[z];return q},H=(f,A)=>{let q={};for(let z of Object.keys(f))if(A(f[z],z))q[z]=f[z];return q},P=(f,A)=>{return H(f,(q,z)=>!A(q,z))},Q=(f,A)=>{let q={};for(let z of Object.keys(f))q[z]=A(f[z],z);return q},S=(f,A)=>{let q={};for(let z of Object.keys(f))q[A(f[z],z)]=f[z];return q},T=(f,A)=>{let q={};return f.forEach((z,E)=>{let C=A(z,E);if(q[C])q[C].push(z);else q[C]=[z]}),q},U=(f)=>{let A={};for(let q of Object.keys(f))A[f[q]]=q;return A},W=(f,A)=>{return Object.hasOwn(f,A)},X=(f)=>{return Object.keys(f)},Y=(f)=>{return Object.entries(f)},Z=(f)=>{return Object.fromEntries(f)},_=(f,...A)=>{return Object.assign({},f,...A)},I=(f,...A)=>{let q={...f};for(let z of A){if(z===void 0)continue;for(let E of Object.keys(z)){let C=z[E],G=q[E];if(F(C))q[E]=I(F(G)?G:{},C);else q[E]=C}}return q};
|
|
8
|
+
export{K as a,L as b,H as c,P as d,Q as e,S as f,T as g,U as h,W as i,X as j,Y as k,Z as l,_ as m,I as n};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var u=(d)=>{return d.trim().toLowerCase().replace(/^[-_\s]+/,"").replace(/[-_\s]+(.)?/g,(f,j)=>j?j.toUpperCase():"")},v=(d)=>{return d.split(/(?=[0-9])|(?<=[0-9])|[^a-zA-Z0-9]+/g).filter(Boolean).map((f)=>f.toLowerCase()).map((f)=>`${f.charAt(0).toUpperCase()}${f.slice(1)}`).join("")},z=(d)=>d.charAt(0).toUpperCase()+d.slice(1),B=(d)=>{if(d==null)return d;return d.normalize("NFKD").replace(/\p{Diacritic}/gu,"").replace(/[^\w\s-]/g," ").replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z][a-z])/g,"$1-$2").replace(/[-_\s]+/g,"-").toLowerCase().replace(/^-+|-+$/g,"").trim()},D=(d)=>{if(d==null)return d;return d.normalize("NFKD").replace(/\p{Diacritic}/gu,"").replace(/[^\w\s-]/g," ").replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z])([A-Z][a-z])/g,"$1_$2").replace(/[-_\s]+/g,"_").toLowerCase().replace(/^_+|_+$/g,"").trim()},F=(d)=>{return d.normalize("NFKD").replace(/[^\w\s-]/g," ").split(/[-_\s]+/).filter(Boolean).map((f)=>f.charAt(0).toUpperCase()+f.slice(1).toLowerCase()).join(" ")},G=(d)=>{return d.normalize("NFKD").toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[-\s_]+/g,"-").replace(/^-+|-+$/g,"")},I=(d)=>{return d.charAt(0).toUpperCase()+d.slice(1)},J=(d)=>{return d.charAt(0).toLowerCase()+d.slice(1)},K=(d,f,j="…")=>{if(d.length<=f)return d;if(f<=j.length)return j.slice(0,f);return d.slice(0,f-j.length)+j},q={"&":"&","<":"<",">":">",'"':""","'":"'"},N=(d)=>{return d.replace(/[&<>"']/g,(f)=>q[f])},O=(d)=>{return d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Q=(d)=>{return d.split(/[-_\s]+/).filter(Boolean)},R=(d)=>{return d.split(/\r\n|\r|\n/)};
|
|
8
|
+
export{u as M,v as N,z as O,B as P,D as Q,F as R,G as S,I as T,J as U,K as V,N as W,O as X,Q as Y,R as Z};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var D=(q)=>{return typeof q==="boolean"},F=(q)=>{return typeof q==="number"},G=(q)=>{return typeof q==="string"},H=(q)=>{return typeof q==="function"},I=(q)=>{if(q===null||typeof q!=="object")return!1;let B=Object.getPrototypeOf(q);return B===Object.prototype||B===null},J=(q)=>{return typeof q==="object"&&q!==null},K=(q)=>{return q===void 0},L=(q)=>{return q===null},N=(q)=>{return q===null||q===void 0},O=(q)=>{return q!==void 0},Q=(q)=>{return Array.isArray(q)},R=(q)=>{return q instanceof Date},T=(q)=>{return q instanceof RegExp},U=(q)=>{return q instanceof Error},V=(q)=>{return q!==null&&(typeof q==="object"||typeof q==="function")&&typeof q.then==="function"},W=(q)=>{return q instanceof Map},X=(q)=>{return q instanceof Set},Y=(q)=>{if(q===null||q===void 0)return!0;let B=typeof q;return B==="string"||B==="number"||B==="boolean"||B==="bigint"||B==="symbol"},Z=(q)=>{if(q===null||q===void 0)return!0;if(typeof q==="string"||Array.isArray(q))return q.length===0;if(q instanceof Map||q instanceof Set)return q.size===0;if(typeof q==="object")return Object.keys(q).length===0;return!1};
|
|
8
|
+
export{D as o,F as p,G as q,H as r,I as s,J as t,K as u,L as v,N as w,O as x,Q as y,R as z,T as A,U as B,V as C,W as D,X as E,Y as F,Z as G};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var u=()=>{return typeof caches<"u"};var K=()=>{if(!u())throw Error("[@pivanov/utils/cache] Cache Storage is not available in this environment.");return caches},R=(J)=>{return K().open(J)},P=(J)=>{if(J.startsWith("http://")||J.startsWith("https://"))return J;return`https://cache.internal/${J}`};var JJ=async(J,Q,X)=>{if(X.bodyUsed)throw TypeError("[@pivanov/utils/cache] cachePutResponse received a Response whose body has already been consumed.");await(await R(J)).put(Q,X.clone())},QJ=async(J,Q,X)=>{return(await R(J)).match(Q,X)},XJ=async(J,Q,X)=>{return(await R(J)).delete(Q,X)},YJ=async(J,Q,X)=>{return await(await R(J)).match(Q,X)!==void 0},ZJ=async(J)=>{return(await(await R(J)).keys()).map((Y)=>Y.url)},_J=async(J)=>{let Q=await R(J),X=await Q.keys();await Promise.all(X.map((Y)=>Q.delete(Y)))},GJ=async()=>{return K().keys()},$J=async(J)=>{return K().has(J)},FJ=async(J)=>{return K().delete(J)};var p=(J,Q)=>{return typeof Q==="bigint"?Q.toString():Q},h=async(J,Q,X)=>{let Y=await R(J),G=JSON.stringify(X,p),B=new Response(G,{headers:{"Content-Type":"application/json"}}),$=P(Q);await Y.put(new Request($),B)},l=async(J,Q)=>{let X=await R(J),Y=P(Q),G=await X.match(new Request(Y));if(!G)return null;let B=await G.text();return JSON.parse(B)},b=(J)=>{return typeof J==="object"&&J!==null&&J.__ttl===!0&&typeof J.exp==="number"},MJ=async(J,Q,X,Y)=>{let G={__ttl:!0,v:X,exp:Date.now()+Y};await h(J,Q,G)},AJ=async(J,Q)=>{let X=await l(J,Q);if(!b(X))return null;if(Date.now()>=X.exp)return await c(J,Q),null;return X.v},c=async(J,Q)=>{let X=await R(J),Y=P(Q);return X.delete(new Request(Y))},OJ=async(J)=>{let Q=await R(J),X=await Q.keys();for(let Y of X)await Q.delete(Y)},k=async(J,Q,X=!0)=>{let Y=await R(J),G=await Y.keys();for(let B of G){let $=B.url.split("/"),W=$[$.length-1]||"";if(X&&W.startsWith(Q)||!X&&W.endsWith(Q))await Y.delete(B)}},RJ=async(J,Q)=>{await k(J,Q,!0)},WJ=async(J,Q)=>{await k(J,Q,!1)},HJ=async(J,Q)=>{let X=await R(J),Y=P(Q);return await X.match(new Request(Y))!==void 0},IJ=async(J)=>{return(await(await R(J)).keys()).map((Y)=>{let G=Y.url.split("/");return G[G.length-1]||""})},EJ=async(J,Q)=>{let X=await R(J);if(Q){let B=P(Q),$=await X.match(new Request(B));if($)return(await $.clone().arrayBuffer()).byteLength;return 0}let Y=await X.keys(),G=0;for(let B of Y){let $=await X.match(B);if($){let W=await $.clone().arrayBuffer();G+=W.byteLength}}return G};var TJ=(J)=>{return M(J,new WeakMap)},M=(J,Q)=>{if(J===null||typeof J!=="object")return J;let X=Q.get(J);if(X)return X;if(Array.isArray(J)){let Z=J.length;if(Z<32){let _=Array(Z);Q.set(J,_);for(let U=0;U<Z;U++)if(U in J)_[U]=M(J[U],Q);return _}let F=Array(Z);if(Q.set(J,F),Object.keys(J).length===Z){let _=0,U=Z%8,O=Z-U;while(_<O)F[_]=M(J[_],Q),F[_+1]=M(J[_+1],Q),F[_+2]=M(J[_+2],Q),F[_+3]=M(J[_+3],Q),F[_+4]=M(J[_+4],Q),F[_+5]=M(J[_+5],Q),F[_+6]=M(J[_+6],Q),F[_+7]=M(J[_+7],Q),_+=8;while(_<Z)F[_]=M(J[_],Q),_++}else for(let _=0;_<Z;_++)if(_ in J)F[_]=M(J[_],Q);return F}if(J instanceof Date||J instanceof RegExp)return new J.constructor(J);if(typeof Buffer<"u")try{if(Buffer.isBuffer(J))return Buffer.from(J)}catch(Z){if(Z instanceof Error)throw Z}if(ArrayBuffer.isView(J)){let Z=J.constructor;if("buffer"in J){let _=J,U=_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);return new Z(U)}return new Z(new ArrayBuffer(J.byteLength))}if(J instanceof ArrayBuffer)return J.slice(0);if(J&&typeof J==="object"&&"buffer"in J&&"byteLength"in J){let Z=J;if(typeof Buffer>"u"){let _=new Uint8Array(Z.buffer,Z.byteOffset||0,Z.byteLength),U=new Uint8Array(_.length);return U.set(_),U}return{buffer:Z.buffer instanceof ArrayBuffer?Z.buffer.slice(0):new ArrayBuffer(Z.byteLength),byteLength:Z.byteLength,byteOffset:Z.byteOffset||0,length:Z.length||Z.byteLength,BYTES_PER_ELEMENT:Z.BYTES_PER_ELEMENT||1}}if(J instanceof Set){let Z=new Set;Q.set(J,Z);let F=Array.from(J),_=F.length;for(let U=0;U<_;U++)Z.add(M(F[U],Q));return Z}if(J instanceof Map){let Z=new Map;Q.set(J,Z);let F=Array.from(J),_=F.length;for(let U=0;U<_;U++){let[O,S]=F[U];Z.set(O,M(S,Q))}return Z}if(Object.getPrototypeOf(J)===Object.prototype){let Z={};Q.set(J,Z);let F=Object.getOwnPropertySymbols(J),_=F.length;if(_>0)for(let A=0;A<_;A++){let H=F[A],I=Object.getOwnPropertyDescriptor(J,H);if(I?.enumerable)Object.defineProperty(Z,H,I)}let U=Object.getOwnPropertyDescriptors(J),O=Object.keys(J),S=O.length,x=!1;for(let A=0;A<S;A++){let H=U[O[A]];if(H.get||H.set){x=!0;break}}if(x)for(let A=0;A<S;A++){let H=O[A],I=U[H];if(I.enumerable)if(I.get||I.set)Object.defineProperty(Z,H,I);else{let T=M(I.value,Q);Object.defineProperty(Z,H,{...I,value:T})}}else{let A=0,H=S%8,I=S-H;while(A<I){let T=O[A],f=O[A+1],N=O[A+2],v=O[A+3],g=O[A+4],C=O[A+5],d=O[A+6],m=O[A+7],E=J;Z[T]=M(E[T],Q),Z[f]=M(E[f],Q),Z[N]=M(E[N],Q),Z[v]=M(E[v],Q),Z[g]=M(E[g],Q),Z[C]=M(E[C],Q),Z[d]=M(E[d],Q),Z[m]=M(E[m],Q),A+=8}while(A<S){let T=O[A++];Z[T]=M(J[T],Q)}}return Z}let Y=Object.getPrototypeOf(J),G=Object.create(Y);Q.set(J,G);let B=Object.getOwnPropertyDescriptors(J),$=Object.keys(B),W=$.length;for(let Z=0;Z<W;Z++){let F=$[Z],_=B[F];if(!_.enumerable)continue;if(_.get||_.set)Object.defineProperty(G,F,_);else{let U=M(_.value,Q);Object.defineProperty(G,F,{..._,value:U})}}let L=Object.getOwnPropertySymbols(J),w=L.length;for(let Z=0;Z<w;Z++){let F=L[Z],_=Object.getOwnPropertyDescriptor(J,F);if(!_?.enumerable)continue;Object.defineProperty(G,F,_)}return G};var zJ=()=>{return typeof window<"u"&&typeof document<"u"},KJ=(J,Q)=>{if(!J)return;for(let[X,Y]of Object.entries(Q))J.style.setProperty(X,Y)},VJ=(J,Q={})=>{let{checkViewport:X=!0,checkDisplay:Y=!0,checkVisibility:G=!0,checkOpacity:B=!0}=Q;if(!J.isConnected)return!1;if(Y||G||B){let $=window.getComputedStyle(J);if(Y&&$.display==="none")return!1;if(G&&$.visibility!==""&&$.visibility!=="visible")return!1;if(B&&$.opacity!==""){let W=Number.parseFloat($.opacity);if(!Number.isNaN(W)&&W===0)return!1}}if(X){let $=J.getBoundingClientRect();if($.width!==0||$.height!==0){let W=window.innerHeight||document.documentElement.clientHeight,L=window.innerWidth||document.documentElement.clientWidth,w=$.bottom<=0||$.top>=W,Z=$.right<=0||$.left>=L;if(w||Z)return!1}}return!0};var q,z,i=()=>{if(z!==void 0)return z;if(typeof document>"u")return z=null,null;return q=document.createElement("canvas"),z=q.getContext("2d"),z},LJ=()=>{q=void 0,z=void 0},wJ=(J,Q={})=>{let{vertical:X=!0,horizontal:Y=!0}=Q,G=J.getBoundingClientRect();if(G.width===0&&G.height===0)return!0;let B=window.innerHeight||document.documentElement.clientHeight,$=window.innerWidth||document.documentElement.clientWidth;if(X&&(G.bottom<=0||G.top>=B))return!1;if(Y&&(G.right<=0||G.left>=$))return!1;return!0},qJ=(J,Q,X=!1,Y='Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"')=>{let G=i();if(!G)return 0;let B=X?J.toUpperCase():J;return G.font=`${Q}px ${Y}`,G.measureText(B).width};var r=(J,Q="\uD83D\uDE80")=>{let X=0,Y=J+Q;for(let G=0;G<Y.length;G++){let B=Y.charCodeAt(G);X=(X<<5)-X+B,X|=0}return(X>>>0).toString(16)},y=(J)=>{return`${r(J)}::${J}`},n=(J,Q)=>{return(X)=>{if(!(X instanceof CustomEvent))return;try{J(X.detail)}catch(Y){if(Q)Q(Y);else console.error("Event listener error:",Y)}}},xJ=(J,Q)=>{if(!J)return;let X=y(J);window.dispatchEvent(new CustomEvent(X,{detail:Q,bubbles:!0,cancelable:!1}))},D=(J,Q,X={})=>{if(!J||typeof Q!=="function")return()=>{};let Y=n(Q,X.onError),G=y(J);return window.addEventListener(G,Y),()=>window.removeEventListener(G,Y)},fJ=(J,Q,X={})=>{if(!J||typeof Q!=="function")return()=>{};let Y=D(J,(G)=>{Y(),Q(G)},X);return Y};import{useEffect as o}from"react";var CJ=(J,Q,X=[])=>{o(()=>{if(!J||typeof Q!=="function")return;return D(J,Q)},[J,Q,...X])};var mJ=(J,Q)=>{return V(J,Q,new WeakMap)},V=(J,Q,X)=>{if(Object.is(J,Q))return!0;if(J instanceof Date&&Q instanceof Date)return J.getTime()===Q.getTime();if(J instanceof RegExp&&Q instanceof RegExp)return J.source===Q.source&&J.flags===Q.flags;if(J instanceof Error&&Q instanceof Error)return J.name===Q.name&&J.message===Q.message;if(J instanceof ArrayBuffer&&Q instanceof ArrayBuffer){if(J.byteLength!==Q.byteLength)return!1;return j(new Uint8Array(J),new Uint8Array(Q))}if(ArrayBuffer.isView(J)&&ArrayBuffer.isView(Q)){if(J.constructor!==Q.constructor)return!1;if(J.byteLength!==Q.byteLength)return!1;let Y=new Uint8Array(J.buffer,J.byteOffset,J.byteLength),G=new Uint8Array(Q.buffer,Q.byteOffset,Q.byteLength);return j(Y,G)}if(typeof J==="object"&&J!==null&&typeof Q==="object"&&Q!==null){let Y=X.get(J);if(Y?.has(Q))return!0;if(Y)Y.add(Q);else X.set(J,new WeakSet([Q]))}if(Array.isArray(J)&&Array.isArray(Q)){if(J.length!==Q.length)return!1;for(let Y=0;Y<J.length;Y++)if(!V(J[Y],Q[Y],X))return!1;return!0}if(J instanceof Set&&Q instanceof Set){if(J.size!==Q.size)return!1;let Y=Array.from(Q);for(let G of J){let B=Y.findIndex(($)=>V(G,$,X));if(B===-1)return!1;Y.splice(B,1)}return!0}if(J instanceof Map&&Q instanceof Map){if(J.size!==Q.size)return!1;for(let[Y,G]of J)if(!Q.has(Y)||!V(G,Q.get(Y),X))return!1;return!0}if(J!==null&&typeof J==="object"&&Q!==null&&typeof Q==="object"){let Y=J,G=Q,B=Object.keys(Y);if(B.length!==Object.keys(G).length)return!1;for(let $ of B)if(!V(Y[$],G[$],X))return!1;return!0}return!1},j=(J,Q)=>{for(let X=0;X<J.length;X++)if(J[X]!==Q[X])return!1;return!0};export{u as _,JJ as $,QJ as aa,XJ as ba,YJ as ca,ZJ as da,_J as ea,GJ as fa,$J as ga,FJ as ha,p as ia,h as ja,l as ka,MJ as la,AJ as ma,c as na,OJ as oa,k as pa,RJ as qa,WJ as ra,HJ as sa,IJ as ta,EJ as ua,TJ as va,zJ as wa,KJ as xa,VJ as ya,LJ as za,wJ as Aa,qJ as Ba,xJ as Ca,D as Da,fJ as Ea,CJ as Fa,mJ as Ga};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pivanov/utils
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
3
|
* (c) 2024-present Pavel Ivanov
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
* https://github.com/pivanov/utils
|
|
6
6
|
*/
|
|
7
|
-
import{
|
|
7
|
+
import{a as A,b as B,c as C,d as D,e as E,f as F,g as G,h as H,i as I,j as J,k as K,l as L,m as M,n as N}from"./chunk-m1ymbxy0.js";import{A as q,B as s,C as u,D as v,E as w,F as y,G as z,o as x,p as a,q as b,r as c,s as d,t as g,u as h,v as i,w as j,x as k,y as l,z as n}from"./chunk-vtcj34cd.js";import{H as O,I as P,J as Q,K as R,L as S}from"./chunk-3ymwkv74.js";import{M as T,N as U,O as V,P as W,Q as X,R as Y,S as Z,T as _,U as $,V as oo,W as ro,X as eo,Y as fo,Z as mo}from"./chunk-m7vtwv05.js";import{$ as to,Aa as Io,Ba as Jo,Ca as Ko,Da as Lo,Ea as Mo,Fa as No,Ga as Oo,_ as po,aa as xo,ba as ao,ca as bo,da as co,ea as go,fa as ho,ga as io,ha as jo,ia as ko,ja as lo,ka as no,la as qo,ma as so,na as uo,oa as vo,pa as wo,qa as yo,ra as zo,sa as Ao,ta as Bo,ua as Co,va as Do,wa as Eo,xa as Fo,ya as Go,za as Ho}from"./chunk-y84wjyfx.js";import"./chunk-jtvcg9xg.js";export{fo as words,No as useEventBus,$ as uncapitalize,oo as truncate,Y as titleCase,P as timeout,ko as stringifyBigIntValues,qo as storageSetItemWithTTL,lo as storageSetItem,uo as storageRemoveItem,so as storageGetItemWithTTL,no as storageGetItem,Bo as storageGetAllKeys,Ao as storageExists,zo as storageClearBySuffix,wo as storageClearByPrefixOrSuffix,yo as storageClearByPrefix,vo as storageClear,Co as storageCalculateSize,X as snakeCase,Z as slugify,O as sleep,Fo as setStyleProperties,Q as retry,C as pickBy,B as pick,U as pascalCase,S as parallelLimit,D as omitBy,A as omit,M as merge,E as mapValues,F as mapKeys,mo as lines,J as keysOf,W as kebabCase,h as isUndefined,b as isString,w as isSet,q as isRegExp,g as isRecord,u as isPromise,y as isPrimitive,d as isObject,a as isNumber,i as isNull,j as isNil,v as isMap,Io as isInViewport,c as isFunction,s as isError,Oo as isEqual,z as isEmpty,k as isDefined,n as isDate,po as isCacheStorageSupported,Eo as isBrowser,x as isBoolean,l as isArray,H as invert,I as hasOwn,G as groupBy,L as fromEntries,eo as escapeRegExp,ro as escapeHtml,K as entriesOf,R as defer,N as deepMerge,Do as deepClone,Go as checkVisibility,V as capitalizeFirstLetter,_ as capitalize,T as camelCase,Jo as calculateRenderedTextWidth,co as cacheResponseKeys,to as cachePutResponse,ho as cacheNames,xo as cacheMatchResponse,bo as cacheHasResponse,io as cacheExists,ao as cacheDeleteResponse,jo as cacheDelete,go as cacheClear,Lo as busSubscribe,Mo as busOnce,Ko as busDispatch,Ho as __resetTextMeasurementCache};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"../chunk-m1ymbxy0.js";import"../chunk-vtcj34cd.js";export{c as pickBy,b as pick,d as omitBy,a as omit,m as merge,e as mapValues,f as mapKeys,j as keysOf,h as invert,i as hasOwn,g as groupBy,l as fromEntries,k as entriesOf,n as deepMerge};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
import{H as a,I as b,J as c,K as d,L as e}from"../chunk-3ymwkv74.js";export{b as timeout,a as sleep,c as retry,e as parallelLimit,d as defer};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
import{M as a,N as b,O as c,P as d,Q as e,R as f,S as g,T as h,U as i,V as j,W as k,X as l,Y as m,Z as n}from"../chunk-m7vtwv05.js";export{m as words,i as uncapitalize,j as truncate,f as titleCase,e as snakeCase,g as slugify,b as pascalCase,n as lines,d as kebabCase,l as escapeRegExp,k as escapeHtml,c as capitalizeFirstLetter,h as capitalize,a as camelCase};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.1
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
import{$ as b,Aa as C,Ba as D,Ca as E,Da as F,Ea as G,Fa as H,Ga as I,_ as a,aa as c,ba as d,ca as e,da as f,ea as g,fa as h,ga as i,ha as j,ia as k,ja as l,ka as m,la as n,ma as o,na as p,oa as q,pa as r,qa as s,ra as t,sa as u,ta as v,ua as w,va as x,wa as y,xa as z,ya as A,za as B}from"../chunk-y84wjyfx.js";export{H as useEventBus,k as stringifyBigIntValues,n as storageSetItemWithTTL,l as storageSetItem,p as storageRemoveItem,o as storageGetItemWithTTL,m as storageGetItem,v as storageGetAllKeys,u as storageExists,t as storageClearBySuffix,r as storageClearByPrefixOrSuffix,s as storageClearByPrefix,q as storageClear,w as storageCalculateSize,z as setStyleProperties,C as isInViewport,I as isEqual,a as isCacheStorageSupported,y as isBrowser,x as deepClone,A as checkVisibility,D as calculateRenderedTextWidth,f as cacheResponseKeys,b as cachePutResponse,h as cacheNames,c as cacheMatchResponse,e as cacheHasResponse,i as cacheExists,d as cacheDeleteResponse,j as cacheDelete,g as cacheClear,F as busSubscribe,G as busOnce,E as busDispatch,B as __resetTextMeasurementCache};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard for `boolean`.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* isBoolean(true); // true
|
|
7
|
+
* isBoolean('true'); // false
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Type guard for `number` (including `NaN`).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* isNumber(42); // true
|
|
17
|
+
* isNumber('42'); // false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const isNumber: (value: unknown) => value is number;
|
|
21
|
+
/**
|
|
22
|
+
* Type guard for `string`.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* isString('hello'); // true
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const isString: (value: unknown) => value is string;
|
|
30
|
+
/**
|
|
31
|
+
* Type guard for `function` (any callable).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* isFunction(() => {}); // true
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const isFunction: (value: unknown) => value is CallableFunction;
|
|
39
|
+
/**
|
|
40
|
+
* Type guard for plain objects (literal `{}` or `Object.create(null)`).
|
|
41
|
+
* Rejects arrays, Dates, Maps, Sets, class instances, etc.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* isObject({}); // true
|
|
46
|
+
* isObject([]); // false
|
|
47
|
+
* isObject(new Date()); // false
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* Type guard for any non-null object (loose - accepts arrays, instances, etc.).
|
|
53
|
+
* Use this when you only need "is it an object reference?".
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* isRecord([]); // true
|
|
58
|
+
* isRecord({}); // true
|
|
59
|
+
* isRecord(new Date()); // true
|
|
60
|
+
* isRecord(null); // false
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
64
|
+
/**
|
|
65
|
+
* Type guard for `undefined`.
|
|
66
|
+
*/
|
|
67
|
+
export declare const isUndefined: (value: unknown) => value is undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Type guard for `null`.
|
|
70
|
+
*/
|
|
71
|
+
export declare const isNull: (value: unknown) => value is null;
|
|
72
|
+
/**
|
|
73
|
+
* Type guard for `null` or `undefined`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* isNil(null); // true
|
|
78
|
+
* isNil(undefined); // true
|
|
79
|
+
* isNil(0); // false
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const isNil: (value: unknown) => value is null | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Type guard: value is not `undefined`. Useful as a filter predicate.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* [1, undefined, 2].filter(isDefined); // [1, 2] typed as number[]
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const isDefined: <T>(value: T | undefined) => value is T;
|
|
92
|
+
/**
|
|
93
|
+
* Type guard for arrays. Thin wrapper over `Array.isArray` with a
|
|
94
|
+
* generic-friendly signature.
|
|
95
|
+
*/
|
|
96
|
+
export declare const isArray: <T = unknown>(value: unknown) => value is T[];
|
|
97
|
+
/**
|
|
98
|
+
* Type guard for `Date` instances.
|
|
99
|
+
*/
|
|
100
|
+
export declare const isDate: (value: unknown) => value is Date;
|
|
101
|
+
/**
|
|
102
|
+
* Type guard for `RegExp`.
|
|
103
|
+
*/
|
|
104
|
+
export declare const isRegExp: (value: unknown) => value is RegExp;
|
|
105
|
+
/**
|
|
106
|
+
* Type guard for `Error` (and subclasses).
|
|
107
|
+
*/
|
|
108
|
+
export declare const isError: (value: unknown) => value is Error;
|
|
109
|
+
/**
|
|
110
|
+
* Type guard for thenable / Promise-like values. Checks for a callable
|
|
111
|
+
* `then` property - aligns with the Promises/A+ spec.
|
|
112
|
+
*/
|
|
113
|
+
export declare const isPromise: <T = unknown>(value: unknown) => value is Promise<T>;
|
|
114
|
+
/**
|
|
115
|
+
* Type guard for `Map`.
|
|
116
|
+
*/
|
|
117
|
+
export declare const isMap: <K = unknown, V = unknown>(value: unknown) => value is Map<K, V>;
|
|
118
|
+
/**
|
|
119
|
+
* Type guard for `Set`.
|
|
120
|
+
*/
|
|
121
|
+
export declare const isSet: <T = unknown>(value: unknown) => value is Set<T>;
|
|
122
|
+
/**
|
|
123
|
+
* Type guard for JS primitives (string, number, boolean, bigint, symbol,
|
|
124
|
+
* null, undefined).
|
|
125
|
+
*/
|
|
126
|
+
export declare const isPrimitive: (value: unknown) => value is string | number | boolean | bigint | symbol | null | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Checks whether a collection or string is empty.
|
|
129
|
+
*
|
|
130
|
+
* - String: length === 0
|
|
131
|
+
* - Array: length === 0
|
|
132
|
+
* - Map/Set: size === 0
|
|
133
|
+
* - Plain object: no own enumerable string keys
|
|
134
|
+
* - null / undefined: true
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* isEmpty([]); // true
|
|
139
|
+
* isEmpty({}); // true
|
|
140
|
+
* isEmpty(''); // true
|
|
141
|
+
* isEmpty(new Map()); // true
|
|
142
|
+
* isEmpty([1]); // false
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare const isEmpty: (value: unknown) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service-worker-safe Cache Storage helpers.
|
|
3
|
+
*
|
|
4
|
+
* This entry point (`@pivanov/utils/cache`) is self-contained on purpose: it
|
|
5
|
+
* pulls in no React, no event bus, no DOM helpers and no shared barrel, so it
|
|
6
|
+
* can be imported from a service worker without dragging the rest of the
|
|
7
|
+
* package along.
|
|
8
|
+
*
|
|
9
|
+
* Two layers are available:
|
|
10
|
+
* - `storage*` for JSON metadata, with optional TTL envelopes.
|
|
11
|
+
* - `cache*Response` and friends for raw `Request`/`Response` traffic, where
|
|
12
|
+
* the body, status and headers survive untouched.
|
|
13
|
+
*/
|
|
14
|
+
export * from "./response";
|
|
15
|
+
export * from "./storage";
|
|
16
|
+
export * from "./support";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the ambient `CacheStorage`, throwing a descriptive error when the
|
|
3
|
+
* runtime does not provide one.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getCacheStorage: () => CacheStorage;
|
|
6
|
+
/** Opens (or creates) a named cache. */
|
|
7
|
+
export declare const openCache: (cacheName: string) => Promise<Cache>;
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes a metadata key into an absolute URL. Keys that already look like
|
|
10
|
+
* URLs are passed through untouched, so callers may address real resources.
|
|
11
|
+
*/
|
|
12
|
+
export declare const createCacheKey: (key: string) => string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anything the Cache Storage API accepts as a request key: an absolute URL
|
|
3
|
+
* string, a `URL`, or a `Request`.
|
|
4
|
+
*/
|
|
5
|
+
export type CacheRequestKey = RequestInfo | URL;
|
|
6
|
+
/**
|
|
7
|
+
* Stores a raw `Response` under `request`, byte for byte.
|
|
8
|
+
*
|
|
9
|
+
* Unlike {@link storageSetItem}, nothing is serialized: the body, status and
|
|
10
|
+
* headers are preserved exactly, which is what a service worker needs when it
|
|
11
|
+
* caches JavaScript, CSS, images or fonts.
|
|
12
|
+
*
|
|
13
|
+
* The response is cached as a **clone**, so the caller's `response` stays
|
|
14
|
+
* readable afterwards and can still be returned to the page.
|
|
15
|
+
*
|
|
16
|
+
* @throws {TypeError} When `response.bodyUsed` is already `true`, since a
|
|
17
|
+
* consumed body cannot be cloned.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const response = await fetch('/assets/app.abc123.js');
|
|
22
|
+
* await cachePutResponse('assets-v1', '/assets/app.abc123.js', response);
|
|
23
|
+
* return response; // still readable
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const cachePutResponse: (cacheName: string, request: CacheRequestKey, response: Response) => Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Reads a raw `Response` back out of the cache, or `undefined` on a miss.
|
|
29
|
+
*
|
|
30
|
+
* The returned response is a fresh, unread `Response` each time, so callers may
|
|
31
|
+
* consume its body without affecting the cached entry.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const hit = await cacheMatchResponse('assets-v1', '/assets/app.abc123.js');
|
|
36
|
+
* if (hit) {
|
|
37
|
+
* return hit;
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const cacheMatchResponse: (cacheName: string, request: CacheRequestKey, options?: CacheQueryOptions) => Promise<Response | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes a single cached response. Returns `true` when an entry was removed.
|
|
44
|
+
*/
|
|
45
|
+
export declare const cacheDeleteResponse: (cacheName: string, request: CacheRequestKey, options?: CacheQueryOptions) => Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Reports whether a response is cached under `request`, without reading its
|
|
48
|
+
* body.
|
|
49
|
+
*/
|
|
50
|
+
export declare const cacheHasResponse: (cacheName: string, request: CacheRequestKey, options?: CacheQueryOptions) => Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Lists the request URLs currently stored in a cache.
|
|
53
|
+
*
|
|
54
|
+
* Each entry can be handed straight back to {@link cacheMatchResponse} or
|
|
55
|
+
* {@link cacheDeleteResponse}, which makes this the building block for
|
|
56
|
+
* revision cleanup.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const stale = (await cacheResponseKeys('assets-v1')).filter((url) => !url.includes(revision));
|
|
61
|
+
* await Promise.all(stale.map((url) => cacheDeleteResponse('assets-v1', url)));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const cacheResponseKeys: (cacheName: string) => Promise<string[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Removes every entry from a cache while keeping the cache itself.
|
|
67
|
+
*
|
|
68
|
+
* Use {@link cacheDelete} to drop the cache entirely.
|
|
69
|
+
*/
|
|
70
|
+
export declare const cacheClear: (cacheName: string) => Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Lists the names of every cache in the current origin's Cache Storage.
|
|
73
|
+
*/
|
|
74
|
+
export declare const cacheNames: () => Promise<string[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Reports whether a cache with this name exists, without creating it.
|
|
77
|
+
*
|
|
78
|
+
* Note that {@link cacheMatchResponse} and friends open the cache on demand, so
|
|
79
|
+
* prefer this check when the mere existence of the cache is the signal.
|
|
80
|
+
*/
|
|
81
|
+
export declare const cacheExists: (cacheName: string) => Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Deletes an entire cache. Returns `true` when a cache was removed.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const outdated = (await cacheNames()).filter((name) => name !== `assets-${revision}`);
|
|
88
|
+
* await Promise.all(outdated.map(cacheDelete));
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const cacheDelete: (cacheName: string) => Promise<boolean>;
|