@pivanov/utils 0.0.3 → 1.0.0
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 +95 -340
- package/dist/cjs/assertion/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/chunk-1rn730je.js +7 -0
- package/dist/esm/chunk-5nmphgya.js +8 -0
- package/dist/esm/chunk-bqewq152.js +8 -0
- package/dist/esm/chunk-f1nddzrj.js +6 -0
- package/dist/esm/chunk-hksj0qca.js +8 -0
- package/dist/esm/chunk-tdt3f0jc.js +8 -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/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/cache-api/index.d.ts +75 -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 +65 -35
- package/dist/index.d.ts +0 -691
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.0
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var{defineProperty:V,getOwnPropertyNames:c,getOwnPropertyDescriptor:r}=Object,n=Object.prototype.hasOwnProperty;var u=new WeakMap,o=(J)=>{var Q=u.get(J),X;if(Q)return Q;if(Q=V({},"__esModule",{value:!0}),J&&typeof J==="object"||typeof J==="function")c(J).map((Y)=>!n.call(Q,Y)&&V(Q,Y,{get:()=>J[Y],enumerable:!(X=r(J,Y))||X.enumerable}));return u.set(J,Q),Q};var i=(J,Q)=>{for(var X in Q)V(J,X,{get:Q[X],enumerable:!0,configurable:!0,set:(Y)=>Q[X]=()=>Y})};var TJ={};i(TJ,{useEventBus:()=>EJ,stringifyBigIntValues:()=>k,storageSetItemWithTTL:()=>s,storageSetItem:()=>p,storageRemoveItem:()=>y,storageGetItemWithTTL:()=>a,storageGetItem:()=>h,storageGetAllKeys:()=>YJ,storageExists:()=>XJ,storageClearBySuffix:()=>QJ,storageClearByPrefixOrSuffix:()=>w,storageClearByPrefix:()=>JJ,storageClear:()=>e,storageCalculateSize:()=>ZJ,setStyleProperties:()=>GJ,isInViewport:()=>MJ,isEqual:()=>IJ,isBrowser:()=>$J,deepClone:()=>_J,checkVisibility:()=>FJ,calculateRenderedTextWidth:()=>RJ,busSubscribe:()=>K,busOnce:()=>HJ,busDispatch:()=>AJ,__resetTextMeasurementCache:()=>BJ});module.exports=o(TJ);var k=(J,Q)=>{return typeof Q==="bigint"?Q.toString():Q},P=(J)=>{if(J.startsWith("http://")||J.startsWith("https://"))return J;return`https://cache.internal/${J}`},p=async(J,Q,X)=>{let Y=await caches.open(J),$=JSON.stringify(X,k),U=new Response($,{headers:{"Content-Type":"application/json"}}),G=P(Q);await Y.put(new Request(G),U)},h=async(J,Q)=>{let X=await caches.open(J),Y=P(Q),$=await X.match(new Request(Y));if(!$)return null;let U=await $.text();return JSON.parse(U)},t=(J)=>{return typeof J==="object"&&J!==null&&J.__ttl===!0&&typeof J.exp==="number"},s=async(J,Q,X,Y)=>{let $={__ttl:!0,v:X,exp:Date.now()+Y};await p(J,Q,$)},a=async(J,Q)=>{let X=await h(J,Q);if(!t(X))return null;if(Date.now()>=X.exp)return await y(J,Q),null;return X.v},y=async(J,Q)=>{let X=await caches.open(J),Y=P(Q);return X.delete(new Request(Y))},e=async(J)=>{let Q=await caches.open(J),X=await Q.keys();for(let Y of X)await Q.delete(Y)},w=async(J,Q,X=!0)=>{let Y=await caches.open(J),$=await Y.keys();for(let U of $){let G=U.url.split("/"),W=G[G.length-1]||"";if(X&&W.startsWith(Q)||!X&&W.endsWith(Q))await Y.delete(U)}},JJ=async(J,Q)=>{await w(J,Q,!0)},QJ=async(J,Q)=>{await w(J,Q,!1)},XJ=async(J,Q)=>{let X=await caches.open(J),Y=P(Q);return await X.match(new Request(Y))!==void 0},YJ=async(J)=>{return(await(await caches.open(J)).keys()).map((Y)=>{let $=Y.url.split("/");return $[$.length-1]||""})},ZJ=async(J,Q)=>{let X=await caches.open(J);if(Q){let U=P(Q),G=await X.match(new Request(U));if(G)return(await G.clone().arrayBuffer()).byteLength;return 0}let Y=await X.keys(),$=0;for(let U of Y){let G=await X.match(U);if(G){let W=await G.clone().arrayBuffer();$+=W.byteLength}}return $};var _J=(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 B=0;B<Z;B++)if(B in J)_[B]=M(J[B],Q);return _}let F=Array(Z);if(Q.set(J,F),Object.keys(J).length===Z){let _=0,B=Z%8,O=Z-B;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,B=_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);return new Z(B)}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),B=new Uint8Array(_.length);return B.set(_),B}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 B=0;B<_;B++)Z.add(M(F[B],Q));return Z}if(J instanceof Map){let Z=new Map;Q.set(J,Z);let F=Array.from(J),_=F.length;for(let B=0;B<_;B++){let[O,I]=F[B];Z.set(O,M(I,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 R=0;R<_;R++){let A=F[R],H=Object.getOwnPropertyDescriptor(J,A);if(H?.enumerable)Object.defineProperty(Z,A,H)}let B=Object.getOwnPropertyDescriptors(J),O=Object.keys(J),I=O.length,N=!1;for(let R=0;R<I;R++){let A=B[O[R]];if(A.get||A.set){N=!0;break}}if(N)for(let R=0;R<I;R++){let A=O[R],H=B[A];if(H.enumerable)if(H.get||H.set)Object.defineProperty(Z,A,H);else{let T=M(H.value,Q);Object.defineProperty(Z,A,{...H,value:T})}}else{let R=0,A=I%8,H=I-A;while(R<H){let T=O[R],x=O[R+1],f=O[R+2],v=O[R+3],g=O[R+4],C=O[R+5],m=O[R+6],d=O[R+7],E=J;Z[T]=M(E[T],Q),Z[x]=M(E[x],Q),Z[f]=M(E[f],Q),Z[v]=M(E[v],Q),Z[g]=M(E[g],Q),Z[C]=M(E[C],Q),Z[m]=M(E[m],Q),Z[d]=M(E[d],Q),R+=8}while(R<I){let T=O[R++];Z[T]=M(J[T],Q)}}return Z}let Y=Object.getPrototypeOf(J),$=Object.create(Y);Q.set(J,$);let U=Object.getOwnPropertyDescriptors(J),G=Object.keys(U),W=G.length;for(let Z=0;Z<W;Z++){let F=G[Z],_=U[F];if(!_.enumerable)continue;if(_.get||_.set)Object.defineProperty($,F,_);else{let B=M(_.value,Q);Object.defineProperty($,F,{..._,value:B})}}let q=Object.getOwnPropertySymbols(J),L=q.length;for(let Z=0;Z<L;Z++){let F=q[Z],_=Object.getOwnPropertyDescriptor(J,F);if(!_?.enumerable)continue;Object.defineProperty($,F,_)}return $};var $J=()=>{return typeof window<"u"&&typeof document<"u"},GJ=(J,Q)=>{if(!J)return;for(let[X,Y]of Object.entries(Q))J.style.setProperty(X,Y)},FJ=(J,Q={})=>{let{checkViewport:X=!0,checkDisplay:Y=!0,checkVisibility:$=!0,checkOpacity:U=!0}=Q;if(!J.isConnected)return!1;if(Y||$||U){let G=window.getComputedStyle(J);if(Y&&G.display==="none")return!1;if($&&G.visibility!==""&&G.visibility!=="visible")return!1;if(U&&G.opacity!==""){let W=Number.parseFloat(G.opacity);if(!Number.isNaN(W)&&W===0)return!1}}if(X){let G=J.getBoundingClientRect();if(G.width!==0||G.height!==0){let W=window.innerHeight||document.documentElement.clientHeight,q=window.innerWidth||document.documentElement.clientWidth,L=G.bottom<=0||G.top>=W,Z=G.right<=0||G.left>=q;if(L||Z)return!1}}return!0};var D,z,UJ=()=>{if(z!==void 0)return z;if(typeof document>"u")return z=null,null;return D=document.createElement("canvas"),z=D.getContext("2d"),z},BJ=()=>{D=void 0,z=void 0},MJ=(J,Q={})=>{let{vertical:X=!0,horizontal:Y=!0}=Q,$=J.getBoundingClientRect();if($.width===0&&$.height===0)return!0;let U=window.innerHeight||document.documentElement.clientHeight,G=window.innerWidth||document.documentElement.clientWidth;if(X&&($.bottom<=0||$.top>=U))return!1;if(Y&&($.right<=0||$.left>=G))return!1;return!0},RJ=(J,Q,X=!1,Y='Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"')=>{let $=UJ();if(!$)return 0;let U=X?J.toUpperCase():J;return $.font=`${Q}px ${Y}`,$.measureText(U).width};var OJ=(J,Q="\uD83D\uDE80")=>{let X=0,Y=J+Q;for(let $=0;$<Y.length;$++){let U=Y.charCodeAt($);X=(X<<5)-X+U,X|=0}return(X>>>0).toString(16)},j=(J)=>{return`${OJ(J)}::${J}`},WJ=(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)}}},AJ=(J,Q)=>{if(!J)return;let X=j(J);window.dispatchEvent(new CustomEvent(X,{detail:Q,bubbles:!0,cancelable:!1}))},K=(J,Q,X={})=>{if(!J||typeof Q!=="function")return()=>{};let Y=WJ(Q,X.onError),$=j(J);return window.addEventListener($,Y),()=>window.removeEventListener($,Y)},HJ=(J,Q,X={})=>{if(!J||typeof Q!=="function")return()=>{};let Y=K(J,($)=>{Y(),Q($)},X);return Y};var l=require("react");var EJ=(J,Q,X=[])=>{l.useEffect(()=>{if(!J||typeof Q!=="function")return;return K(J,Q)},[J,Q,...X])};var IJ=(J,Q)=>{return S(J,Q,new WeakMap)},S=(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 b(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),$=new Uint8Array(Q.buffer,Q.byteOffset,Q.byteLength);return b(Y,$)}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(!S(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 $ of J){let U=Y.findIndex((G)=>S($,G,X));if(U===-1)return!1;Y.splice(U,1)}return!0}if(J instanceof Map&&Q instanceof Map){if(J.size!==Q.size)return!1;for(let[Y,$]of J)if(!Q.has(Y)||!S($,Q.get(Y),X))return!1;return!0}if(J!==null&&typeof J==="object"&&Q!==null&&typeof Q==="object"){let Y=J,$=Q,U=Object.keys(Y);if(U.length!==Object.keys($).length)return!1;for(let G of U)if(!S(Y[G],$[G],X))return!1;return!0}return!1},b=(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.0
|
|
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;var J=new WeakMap,N=(q)=>{var k=J.get(q),z;if(k)return k;if(k=H({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function")K(q).map((G)=>!M.call(k,G)&&H(k,G,{get:()=>q[G],enumerable:!(z=L(q,G))||z.enumerable}));return J.set(q,k),k};var Q=(q,k)=>{for(var z in k)H(q,z,{get:k[z],enumerable:!0,configurable:!0,set:(G)=>k[z]=()=>G})};var O={};module.exports=N(O);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.0
|
|
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-5nmphgya.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.0
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
var k=(J,Q)=>{return typeof Q==="bigint"?Q.toString():Q},P=(J)=>{if(J.startsWith("http://")||J.startsWith("https://"))return J;return`https://cache.internal/${J}`},p=async(J,Q,X)=>{let Y=await caches.open(J),$=JSON.stringify(X,k),U=new Response($,{headers:{"Content-Type":"application/json"}}),G=P(Q);await Y.put(new Request(G),U)},h=async(J,Q)=>{let X=await caches.open(J),Y=P(Q),$=await X.match(new Request(Y));if(!$)return null;let U=await $.text();return JSON.parse(U)},y=(J)=>{return typeof J==="object"&&J!==null&&J.__ttl===!0&&typeof J.exp==="number"},n=async(J,Q,X,Y)=>{let $={__ttl:!0,v:X,exp:Date.now()+Y};await p(J,Q,$)},o=async(J,Q)=>{let X=await h(J,Q);if(!y(X))return null;if(Date.now()>=X.exp)return await j(J,Q),null;return X.v},j=async(J,Q)=>{let X=await caches.open(J),Y=P(Q);return X.delete(new Request(Y))},i=async(J)=>{let Q=await caches.open(J),X=await Q.keys();for(let Y of X)await Q.delete(Y)},m=async(J,Q,X=!0)=>{let Y=await caches.open(J),$=await Y.keys();for(let U of $){let G=U.url.split("/"),W=G[G.length-1]||"";if(X&&W.startsWith(Q)||!X&&W.endsWith(Q))await Y.delete(U)}},t=async(J,Q)=>{await m(J,Q,!0)},s=async(J,Q)=>{await m(J,Q,!1)},a=async(J,Q)=>{let X=await caches.open(J),Y=P(Q);return await X.match(new Request(Y))!==void 0},e=async(J)=>{return(await(await caches.open(J)).keys()).map((Y)=>{let $=Y.url.split("/");return $[$.length-1]||""})},JJ=async(J,Q)=>{let X=await caches.open(J);if(Q){let U=P(Q),G=await X.match(new Request(U));if(G)return(await G.clone().arrayBuffer()).byteLength;return 0}let Y=await X.keys(),$=0;for(let U of Y){let G=await X.match(U);if(G){let W=await G.clone().arrayBuffer();$+=W.byteLength}}return $};var XJ=(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 B=0;B<Z;B++)if(B in J)_[B]=M(J[B],Q);return _}let F=Array(Z);if(Q.set(J,F),Object.keys(J).length===Z){let _=0,B=Z%8,O=Z-B;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,B=_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);return new Z(B)}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),B=new Uint8Array(_.length);return B.set(_),B}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 B=0;B<_;B++)Z.add(M(F[B],Q));return Z}if(J instanceof Map){let Z=new Map;Q.set(J,Z);let F=Array.from(J),_=F.length;for(let B=0;B<_;B++){let[O,I]=F[B];Z.set(O,M(I,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 R=0;R<_;R++){let A=F[R],H=Object.getOwnPropertyDescriptor(J,A);if(H?.enumerable)Object.defineProperty(Z,A,H)}let B=Object.getOwnPropertyDescriptors(J),O=Object.keys(J),I=O.length,w=!1;for(let R=0;R<I;R++){let A=B[O[R]];if(A.get||A.set){w=!0;break}}if(w)for(let R=0;R<I;R++){let A=O[R],H=B[A];if(H.enumerable)if(H.get||H.set)Object.defineProperty(Z,A,H);else{let T=M(H.value,Q);Object.defineProperty(Z,A,{...H,value:T})}}else{let R=0,A=I%8,H=I-A;while(R<H){let T=O[R],D=O[R+1],N=O[R+2],x=O[R+3],f=O[R+4],v=O[R+5],g=O[R+6],C=O[R+7],E=J;Z[T]=M(E[T],Q),Z[D]=M(E[D],Q),Z[N]=M(E[N],Q),Z[x]=M(E[x],Q),Z[f]=M(E[f],Q),Z[v]=M(E[v],Q),Z[g]=M(E[g],Q),Z[C]=M(E[C],Q),R+=8}while(R<I){let T=O[R++];Z[T]=M(J[T],Q)}}return Z}let Y=Object.getPrototypeOf(J),$=Object.create(Y);Q.set(J,$);let U=Object.getOwnPropertyDescriptors(J),G=Object.keys(U),W=G.length;for(let Z=0;Z<W;Z++){let F=G[Z],_=U[F];if(!_.enumerable)continue;if(_.get||_.set)Object.defineProperty($,F,_);else{let B=M(_.value,Q);Object.defineProperty($,F,{..._,value:B})}}let q=Object.getOwnPropertySymbols(J),K=q.length;for(let Z=0;Z<K;Z++){let F=q[Z],_=Object.getOwnPropertyDescriptor(J,F);if(!_?.enumerable)continue;Object.defineProperty($,F,_)}return $};var ZJ=()=>{return typeof window<"u"&&typeof document<"u"},_J=(J,Q)=>{if(!J)return;for(let[X,Y]of Object.entries(Q))J.style.setProperty(X,Y)},$J=(J,Q={})=>{let{checkViewport:X=!0,checkDisplay:Y=!0,checkVisibility:$=!0,checkOpacity:U=!0}=Q;if(!J.isConnected)return!1;if(Y||$||U){let G=window.getComputedStyle(J);if(Y&&G.display==="none")return!1;if($&&G.visibility!==""&&G.visibility!=="visible")return!1;if(U&&G.opacity!==""){let W=Number.parseFloat(G.opacity);if(!Number.isNaN(W)&&W===0)return!1}}if(X){let G=J.getBoundingClientRect();if(G.width!==0||G.height!==0){let W=window.innerHeight||document.documentElement.clientHeight,q=window.innerWidth||document.documentElement.clientWidth,K=G.bottom<=0||G.top>=W,Z=G.right<=0||G.left>=q;if(K||Z)return!1}}return!0};var L,z,l=()=>{if(z!==void 0)return z;if(typeof document>"u")return z=null,null;return L=document.createElement("canvas"),z=L.getContext("2d"),z},GJ=()=>{L=void 0,z=void 0},FJ=(J,Q={})=>{let{vertical:X=!0,horizontal:Y=!0}=Q,$=J.getBoundingClientRect();if($.width===0&&$.height===0)return!0;let U=window.innerHeight||document.documentElement.clientHeight,G=window.innerWidth||document.documentElement.clientWidth;if(X&&($.bottom<=0||$.top>=U))return!1;if(Y&&($.right<=0||$.left>=G))return!1;return!0},UJ=(J,Q,X=!1,Y='Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"')=>{let $=l();if(!$)return 0;let U=X?J.toUpperCase():J;return $.font=`${Q}px ${Y}`,$.measureText(U).width};var b=(J,Q="\uD83D\uDE80")=>{let X=0,Y=J+Q;for(let $=0;$<Y.length;$++){let U=Y.charCodeAt($);X=(X<<5)-X+U,X|=0}return(X>>>0).toString(16)},d=(J)=>{return`${b(J)}::${J}`},c=(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)}}},MJ=(J,Q)=>{if(!J)return;let X=d(J);window.dispatchEvent(new CustomEvent(X,{detail:Q,bubbles:!0,cancelable:!1}))},V=(J,Q,X={})=>{if(!J||typeof Q!=="function")return()=>{};let Y=c(Q,X.onError),$=d(J);return window.addEventListener($,Y),()=>window.removeEventListener($,Y)},RJ=(J,Q,X={})=>{if(!J||typeof Q!=="function")return()=>{};let Y=V(J,($)=>{Y(),Q($)},X);return Y};import{useEffect as r}from"react";var HJ=(J,Q,X=[])=>{r(()=>{if(!J||typeof Q!=="function")return;return V(J,Q)},[J,Q,...X])};var IJ=(J,Q)=>{return S(J,Q,new WeakMap)},S=(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 u(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),$=new Uint8Array(Q.buffer,Q.byteOffset,Q.byteLength);return u(Y,$)}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(!S(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 $ of J){let U=Y.findIndex((G)=>S($,G,X));if(U===-1)return!1;Y.splice(U,1)}return!0}if(J instanceof Map&&Q instanceof Map){if(J.size!==Q.size)return!1;for(let[Y,$]of J)if(!Q.has(Y)||!S($,Q.get(Y),X))return!1;return!0}if(J!==null&&typeof J==="object"&&Q!==null&&typeof Q==="object"){let Y=J,$=Q,U=Object.keys(Y);if(U.length!==Object.keys($).length)return!1;for(let G of U)if(!S(Y[G],$[G],X))return!1;return!0}return!1},u=(J,Q)=>{for(let X=0;X<J.length;X++)if(J[X]!==Q[X])return!1;return!0};export{k as _,p as $,h as aa,n as ba,o as ca,j as da,i as ea,m as fa,t as ga,s as ha,a as ia,e as ja,JJ as ka,XJ as la,ZJ as ma,_J as na,$J as oa,GJ as pa,FJ as qa,UJ as ra,MJ as sa,V as ta,RJ as ua,HJ as va,IJ as wa};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.0
|
|
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,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.0
|
|
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-5nmphgya.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.0
|
|
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.0
|
|
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};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @pivanov/utils
|
|
2
|
+
* @pivanov/utils v1.0.0
|
|
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-bqewq152.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-5nmphgya.js";import{H as O,I as P,J as Q,K as R,L as S}from"./chunk-tdt3f0jc.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-hksj0qca.js";import{$ as to,_ 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}from"./chunk-1rn730je.js";import"./chunk-f1nddzrj.js";export{fo as words,Do as useEventBus,$ as uncapitalize,oo as truncate,Y as titleCase,P as timeout,po as stringifyBigIntValues,ao as storageSetItemWithTTL,to as storageSetItem,co as storageRemoveItem,bo as storageGetItemWithTTL,xo as storageGetItem,lo as storageGetAllKeys,ko as storageExists,jo as storageClearBySuffix,ho as storageClearByPrefixOrSuffix,io as storageClearByPrefix,go as storageClear,no as storageCalculateSize,X as snakeCase,Z as slugify,O as sleep,uo 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,yo as isInViewport,c as isFunction,s as isError,Eo as isEqual,z as isEmpty,k as isDefined,n as isDate,so 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,qo as deepClone,vo as checkVisibility,V as capitalizeFirstLetter,_ as capitalize,T as camelCase,zo as calculateRenderedTextWidth,Bo as busSubscribe,Co as busOnce,Ao as busDispatch,wo as __resetTextMeasurementCache};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pivanov/utils v1.0.0
|
|
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-bqewq152.js";import"../chunk-5nmphgya.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.0
|
|
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-tdt3f0jc.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.0
|
|
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-hksj0qca.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.0
|
|
3
|
+
* (c) 2024-present Pavel Ivanov
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
* https://github.com/pivanov/utils
|
|
6
|
+
*/
|
|
7
|
+
import{$ as b,_ 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}from"../chunk-1rn730je.js";export{x as useEventBus,a as stringifyBigIntValues,d as storageSetItemWithTTL,b as storageSetItem,f as storageRemoveItem,e as storageGetItemWithTTL,c as storageGetItem,l as storageGetAllKeys,k as storageExists,j as storageClearBySuffix,h as storageClearByPrefixOrSuffix,i as storageClearByPrefix,g as storageClear,m as storageCalculateSize,p as setStyleProperties,s as isInViewport,y as isEqual,o as isBrowser,n as deepClone,q as checkVisibility,t as calculateRenderedTextWidth,v as busSubscribe,w as busOnce,u as busDispatch,r 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,118 @@
|
|
|
1
|
+
import type { TDict } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new object with the specified keys removed.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* omit({ name: 'John', age: 30 }, ['age']); // { name: 'John' }
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare const omit: <T extends TDict, K extends keyof T>(object: T, keys: K[]) => Omit<T, K>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new object with only the specified keys.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* pick({ name: 'John', age: 30 }, ['name']); // { name: 'John' }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const pick: <T extends TDict, K extends keyof T>(object: T, keys: K[]) => Pick<T, K>;
|
|
20
|
+
/**
|
|
21
|
+
* Returns a new object keeping entries where the predicate returns true.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* pickBy({ a: 1, b: 2, c: 3 }, (v) => v > 1); // { b: 2, c: 3 }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const pickBy: <T extends TDict>(object: T, predicate: (value: T[keyof T], key: keyof T) => boolean) => Partial<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a new object dropping entries where the predicate returns true.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* omitBy({ a: 1, b: null, c: 3 }, (v) => v === null); // { a: 1, c: 3 }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const omitBy: <T extends TDict>(object: T, predicate: (value: T[keyof T], key: keyof T) => boolean) => Partial<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a new object with values mapped via the transform function.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* mapValues({ a: 1, b: 2 }, (v) => v * 2); // { a: 2, b: 4 }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const mapValues: <T extends TDict, R>(object: T, mapper: (value: T[keyof T], key: keyof T) => R) => Record<keyof T, R>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns a new object with keys mapped via the transform function.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* mapKeys({ a: 1, b: 2 }, (_, k) => k.toUpperCase()); // { A: 1, B: 2 }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const mapKeys: <T extends TDict>(object: T, mapper: (value: T[keyof T], key: keyof T) => string) => Record<string, T[keyof T]>;
|
|
56
|
+
/**
|
|
57
|
+
* Groups items by the key returned by the iteratee.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* groupBy(['apple', 'banana', 'cherry'], (s) => s[0]);
|
|
62
|
+
* // { a: ['apple'], b: ['banana'], c: ['cherry'] }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const groupBy: <T, K extends string | number>(items: readonly T[], iteratee: (item: T, index: number) => K) => Record<K, T[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Swaps keys with values. Values must be valid object keys.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* invert({ a: 'x', b: 'y' }); // { x: 'a', y: 'b' }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const invert: <K extends string, V extends string | number | symbol>(object: Record<K, V>) => Record<V, K>;
|
|
75
|
+
/**
|
|
76
|
+
* Typed `Object.hasOwn`. Narrows the key into the object's own keys.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* if (hasOwn(obj, 'name')) obj.name; // narrowed
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare const hasOwn: <T extends object, K extends PropertyKey>(object: T, key: K) => object is T & Record<K, unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* Typed `Object.keys`. Returns `(keyof T)[]` instead of `string[]`.
|
|
86
|
+
*
|
|
87
|
+
* Note: like `Object.keys`, the runtime keys are just the own enumerable
|
|
88
|
+
* string keys, so this typing can be unsound if the object has extra runtime
|
|
89
|
+
* properties not in its compile-time type.
|
|
90
|
+
*/
|
|
91
|
+
export declare const keysOf: <T extends object>(object: T) => (keyof T)[];
|
|
92
|
+
/**
|
|
93
|
+
* Typed `Object.entries`. Returns `[keyof T, T[keyof T]][]`.
|
|
94
|
+
*/
|
|
95
|
+
export declare const entriesOf: <T extends object>(object: T) => [keyof T, T[keyof T]][];
|
|
96
|
+
/**
|
|
97
|
+
* Typed `Object.fromEntries` for tuple arrays with literal key types.
|
|
98
|
+
*/
|
|
99
|
+
export declare const fromEntries: <K extends PropertyKey, V>(entries: readonly (readonly [K, V])[]) => Record<K, V>;
|
|
100
|
+
/**
|
|
101
|
+
* Shallow-merges multiple objects into a new object. Does not mutate inputs.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* merge({ a: 1 }, { b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare const merge: <T extends object>(target: T, ...sources: Partial<T>[]) => T;
|
|
109
|
+
/**
|
|
110
|
+
* Recursively merges multiple objects into a new object. Does not mutate
|
|
111
|
+
* inputs. Nested plain objects are merged; arrays and other values replace.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* deepMerge({ a: { b: 1 } }, { a: { c: 2 } }); // { a: { b: 1, c: 2 } }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare const deepMerge: <T extends object>(target: T, ...sources: Partial<T>[]) => T;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously waits for the specified number of milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* Accepts an optional `AbortSignal` - when the signal aborts, the returned
|
|
5
|
+
* promise rejects with the signal's `reason` and the pending timer is cleared.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* await sleep(1000);
|
|
10
|
+
*
|
|
11
|
+
* const ctrl = new AbortController();
|
|
12
|
+
* setTimeout(() => ctrl.abort(), 50);
|
|
13
|
+
* await sleep(1000, ctrl.signal); // rejects after 50ms
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const sleep: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Races a promise against a timeout. Rejects with the given reason (or a
|
|
19
|
+
* default `TimeoutError`) if the promise doesn't settle in time.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* await timeout(fetch('/slow'), 3000);
|
|
24
|
+
* await timeout(work(), 5000, new Error('took too long'));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const timeout: <T>(promise: Promise<T>, ms: number, reason?: unknown) => Promise<T>;
|
|
28
|
+
interface IRetryOptions {
|
|
29
|
+
/** Maximum number of attempts (including the first). Default: 3. */
|
|
30
|
+
attempts?: number;
|
|
31
|
+
/** Milliseconds to wait between attempts. Can be a fixed number or a function
|
|
32
|
+
* `(attempt) => ms` where attempt is 1-indexed. Default: 0 (no delay). */
|
|
33
|
+
backoff?: number | ((attempt: number) => number);
|
|
34
|
+
/** Cancels in-flight retries. */
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
/** Optional predicate - return false to abort retrying for a given error. */
|
|
37
|
+
shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Runs `fn` and retries on rejection up to `attempts` times with optional
|
|
41
|
+
* backoff. Re-throws the last error if all attempts fail.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* await retry(() => fetch('/api'), { attempts: 3, backoff: 500 });
|
|
46
|
+
* await retry(work, {
|
|
47
|
+
* attempts: 5,
|
|
48
|
+
* backoff: (n) => 100 * 2 ** n, // exponential
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const retry: <T>(fn: (attempt: number) => Promise<T> | T, options?: IRetryOptions) => Promise<T>;
|
|
53
|
+
interface IDeferred<T> {
|
|
54
|
+
promise: Promise<T>;
|
|
55
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
56
|
+
reject: (reason?: unknown) => void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates an externally-resolvable promise. Equivalent to `Promise.withResolvers`
|
|
60
|
+
* (ES2024) but works in older runtimes.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const { promise, resolve } = defer<string>();
|
|
65
|
+
* setTimeout(() => resolve('hi'), 100);
|
|
66
|
+
* const value = await promise;
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare const defer: <T>() => IDeferred<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Maps `items` through `fn` with bounded concurrency. Results preserve input
|
|
72
|
+
* order. If any task rejects, the returned promise rejects as soon as that
|
|
73
|
+
* error surfaces (but already-started tasks continue running).
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const bodies = await parallelLimit(urls, 4, (url) => fetch(url));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare const parallelLimit: <T, R>(items: readonly T[], concurrency: number, fn: (item: T, index: number) => Promise<R> | R) => Promise<R[]>;
|
|
81
|
+
export {};
|