@react-hive/honey-utils 1.6.0 → 1.7.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 +190 -109
- package/dist/README.md +190 -109
- package/dist/array.d.ts +77 -15
- package/dist/guards.d.ts +29 -21
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.dev.cjs +99 -42
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/guards.d.ts
CHANGED
|
@@ -7,6 +7,35 @@ export declare function assert(condition: any, message: string): asserts conditi
|
|
|
7
7
|
* @returns `true` if the value is null; otherwise, `false`.
|
|
8
8
|
*/
|
|
9
9
|
export declare const isNull: (value: unknown) => value is null;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a value is null or undefined.
|
|
12
|
+
*
|
|
13
|
+
* @param value - The value to check.
|
|
14
|
+
*
|
|
15
|
+
* @returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const isNil: (value: unknown) => value is null | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether the provided value is considered "empty".
|
|
20
|
+
*
|
|
21
|
+
* A value is considered empty if it is:
|
|
22
|
+
* - `null`
|
|
23
|
+
* - `undefined`
|
|
24
|
+
* - `''`
|
|
25
|
+
*
|
|
26
|
+
* @param value - The value to check.
|
|
27
|
+
*
|
|
28
|
+
* @returns `true` if the value is empty; otherwise, `false`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const isNilOrEmptyString: (value: unknown) => value is null | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if a value is neither `null` nor `undefined`.
|
|
33
|
+
*
|
|
34
|
+
* @param value - The value to check.
|
|
35
|
+
*
|
|
36
|
+
* @returns `true` if the value is defined (not `null` or `undefined`); otherwise, `false`.
|
|
37
|
+
*/
|
|
38
|
+
export declare const isDefined: <T>(value: T) => value is NonNullable<T>;
|
|
10
39
|
/**
|
|
11
40
|
* Checks if a value is a string.
|
|
12
41
|
*
|
|
@@ -81,27 +110,6 @@ export declare const isFunction: (value: unknown) => value is Function;
|
|
|
81
110
|
* @returns `true` if the value is a Promise; otherwise, `false`.
|
|
82
111
|
*/
|
|
83
112
|
export declare const isPromise: <T = unknown>(value: unknown) => value is Promise<T>;
|
|
84
|
-
/**
|
|
85
|
-
* Checks if a value is null or undefined.
|
|
86
|
-
*
|
|
87
|
-
* @param value - The value to check.
|
|
88
|
-
*
|
|
89
|
-
* @returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
90
|
-
*/
|
|
91
|
-
export declare const isNil: (value: unknown) => value is null | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Checks whether the provided value is considered "empty".
|
|
94
|
-
*
|
|
95
|
-
* A value is considered empty if it is:
|
|
96
|
-
* - `null`
|
|
97
|
-
* - `undefined`
|
|
98
|
-
* - `''`
|
|
99
|
-
*
|
|
100
|
-
* @param value - The value to check.
|
|
101
|
-
*
|
|
102
|
-
* @returns `true` if the value is empty; otherwise, `false`.
|
|
103
|
-
*/
|
|
104
|
-
export declare const isNilOrEmptyString: (value: unknown) => value is null | undefined;
|
|
105
113
|
/**
|
|
106
114
|
* Checks if a value is a Date object.
|
|
107
115
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{assert:()=>
|
|
1
|
+
(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{assert:()=>s,boolFilter:()=>F,calculateEuclideanDistance:()=>K,calculateMovingSpeed:()=>U,calculatePercentage:()=>W,camelToDashCase:()=>n,chunk:()=>D,cloneBlob:()=>H,compose:()=>q,convertBlobToFile:()=>J,delay:()=>Z,difference:()=>x,everyAsync:()=>I,filterAsync:()=>X,findAsync:()=>$,forAsync:()=>B,hashString:()=>i,intersection:()=>E,invokeIfFunction:()=>V,isArray:()=>h,isBool:()=>p,isDate:()=>A,isDefined:()=>u,isEmptyArray:()=>d,isEmptyObject:()=>m,isFiniteNumber:()=>j,isFunction:()=>b,isInteger:()=>C,isMap:()=>M,isNil:()=>l,isNilOrEmptyString:()=>c,isNull:()=>o,isNumber:()=>f,isObject:()=>g,isPromise:()=>w,isRegExp:()=>v,isSet:()=>k,isString:()=>y,isSymbol:()=>O,isUndefined:()=>P,isValidDate:()=>S,mapAsync:()=>T,noop:()=>z,parse2DMatrix:()=>G,pipe:()=>L,reduceAsync:()=>R,retry:()=>_,someAsync:()=>Y,splitStringIntoWords:()=>a,toKebabCase:()=>r,unique:()=>N});const r=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),n=e=>{const t=e.charAt(0),r=e.slice(1);return t.toLowerCase()+r.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)},a=e=>e.split(" ").filter(Boolean),i=e=>{let t=5381;for(let r=0;r<e.length;r++)t=33*t^e.charCodeAt(r);return(t>>>0).toString(36)};function s(e,t){if(!e)throw new Error(t)}const o=e=>null===e,l=e=>null==e,c=e=>""===e||l(e),u=e=>null!=e,y=e=>"string"==typeof e,f=e=>"number"==typeof e,p=e=>"boolean"==typeof e,g=e=>"object"==typeof e,m=e=>g(e)&&!o(e)&&0===Object.keys(e).length,h=e=>Array.isArray(e),d=e=>h(e)&&0===e.length,b=e=>"function"==typeof e,w=e=>b(e?.then),A=e=>e instanceof Date,S=e=>A(e)&&!isNaN(e.getTime()),v=e=>e instanceof RegExp,M=e=>e instanceof Map,k=e=>e instanceof Set,O=e=>"symbol"==typeof e,P=e=>void 0===e,j=e=>f(e)&&isFinite(e),C=e=>f(e)&&Number.isInteger(e),F=e=>e.filter(Boolean),N=e=>[...new Set(e)],D=(e,t)=>(s(t>0,"Chunk size must be greater than 0"),Array.from({length:Math.ceil(e.length/t)},(r,n)=>e.slice(n*t,(n+1)*t))),E=(...e)=>{if(0===e.length)return[];if(1===e.length)return[...e[0]];const[t,...r]=e;return N(t).filter(e=>r.every(t=>t.includes(e)))},x=(e,t)=>e.filter(e=>!t.includes(e)),B=async(e,t)=>{const r=[];for(let n=0;n<e.length;n++)r.push(await t(e[n],n,e));return r},T=async(e,t)=>Promise.all(e.map(t)),X=async(e,t)=>{const r=await T(e,async(e,r,n)=>!!await t(e,r,n)&&e);return F(r)},Y=async(e,t)=>{for(let r=0;r<e.length;r++)if(await t(e[r],r,e))return!0;return!1},I=async(e,t)=>{for(let r=0;r<e.length;r++)if(!await t(e[r],r,e))return!1;return!0},R=async(e,t,r)=>{let n=r;for(let r=0;r<e.length;r++)n=await t(n,e[r],r,e);return n},$=async(e,t)=>{for(let r=0;r<e.length;r++)if(await t(e[r],r,e))return e[r];return null},L=(...e)=>t=>e.reduce((e,t)=>t(e),t),q=(...e)=>t=>e.reduceRight((e,t)=>t(e),t),z=()=>{},V=(e,...t)=>"function"==typeof e?e(...t):e,Z=e=>new Promise(t=>setTimeout(t,e)),_=(e,{maxAttempts:t=3,delayMs:r=300,backoff:n=!0,onRetry:a}={})=>async(...i)=>{let s;for(let o=1;o<=t;o++)try{return await e(...i)}catch(e){if(s=e,o<t){a?.(o,e);const t=n?r*2**(o-1):r;await Z(t)}}throw s},K=(e,t,r,n)=>{const a=r-e,i=n-t;return Math.sqrt(a**2+i**2)},U=(e,t)=>Math.abs(e/t),W=(e,t)=>e*t/100,G=e=>{const t=window.getComputedStyle(e).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!t)return{translateX:0,translateY:0,scaleX:1,scaleY:1,skewX:0,skewY:0};const[r,n,a,i,s,o]=t[1].split(", ").map(parseFloat);return{translateX:s,translateY:o,scaleX:r,scaleY:i,skewX:a,skewY:n}},H=e=>new Blob([e],{type:e.type}),J=(e,t)=>new File([e],t,{type:e.type});module.exports=t})();
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","mappings":"mBACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,i1BCYhD,MAAMC,EAAeC,GAC1BA,EAAMC,QAAQ,qBAAsB,SAASC,cAqBlCC,EAAmBH,IAE9B,MAAMI,EAAYJ,EAAMK,OAAO,GACzBC,EAAeN,EAAMO,MAAM,GAQjC,OAL2BH,EAAUF,cAGfI,EAAaL,QAAQ,SAAUO,GAAU,IAAIA,EAAON,kBAY/DO,EAAwBT,GAA4BA,EAAMU,MAAM,KAAKC,OAAOC,SA0B5EC,EAAcb,IACzB,IAAIc,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIf,EA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AOD,EAAQH,EAAYC,GAAcN,EAAY,GACxEjH,MAAM,MACNyE,IAAImD,YAEP,MAAO,CACLN,aACAC,aACAC,SACAC,SACAC,QACAC,UAWSE,EAAaC,GAAqB,IAAIC,KAAK,CAACD,GAAO,CAAEE,KAAMF,EAAKE,OAqBhEC,EAAoB,CAACH,EAAYI,IAC5C,IAAIC,KAAK,CAACL,GAAOI,EAAU,CACzBF,KAAMF,EAAKE,O","sources":["webpack://@react-hive/honey-utils/webpack/bootstrap","webpack://@react-hive/honey-utils/webpack/runtime/define property getters","webpack://@react-hive/honey-utils/webpack/runtime/hasOwnProperty shorthand","webpack://@react-hive/honey-utils/webpack/runtime/make namespace object","webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * Converts a string to kebab-case format.\n *\n * This function transforms camelCase or PascalCase strings into kebab-case by inserting\n * hyphens between lowercase and uppercase letters, then converting everything to lowercase.\n *\n * @param input - The string to convert to kebab-case.\n *\n * @returns The kebab-case formatted string.\n *\n * @example\n * ```ts\n * toKebabCase('helloWorld'); // → 'hello-world'\n * toKebabCase('HelloWorld'); // → 'hello-world'\n * toKebabCase('hello123World'); // → 'hello123-world'\n * ```\n */\nexport const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\n/**\n * Converts a camelCase string to dash-case format.\n *\n * This function transforms camelCase strings into dash-case by inserting\n * hyphens before uppercase letters and converting them to lowercase.\n * The function ensures that no hyphen is added at the start of the output string,\n * even if the input begins with an uppercase letter.\n *\n * @param input - The camelCase string to convert to dash-case.\n *\n * @returns The dash-case formatted string.\n *\n * @example\n * ```ts\n * camelToDashCase('helloWorld'); // → 'hello-world'\n * camelToDashCase('HelloWorld'); // → 'hello-world'\n * camelToDashCase('backgroundColor'); // → 'background-color'\n * ```\n */\nexport const camelToDashCase = (input: string): string => {\n // First handle the first character separately to avoid adding a hyphen at the start\n const firstChar = input.charAt(0);\n const restOfString = input.slice(1);\n \n // Convert the first character to lowercase without adding a hyphen\n const firstCharProcessed = firstChar.toLowerCase();\n \n // Process the rest of the string normally, adding hyphens before uppercase letters\n const restProcessed = restOfString.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n \n return firstCharProcessed + restProcessed;\n};\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","export function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\n/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","import { assert } from './guards';\n\n/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n\n/**\n * Returns a new array with duplicate values removed.\n *\n * Uses Set for efficient duplicate removal while preserving the original order.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array that may contain duplicate values.\n *\n * @returns A new array with only unique values, maintaining the original order.\n *\n * @example\n * ```ts\n * unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]\n * unique(['a', 'b', 'a', 'c']); // ['a', 'b', 'c']\n * ```\n */\nexport const unique = <T>(array: T[]): T[] => [...new Set(array)];\n\n/**\n * Splits an array into chunks of the specified size.\n *\n * Useful for pagination, batch processing, or creating grid layouts.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array to be chunked.\n * @param size - The size of each chunk. Must be greater than 0.\n *\n * @returns An array of chunks, where each chunk is an array of the specified size\n * (except possibly the last chunk, which may be smaller).\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]\n * chunk(['a', 'b', 'c', 'd'], 3); // [['a', 'b', 'c'], ['d']]\n * ```\n */\nexport const chunk = <T>(array: T[], size: number): T[][] => {\n assert(size > 0, 'Chunk size must be greater than 0');\n\n return Array.from({ length: Math.ceil(array.length / size) }, (_, index) =>\n array.slice(index * size, (index + 1) * size),\n );\n};\n\n/**\n * Returns an array containing elements that exist in all provided arrays.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param arrays - Two or more arrays to find common elements from.\n *\n * @returns A new array containing only the elements that exist in all input arrays.\n *\n * @example\n * ```ts\n * intersection([1, 2, 3], [2, 3, 4]); // [2, 3]\n * intersection(['a', 'b', 'c'], ['b', 'c', 'd'], ['b', 'e']); // ['b']\n * ```\n */\nexport const intersection = <T>(...arrays: T[][]): T[] => {\n if (arrays.length === 0) {\n return [];\n }\n\n if (arrays.length === 1) {\n return [...arrays[0]];\n }\n\n const [first, ...rest] = arrays;\n const uniqueFirst = unique(first);\n\n return uniqueFirst.filter(item => rest.every(array => array.includes(item)));\n};\n\n/**\n * Returns elements from the first array that don't exist in the second array.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param array - The source array.\n * @param exclude - The array containing elements to exclude.\n *\n * @returns A new array with elements from the first array that don't exist in the second array.\n *\n * @example\n * ```ts\n * difference([1, 2, 3, 4], [2, 4]); // [1, 3]\n * difference(['a', 'b', 'c'], ['b']); // ['a', 'c']\n * ```\n */\nexport const difference = <T>(array: T[], exclude: T[]): T[] =>\n array.filter(item => !exclude.includes(item));\n\n/**\n * Asynchronously iterates over an array and executes an async function on each item sequentially,\n * collecting the results.\n *\n * Unlike `Promise.all`, this runs each promise one after another (not in parallel).\n * Useful when order or timing matters (e.g., rate limits, UI updates, animations).\n *\n * @param array - The array of items to iterate over.\n * @param callbackFn - An async function to execute for each item. Must return a value.\n *\n * @returns A promise that resolves with an array of results from each callback call.\n *\n * @example\n * ```ts\n * const results = await forAsync([1, 2, 3], async (item) => {\n * await delay(100);\n *\n * return item * 2;\n * });\n *\n * console.log(results); // [2, 4, 6]\n * ```\n */\nexport const forAsync = async <Item, Result>(\n array: Item[],\n callbackFn: (item: Item, index: number, array: Item[]) => Promise<Result>,\n): Promise<Result[]> => {\n const results: Result[] = [];\n\n for (let i = 0; i < array.length; i++) {\n results.push(await callbackFn(array[i], i, array));\n }\n\n return results;\n};\n\n/**\n * Executes an asynchronous operation on each element of an array and waits for all promises to resolve.\n *\n * @param array - The array of items to operate on.\n * @param callbackFn - The asynchronous operation to perform on each item.\n *\n * @returns A promise that resolves with an array of results after all operations are completed.\n */\nexport const mapAsync = async <Item, Return>(\n array: Item[],\n callbackFn: (item: Item, index: number, array: Item[]) => Promise<Return>,\n): Promise<Return[]> => Promise.all(array.map(callbackFn));\n\n/**\n * A generic function that processes an array asynchronously and filters the results\n * based on the provided async condition.\n *\n * @template Item - The type of the items in the array.\n * @template Return - The type of the items returned by the condition.\n *\n * @param array - An array of items to be processed.\n * @param callbackFn - An async function that returns a condition for each item.\n *\n * @returns A Promise that resolves to an array of items that match the condition.\n */\nexport const filterAsync = async <Item>(\n array: Item[],\n callbackFn: (item: Item, index: number, array: Item[]) => Promise<boolean>,\n): Promise<Item[]> => {\n const results = await mapAsync(array, async (item, index, array) =>\n (await callbackFn(item, index, array)) ? item : false,\n );\n\n return boolFilter(results);\n};\n\n/**\n * Asynchronously checks if at least one element in the array satisfies the async condition.\n *\n * @param array - The array of items to check.\n * @param callbackFn - An async function that returns a boolean.\n *\n * @returns A promise that resolves to true if any item passes the condition.\n */\nexport const someAsync = async <Item>(\n array: Item[],\n callbackFn: (item: Item, index: number, array: Item[]) => Promise<boolean>,\n): Promise<boolean> => {\n for (let i = 0; i < array.length; i++) {\n if (await callbackFn(array[i], i, array)) {\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Asynchronously checks if all elements in the array satisfy the async condition.\n *\n * @param array - The array of items to check.\n * @param callbackFn - An async function that returns a boolean.\n *\n * @returns A promise that resolves to true if all items pass the condition.\n */\nexport const everyAsync = async <Item>(\n array: Item[],\n callbackFn: (item: Item, index: number, array: Item[]) => Promise<boolean>,\n): Promise<boolean> => {\n for (let i = 0; i < array.length; i++) {\n if (!(await callbackFn(array[i], i, array))) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Asynchronously reduces an array to a single accumulated value.\n *\n * @template Item - The type of items in the array.\n * @template Accumulator - The type of the accumulated result.\n *\n * @param array - The array to reduce.\n * @param callbackFn - The async reducer function that processes each item and returns the updated accumulator.\n * @param initialValue - The initial accumulator value.\n *\n * @returns A promise that resolves to the final accumulated result.\n */\nexport const reduceAsync = async <Item, Accumulator>(\n array: Item[],\n callbackFn: (\n accumulator: Accumulator,\n item: Item,\n index: number,\n array: Item[],\n ) => Promise<Accumulator>,\n initialValue: Accumulator,\n): Promise<Accumulator> => {\n let accumulator = initialValue;\n\n for (let i = 0; i < array.length; i++) {\n accumulator = await callbackFn(accumulator, array[i], i, array);\n }\n\n return accumulator;\n};\n\n/**\n * Asynchronously finds the first element that satisfies the async condition.\n *\n * @param array - The array of items to search.\n * @param callbackFn - An async function that returns a boolean.\n *\n * @returns A promise that resolves to the found item or null if none match.\n */\nexport const findAsync = async <Item>(\n array: Item[],\n callbackFn: (item: Item, index: number, array: Item[]) => Promise<boolean>,\n): Promise<Item | null> => {\n for (let i = 0; i < array.length; i++) {\n if (await callbackFn(array[i], i, array)) {\n return array[i];\n }\n }\n\n return null;\n};\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends unknown[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n\n/**\n * Creates a promise that resolves after the specified delay.\n *\n * Useful for creating artificial delays, implementing timeouts, or spacing operations.\n *\n * @param delayMs - The delay in milliseconds.\n *\n * @returns A promise that resolves after the specified delay.\n *\n * @example\n * ```ts\n * // Wait for 1 second\n * await delay(1000);\n * console.log('This logs after 1 second');\n *\n * // Use with other async operations\n * async function fetchWithTimeout() {\n * const timeoutPromise = delay(5000).then(() => {\n * throw new Error('Request timed out');\n * });\n *\n * return Promise.race([fetchData(), timeoutPromise]);\n * }\n * ```\n */\nexport const delay = (delayMs: number): Promise<void> =>\n new Promise(resolve => setTimeout(resolve, delayMs));\n\ninterface RetryOptions {\n /**\n * Maximum number of retry attempts before failing.\n *\n * @default 3\n */\n maxAttempts?: number;\n /**\n * Delay in milliseconds between retry attempts.\n * If `backoff` is true, this is the base delay for exponential backoff.\n *\n * @default 300\n */\n delayMs?: number;\n /**\n * Whether to use exponential backoff for delays between attempts.\n * When enabled, the delay is multiplied by 2 ^ (`attempt` - 1).\n *\n * @default true\n */\n backoff?: boolean;\n /**\n * Optional callback triggered before each retry attempt.\n *\n * @param attempt - The current attempt number (starting from 1).\n * @param error - The error that caused the retry.\n */\n onRetry?: (attempt: number, error: unknown) => void;\n}\n\n/**\n * Wraps an asynchronous function with retry logic.\n *\n * The returned function will attempt to call the original function up to `maxAttempts` times,\n * with a delay between retries. If all attempts fail, the last encountered error is thrown.\n *\n * Useful for operations that may fail intermittently, such as network requests.\n *\n * @template Task - The type of the async function to wrap.\n * @template TaskResult - The result type of the async function.\n *\n * @param task - The async function to wrap with retry logic.\n * @param options - Configuration options for retry behavior.\n *\n * @returns A function that wraps the original function with retry support.\n *\n * @example\n * ```ts\n * async function fetchData() {\n * const response = await fetch('/api/data');\n *\n * if (!response.ok) {\n * throw new Error('Network error');\n * }\n *\n * return await response.json();\n * }\n *\n * const fetchWithRetry = retry(fetchData, {\n * maxAttempts: 5,\n * delayMs: 500,\n * onRetry: (attempt, error) => {\n * console.warn(`Attempt ${attempt} failed:`, error);\n * }\n * });\n *\n * fetchWithRetry()\n * .then(data => console.log('Success:', data))\n * .catch(error => console.error('Failed after retries:', error));\n * ```\n */\nexport const retry = <Task extends (...args: unknown[]) => Promise<TaskResult>, TaskResult>(\n task: Task,\n { maxAttempts = 3, delayMs = 300, backoff = true, onRetry }: RetryOptions = {},\n): ((...args: Parameters<Task>) => Promise<TaskResult>) => {\n return async (...args: Parameters<Task>): Promise<TaskResult> => {\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await task(...args);\n } catch (e) {\n lastError = e;\n\n if (attempt < maxAttempts) {\n onRetry?.(attempt, e);\n\n const delayTime = backoff ? delayMs * 2 ** (attempt - 1) : delayMs;\n await delay(delayTime);\n }\n }\n }\n\n throw lastError;\n };\n};\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n scaleX: number;\n scaleY: number;\n skewX: number;\n skewY: number;\n}\n\n/**\n * Extracts transformation values (translate, scale, skew) from the 2D transformation matrix of a given HTML element.\n *\n * Only works with 2D transforms (i.e., `matrix(a, b, c, d, e, f)`).\n *\n * @param element - The element with a CSS transform applied.\n * @returns An object with parsed transformation values.\n *\n * @example\n * ```ts\n * const values = parse2DMatrix(myElement);\n * console.log(values.translateX);\n * console.log(values.scaleX);\n * ```\n */\nexport const parse2DMatrix = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrixMatch = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrixMatch) {\n return {\n translateX: 0,\n translateY: 0,\n scaleX: 1,\n scaleY: 1,\n skewX: 0,\n skewY: 0,\n };\n }\n\n const [scaleX, skewY, skewX, scaleY, translateX, translateY] = matrixMatch[1]\n .split(', ')\n .map(parseFloat);\n\n return {\n translateX,\n translateY,\n scaleX,\n scaleY,\n skewX,\n skewY,\n };\n};\n\n/**\n * Creates a clone of a Blob object.\n *\n * @param blob - The Blob object to clone.\n *\n * @returns A new Blob with the same content and type as the original.\n */\nexport const cloneBlob = (blob: Blob): Blob => new Blob([blob], { type: blob.type });\n\n/**\n * Converts a `Blob` object into a `File` object with the specified name.\n *\n * This is useful when you receive a `Blob` (e.g., from canvas, fetch, or file manipulation)\n * and need to convert it into a `File` to upload via `FormData` or file inputs.\n *\n * @param blob - The `Blob` to convert.\n * @param fileName - The desired name for the resulting file (including extension).\n *\n * @returns A `File` instance with the same content and MIME type as the input `Blob`.\n *\n * @example\n * ```ts\n * const blob = new Blob(['Hello world'], { type: 'text/plain' });\n * const file = convertBlobToFile(blob, 'hello.txt');\n *\n * console.log(file instanceof File); // true\n * ```\n */\nexport const convertBlobToFile = (blob: Blob, fileName: string): File =>\n new File([blob], fileName, {\n type: blob.type,\n });\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","toKebabCase","input","replace","toLowerCase","camelToDashCase","firstChar","charAt","restOfString","slice","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","assert","condition","message","Error","isNull","isString","isNumber","isBool","isObject","isEmptyObject","keys","isArray","Array","isEmptyArray","isFunction","isPromise","then","isNil","isNilOrEmptyString","isDate","Date","isValidDate","isNaN","getTime","isRegExp","RegExp","isMap","Map","isSet","Set","isSymbol","isUndefined","undefined","isFiniteNumber","isFinite","isInteger","Number","boolFilter","array","unique","chunk","size","from","Math","ceil","_","index","intersection","arrays","first","rest","item","every","includes","difference","exclude","forAsync","async","callbackFn","results","push","mapAsync","Promise","all","map","filterAsync","someAsync","everyAsync","reduceAsync","initialValue","accumulator","findAsync","noop","invokeIfFunction","args","delay","delayMs","resolve","setTimeout","retry","task","maxAttempts","backoff","onRetry","lastError","attempt","e","delayTime","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","parse2DMatrix","element","matrixMatch","window","getComputedStyle","getPropertyValue","match","translateX","translateY","scaleX","scaleY","skewX","skewY","parseFloat","cloneBlob","blob","Blob","type","convertBlobToFile","fileName","File"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.cjs","mappings":"mBACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,a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B,CAAE,MAAOY,GAGP,GAFAF,EAAYE,EAERD,EAAUJ,EAAa,CACzBE,IAAUE,EAASC,GAEnB,MAAMC,EAAYL,EAAUN,EAAU,IAAMS,EAAU,GAAKT,QACrDD,EAAMY,EACd,CACF,CAGF,MAAMH,GClIGI,EAA6B,CACxCC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASF,EAAOF,EAChBK,EAASF,EAAOF,EAEtB,OAAOvD,KAAK4D,KAAKF,GAAU,EAAIC,GAAU,IAW9BE,EAAuB,CAACC,EAAeC,IAClD/D,KAAKgE,IAAIF,EAAQC,GAUNE,EAAsB,CAAClI,EAAemI,IACzCnI,EAAQmI,EAAc,IClBnBC,EAAiBC,IAC5B,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEpBC,MAAM,oBACzC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,EACZC,OAAQ,EACRC,OAAQ,EACRC,MAAO,EACPC,MAAO,GAIX,MAAOH,EAAQG,EAAOD,EAAOD,EAAQH,EAAYC,GAAcN,EAAY,GACxE1H,MAAM,MACN0E,IAAI2D,YAEP,MAAO,CACLN,aACAC,aACAC,SACAC,SACAC,QACAC,UAWSE,EAAaC,GAAqB,IAAIC,KAAK,CAACD,GAAO,CAAEE,KAAMF,EAAKE,OAqBhEC,EAAoB,CAACH,EAAYI,IAC5C,IAAIC,KAAK,CAACL,GAAOI,EAAU,CACzBF,KAAMF,EAAKE,O","sources":["webpack://@react-hive/honey-utils/webpack/bootstrap","webpack://@react-hive/honey-utils/webpack/runtime/define property getters","webpack://@react-hive/honey-utils/webpack/runtime/hasOwnProperty shorthand","webpack://@react-hive/honey-utils/webpack/runtime/make namespace object","webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * Converts a string to kebab-case format.\n *\n * This function transforms camelCase or PascalCase strings into kebab-case by inserting\n * hyphens between lowercase and uppercase letters, then converting everything to lowercase.\n *\n * @param input - The string to convert to kebab-case.\n *\n * @returns The kebab-case formatted string.\n *\n * @example\n * ```ts\n * toKebabCase('helloWorld'); // → 'hello-world'\n * toKebabCase('HelloWorld'); // → 'hello-world'\n * toKebabCase('hello123World'); // → 'hello123-world'\n * ```\n */\nexport const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\n/**\n * Converts a camelCase string to dash-case format.\n *\n * This function transforms camelCase strings into dash-case by inserting\n * hyphens before uppercase letters and converting them to lowercase.\n * The function ensures that no hyphen is added at the start of the output string,\n * even if the input begins with an uppercase letter.\n *\n * @param input - The camelCase string to convert to dash-case.\n *\n * @returns The dash-case formatted string.\n *\n * @example\n * ```ts\n * camelToDashCase('helloWorld'); // → 'hello-world'\n * camelToDashCase('HelloWorld'); // → 'hello-world'\n * camelToDashCase('backgroundColor'); // → 'background-color'\n * ```\n */\nexport const camelToDashCase = (input: string): string => {\n // First handle the first character separately to avoid adding a hyphen at the start\n const firstChar = input.charAt(0);\n const restOfString = input.slice(1);\n \n // Convert the first character to lowercase without adding a hyphen\n const firstCharProcessed = firstChar.toLowerCase();\n \n // Process the rest of the string normally, adding hyphens before uppercase letters\n const restProcessed = restOfString.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n \n return firstCharProcessed + restProcessed;\n};\n\n/**\n * Splits a string into an array of filtered from redundant spaces words.\n *\n * @param input - The input string to be split.\n *\n * @returns An array of words from the input string.\n */\nexport const splitStringIntoWords = (input: string): string[] => input.split(' ').filter(Boolean);\n\n/**\n * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.\n *\n * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm\n * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer,\n * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output.\n *\n * Useful for:\n * - Generating stable class names in CSS-in-JS libraries.\n * - Producing consistent cache keys.\n * - Quick and lightweight hashing needs where cryptographic security is not required.\n *\n * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.\n *\n * @param input - The input string to hash.\n *\n * @returns A short, base-36 encoded hash string.\n *\n * @example\n * ```ts\n * const className = hashString('background-color: red;');\n * // → 'e4k1z0x'\n * ```\n */\nexport const hashString = (input: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < input.length; i++) {\n hash = (hash * 33) ^ input.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","export function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\n/**\n * Checks if a value is null.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is null; otherwise, `false`.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if a value is null or undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is `null` or `undefined`, otherwise `false`.\n */\nexport const isNil = (value: unknown): value is null | undefined =>\n value === undefined || value === null;\n\n/**\n * Checks whether the provided value is considered \"empty\".\n *\n * A value is considered empty if it is:\n * - `null`\n * - `undefined`\n * - `''`\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is empty; otherwise, `false`.\n */\nexport const isNilOrEmptyString = (value: unknown): value is null | undefined =>\n value === '' || isNil(value);\n\n/**\n * Checks if a value is neither `null` nor `undefined`.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is defined (not `null` or `undefined`); otherwise, `false`.\n */\nexport const isDefined = <T>(value: T): value is NonNullable<T> =>\n value !== null && value !== undefined;\n\n/**\n * Checks if a value is a string.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a string; otherwise, `false`.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if a value is a number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a number; otherwise, `false`.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if a value is a boolean.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a boolean; otherwise, `false`.\n */\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\n/**\n * Checks if a value is an object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an object; otherwise, `false`.\n */\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\n/**\n * Checks if a value is an empty object (no own enumerable properties).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty object; otherwise, `false`.\n */\nexport const isEmptyObject = (value: unknown): value is Record<string, never> =>\n isObject(value) && !isNull(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if a value is an array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an array; otherwise, `false`.\n */\nexport const isArray = (value: unknown): value is unknown[] => Array.isArray(value);\n\n/**\n * Checks if a value is an empty array.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an empty array; otherwise, `false`.\n */\nexport const isEmptyArray = (value: unknown): value is [] => isArray(value) && value.length === 0;\n\n/**\n * Checks if a value is a function.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a function; otherwise, `false`.\n */\nexport const isFunction = (value: unknown) => typeof value === 'function';\n\n/**\n * Checks if a value is a Promise.\n *\n * @template T - The type of the value that the Promise resolves to.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Promise; otherwise, `false`.\n */\nexport const isPromise = <T = unknown>(value: unknown): value is Promise<T> =>\n isFunction((value as Promise<T>)?.then);\n\n/**\n * Checks if a value is a Date object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Date object; otherwise, `false`.\n */\nexport const isDate = (value: unknown): value is Date => value instanceof Date;\n\n/**\n * Checks if a value is a valid Date object (not Invalid Date).\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a valid Date object; otherwise, `false`.\n */\nexport const isValidDate = (value: unknown): value is Date =>\n isDate(value) && !isNaN(value.getTime());\n\n/**\n * Checks if a value is a RegExp object.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a RegExp object; otherwise, `false`.\n */\nexport const isRegExp = (value: unknown): value is RegExp => value instanceof RegExp;\n\n/**\n * Checks if a value is a Map.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Map; otherwise, `false`.\n */\nexport const isMap = (value: unknown): value is Map<unknown, unknown> => value instanceof Map;\n\n/**\n * Checks if a value is a Set.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Set; otherwise, `false`.\n */\nexport const isSet = (value: unknown): value is Set<unknown> => value instanceof Set;\n\n/**\n * Checks if a value is a Symbol.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a Symbol; otherwise, `false`.\n */\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol';\n\n/**\n * Checks if a value is undefined.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is undefined; otherwise, `false`.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if a value is a finite number.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is a finite number; otherwise, `false`.\n */\nexport const isFiniteNumber = (value: unknown): value is number =>\n isNumber(value) && isFinite(value);\n\n/**\n * Checks if a value is an integer.\n *\n * @param value - The value to check.\n *\n * @returns `true` if the value is an integer; otherwise, `false`.\n */\nexport const isInteger = (value: unknown): value is number =>\n isNumber(value) && Number.isInteger(value);\n","import { assert } from './guards';\n\n/**\n * Filters out `null`, `undefined`, and other falsy values from an array,\n * returning a typed array of only truthy `Item` values.\n *\n * Useful when working with optional or nullable items that need to be sanitized.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - An array of items that may include `null`, `undefined`, or falsy values.\n *\n * @returns A new array containing only truthy `Item` values.\n */\nexport const boolFilter = <T>(array: (T | false | null | undefined)[]): T[] =>\n array.filter(Boolean) as T[];\n\n/**\n * Returns a new array with duplicate values removed.\n *\n * Uses Set for efficient duplicate removal while preserving the original order.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array that may contain duplicate values.\n *\n * @returns A new array with only unique values, maintaining the original order.\n *\n * @example\n * ```ts\n * unique([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]\n * unique(['a', 'b', 'a', 'c']); // ['a', 'b', 'c']\n * ```\n */\nexport const unique = <T>(array: T[]): T[] => [...new Set(array)];\n\n/**\n * Splits an array into chunks of the specified size.\n *\n * Useful for pagination, batch processing, or creating grid layouts.\n *\n * @template T - The type of the items in the array.\n *\n * @param array - The input array to be chunked.\n * @param size - The size of each chunk. Must be greater than 0.\n *\n * @returns An array of chunks, where each chunk is an array of the specified size\n * (except possibly the last chunk, which may be smaller).\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]\n * chunk(['a', 'b', 'c', 'd'], 3); // [['a', 'b', 'c'], ['d']]\n * ```\n */\nexport const chunk = <T>(array: T[], size: number): T[][] => {\n assert(size > 0, 'Chunk size must be greater than 0');\n\n return Array.from({ length: Math.ceil(array.length / size) }, (_, index) =>\n array.slice(index * size, (index + 1) * size),\n );\n};\n\n/**\n * Returns an array containing elements that exist in all provided arrays.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param arrays - Two or more arrays to find common elements from.\n *\n * @returns A new array containing only the elements that exist in all input arrays.\n *\n * @example\n * ```ts\n * intersection([1, 2, 3], [2, 3, 4]); // [2, 3]\n * intersection(['a', 'b', 'c'], ['b', 'c', 'd'], ['b', 'e']); // ['b']\n * ```\n */\nexport const intersection = <T>(...arrays: T[][]): T[] => {\n if (arrays.length === 0) {\n return [];\n }\n\n if (arrays.length === 1) {\n return [...arrays[0]];\n }\n\n const [first, ...rest] = arrays;\n const uniqueFirst = unique(first);\n\n return uniqueFirst.filter(item => rest.every(array => array.includes(item)));\n};\n\n/**\n * Returns elements from the first array that don't exist in the second array.\n *\n * @template T - The type of the items in the arrays.\n *\n * @param array - The source array.\n * @param exclude - The array containing elements to exclude.\n *\n * @returns A new array with elements from the first array that don't exist in the second array.\n *\n * @example\n * ```ts\n * difference([1, 2, 3, 4], [2, 4]); // [1, 3]\n * difference(['a', 'b', 'c'], ['b']); // ['a', 'c']\n * ```\n */\nexport const difference = <T>(array: T[], exclude: T[]): T[] =>\n array.filter(item => !exclude.includes(item));\n\n/**\n * Asynchronously iterates over an array and executes an async function on each item sequentially,\n * collecting the results.\n *\n * Unlike `Promise.all`, this runs each promise one after another (not in parallel).\n * Useful when order or timing matters (e.g., rate limits, UI updates, animations).\n *\n * @param array - The array of items to iterate over.\n * @param predicate - An async function to execute for each item. Must return a value.\n *\n * @returns A promise that resolves with an array of results from each predicate call.\n *\n * @example\n * ```ts\n * const results = await forAsync([1, 2, 3], async (item) => {\n * await delay(100);\n *\n * return item * 2;\n * });\n *\n * console.log(results); // [2, 4, 6]\n * ```\n */\nexport const forAsync = async <Item, Result>(\n array: Item[],\n predicate: (item: Item, index: number, array: Item[]) => Promise<Result>,\n): Promise<Result[]> => {\n const results: Result[] = [];\n\n for (let i = 0; i < array.length; i++) {\n results.push(await predicate(array[i], i, array));\n }\n\n return results;\n};\n\n/**\n * Executes an asynchronous operation on each element of an array and waits for all promises to resolve.\n *\n * @param array - The array of items to operate on.\n * @param predicate - The asynchronous operation to perform on each item.\n *\n * @returns A promise that resolves with an array of results after all operations are completed.\n */\nexport const mapAsync = async <Item, Return>(\n array: Item[],\n predicate: (item: Item, index: number, array: Item[]) => Promise<Return>,\n): Promise<Return[]> => Promise.all(array.map(predicate));\n\n/**\n * A generic function that processes an array asynchronously and filters the results\n * based on the provided async condition.\n *\n * @template Item - The type of the items in the array.\n * @template Return - The type of the items returned by the condition.\n *\n * @param array - An array of items to be processed.\n * @param predicate - An async function that returns a condition for each item.\n *\n * @returns A Promise that resolves to an array of items that match the condition.\n */\nexport const filterAsync = async <Item>(\n array: Item[],\n predicate: (item: Item, index: number, array: Item[]) => Promise<boolean>,\n): Promise<Item[]> => {\n const results = await mapAsync(array, async (item, index, array) =>\n (await predicate(item, index, array)) ? item : false,\n );\n\n return boolFilter(results);\n};\n\n/**\n * Asynchronously checks if at least one element in the array satisfies the async condition.\n *\n * @param array - The array of items to check.\n * @param predicate - An async function that returns a boolean.\n *\n * @returns A promise that resolves to true if any item passes the condition.\n */\nexport const someAsync = async <Item>(\n array: Item[],\n predicate: (item: Item, index: number, array: Item[]) => Promise<boolean>,\n): Promise<boolean> => {\n for (let i = 0; i < array.length; i++) {\n if (await predicate(array[i], i, array)) {\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * Asynchronously checks if all elements in the array satisfy the async condition.\n *\n * @param array - The array of items to check.\n * @param predicate - An async function that returns a boolean.\n *\n * @returns A promise that resolves to true if all items pass the condition.\n */\nexport const everyAsync = async <Item>(\n array: Item[],\n predicate: (item: Item, index: number, array: Item[]) => Promise<boolean>,\n): Promise<boolean> => {\n for (let i = 0; i < array.length; i++) {\n if (!(await predicate(array[i], i, array))) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Asynchronously reduces an array to a single accumulated value.\n *\n * @template Item - The type of items in the array.\n * @template Accumulator - The type of the accumulated result.\n *\n * @param array - The array to reduce.\n * @param predicate - The async reducer function that processes each item and returns the updated accumulator.\n * @param initialValue - The initial accumulator value.\n *\n * @returns A promise that resolves to the final accumulated result.\n */\nexport const reduceAsync = async <Item, Accumulator>(\n array: Item[],\n predicate: (\n accumulator: Accumulator,\n item: Item,\n index: number,\n array: Item[],\n ) => Promise<Accumulator>,\n initialValue: Accumulator,\n): Promise<Accumulator> => {\n let accumulator = initialValue;\n\n for (let i = 0; i < array.length; i++) {\n accumulator = await predicate(accumulator, array[i], i, array);\n }\n\n return accumulator;\n};\n\n/**\n * Asynchronously finds the first element that satisfies the async condition.\n *\n * @param array - The array of items to search.\n * @param predicate - An async function that returns a boolean.\n *\n * @returns A promise that resolves to the found item or null if none match.\n */\nexport const findAsync = async <Item>(\n array: Item[],\n predicate: (item: Item, index: number, array: Item[]) => Promise<boolean>,\n): Promise<Item | null> => {\n for (let i = 0; i < array.length; i++) {\n if (await predicate(array[i], i, array)) {\n return array[i];\n }\n }\n\n return null;\n};\n\ntype PipeFn = (arg: unknown) => unknown;\n\ntype Pipe = {\n <A, B>(fn1: (a: A) => B): (a: A) => B;\n <A, B, C>(fn1: (a: A) => B, fn2: (b: B) => C): (a: A) => C;\n <A, B, C, D>(fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): (a: A) => D;\n <A, B, C, D, E>(\n fn1: (a: A) => B,\n fn2: (b: B) => C,\n fn3: (c: C) => D,\n fn4: (d: D) => E,\n ): (a: A) => E;\n <A, B, C, D, E, F>(\n fn1: (a: A) => B,\n fn2: (b: B) => C,\n fn3: (c: C) => D,\n fn4: (d: D) => E,\n fn5: (e: E) => F,\n ): (a: A) => F;\n (...fns: PipeFn[]): (arg: unknown) => unknown;\n};\n\n/**\n * Composes multiple unary functions into a single function, applying them from left to right.\n *\n * Useful for building a data processing pipeline where the output of one function becomes the input of the next.\n *\n * Types are inferred up to 5 chained functions for full type safety. Beyond that, it falls back to the unknown.\n *\n * @param fns - A list of unary functions to compose.\n *\n * @returns A new function that applies all functions from left to right.\n *\n * @example\n * ```ts\n * const add = (x: number) => x + 1;\n * const double = (x: number) => x * 2;\n * const toStr = (x: number) => `Result: ${x}`;\n *\n * const result = pipe(add, double, toStr)(2);\n * // => 'Result: 6'\n * ```\n */\nexport const pipe: Pipe =\n (...fns: PipeFn[]) =>\n (arg: unknown) =>\n fns.reduce((prev, fn) => fn(prev), arg);\n\ntype ComposeFn = (arg: unknown) => unknown;\n\ntype Compose = {\n <A, R>(fn1: (a: A) => R): (a: A) => R;\n <A, B, R>(fn1: (b: B) => R, fn2: (a: A) => B): (a: A) => R;\n <A, B, C, R>(fn1: (c: C) => R, fn2: (b: B) => C, fn3: (a: A) => B): (a: A) => R;\n <A, B, C, D, R>(\n fn1: (d: D) => R,\n fn2: (c: C) => D,\n fn3: (b: B) => C,\n fn4: (a: A) => B,\n ): (a: A) => R;\n <A, B, C, D, E, R>(\n fn1: (e: E) => R,\n fn2: (d: D) => E,\n fn3: (c: C) => D,\n fn4: (b: B) => C,\n fn5: (a: A) => B,\n ): (a: A) => R;\n (...fns: ComposeFn[]): (arg: unknown) => unknown;\n};\n\n/**\n * Composes multiple unary functions into a single function, applying them from **right to left**.\n *\n * Often used for building functional pipelines where the innermost function runs first.\n * Types are inferred up to 5 chained functions for full type safety.\n *\n * @param fns - A list of unary functions to compose.\n *\n * @returns A new function that applies all functions from right to left.\n *\n * @example\n * ```ts\n * const add = (x: number) => x + 1;\n * const double = (x: number) => x * 2;\n * const toStr = (x: number) => `Result: ${x}`;\n *\n * const result = compose(toStr, double, add)(2);\n * // => 'Result: 6'\n * ```\n */\nexport const compose: Compose =\n (...fns: ComposeFn[]) =>\n (arg: unknown) =>\n fns.reduceRight((prev, fn) => fn(prev), arg);\n","export const noop = () => {};\n\n/**\n * Invokes the given input if it is a function, passing the provided arguments.\n * Otherwise, returns the input as-is.\n *\n * @template Args - Tuple of argument types to pass to the function.\n * @template Result - Return type of the function or the value.\n *\n * @param input - A function to invoke with `args`, or a direct value of type `Result`.\n * @param args - Arguments to pass if `input` is a function.\n *\n * @returns The result of invoking the function, or the original value if it's not a function.\n */\nexport const invokeIfFunction = <Args extends unknown[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n\n/**\n * Creates a promise that resolves after the specified delay.\n *\n * Useful for creating artificial delays, implementing timeouts, or spacing operations.\n *\n * @param delayMs - The delay in milliseconds.\n *\n * @returns A promise that resolves after the specified delay.\n *\n * @example\n * ```ts\n * // Wait for 1 second\n * await delay(1000);\n * console.log('This logs after 1 second');\n *\n * // Use with other async operations\n * async function fetchWithTimeout() {\n * const timeoutPromise = delay(5000).then(() => {\n * throw new Error('Request timed out');\n * });\n *\n * return Promise.race([fetchData(), timeoutPromise]);\n * }\n * ```\n */\nexport const delay = (delayMs: number): Promise<void> =>\n new Promise(resolve => setTimeout(resolve, delayMs));\n\ninterface RetryOptions {\n /**\n * Maximum number of retry attempts before failing.\n *\n * @default 3\n */\n maxAttempts?: number;\n /**\n * Delay in milliseconds between retry attempts.\n * If `backoff` is true, this is the base delay for exponential backoff.\n *\n * @default 300\n */\n delayMs?: number;\n /**\n * Whether to use exponential backoff for delays between attempts.\n * When enabled, the delay is multiplied by 2 ^ (`attempt` - 1).\n *\n * @default true\n */\n backoff?: boolean;\n /**\n * Optional callback triggered before each retry attempt.\n *\n * @param attempt - The current attempt number (starting from 1).\n * @param error - The error that caused the retry.\n */\n onRetry?: (attempt: number, error: unknown) => void;\n}\n\n/**\n * Wraps an asynchronous function with retry logic.\n *\n * The returned function will attempt to call the original function up to `maxAttempts` times,\n * with a delay between retries. If all attempts fail, the last encountered error is thrown.\n *\n * Useful for operations that may fail intermittently, such as network requests.\n *\n * @template Task - The type of the async function to wrap.\n * @template TaskResult - The result type of the async function.\n *\n * @param task - The async function to wrap with retry logic.\n * @param options - Configuration options for retry behavior.\n *\n * @returns A function that wraps the original function with retry support.\n *\n * @example\n * ```ts\n * async function fetchData() {\n * const response = await fetch('/api/data');\n *\n * if (!response.ok) {\n * throw new Error('Network error');\n * }\n *\n * return await response.json();\n * }\n *\n * const fetchWithRetry = retry(fetchData, {\n * maxAttempts: 5,\n * delayMs: 500,\n * onRetry: (attempt, error) => {\n * console.warn(`Attempt ${attempt} failed:`, error);\n * }\n * });\n *\n * fetchWithRetry()\n * .then(data => console.log('Success:', data))\n * .catch(error => console.error('Failed after retries:', error));\n * ```\n */\nexport const retry = <Task extends (...args: unknown[]) => Promise<TaskResult>, TaskResult>(\n task: Task,\n { maxAttempts = 3, delayMs = 300, backoff = true, onRetry }: RetryOptions = {},\n): ((...args: Parameters<Task>) => Promise<TaskResult>) => {\n return async (...args: Parameters<Task>): Promise<TaskResult> => {\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n return await task(...args);\n } catch (e) {\n lastError = e;\n\n if (attempt < maxAttempts) {\n onRetry?.(attempt, e);\n\n const delayTime = backoff ? delayMs * 2 ** (attempt - 1) : delayMs;\n await delay(delayTime);\n }\n }\n }\n\n throw lastError;\n };\n};\n","/**\n * Calculates the Euclidean distance between two points in 2D space.\n *\n * @param startX - The X coordinate of the starting point.\n * @param startY - The Y coordinate of the starting point.\n * @param endX - The X coordinate of the ending point.\n * @param endY - The Y coordinate of the ending point.\n *\n * @returns The Euclidean distance between the two points.\n */\nexport const calculateEuclideanDistance = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): number => {\n const deltaX = endX - startX;\n const deltaY = endY - startY;\n\n return Math.sqrt(deltaX ** 2 + deltaY ** 2);\n};\n\n/**\n * Calculates the moving speed.\n *\n * @param delta - The change in position (distance).\n * @param elapsedTime - The time taken to move the distance.\n *\n * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.\n */\nexport const calculateMovingSpeed = (delta: number, elapsedTime: number): number =>\n Math.abs(delta / elapsedTime);\n\n/**\n * Calculates the specified percentage of a given value.\n *\n * @param value - The value to calculate the percentage of.\n * @param percentage - The percentage to calculate.\n *\n * @returns The calculated percentage of the value.\n */\nexport const calculatePercentage = (value: number, percentage: number): number => {\n return (value * percentage) / 100;\n};\n","interface HTMLElementTransformationValues {\n translateX: number;\n translateY: number;\n scaleX: number;\n scaleY: number;\n skewX: number;\n skewY: number;\n}\n\n/**\n * Extracts transformation values (translate, scale, skew) from the 2D transformation matrix of a given HTML element.\n *\n * Only works with 2D transforms (i.e., `matrix(a, b, c, d, e, f)`).\n *\n * @param element - The element with a CSS transform applied.\n * @returns An object with parsed transformation values.\n *\n * @example\n * ```ts\n * const values = parse2DMatrix(myElement);\n * console.log(values.translateX);\n * console.log(values.scaleX);\n * ```\n */\nexport const parse2DMatrix = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrixMatch = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrixMatch) {\n return {\n translateX: 0,\n translateY: 0,\n scaleX: 1,\n scaleY: 1,\n skewX: 0,\n skewY: 0,\n };\n }\n\n const [scaleX, skewY, skewX, scaleY, translateX, translateY] = matrixMatch[1]\n .split(', ')\n .map(parseFloat);\n\n return {\n translateX,\n translateY,\n scaleX,\n scaleY,\n skewX,\n skewY,\n };\n};\n\n/**\n * Creates a clone of a Blob object.\n *\n * @param blob - The Blob object to clone.\n *\n * @returns A new Blob with the same content and type as the original.\n */\nexport const cloneBlob = (blob: Blob): Blob => new Blob([blob], { type: blob.type });\n\n/**\n * Converts a `Blob` object into a `File` object with the specified name.\n *\n * This is useful when you receive a `Blob` (e.g., from canvas, fetch, or file manipulation)\n * and need to convert it into a `File` to upload via `FormData` or file inputs.\n *\n * @param blob - The `Blob` to convert.\n * @param fileName - The desired name for the resulting file (including extension).\n *\n * @returns A `File` instance with the same content and MIME type as the input `Blob`.\n *\n * @example\n * ```ts\n * const blob = new Blob(['Hello world'], { type: 'text/plain' });\n * const file = convertBlobToFile(blob, 'hello.txt');\n *\n * console.log(file instanceof File); // true\n * ```\n */\nexport const convertBlobToFile = (blob: Blob, fileName: string): File =>\n new File([blob], fileName, {\n type: blob.type,\n });\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","toKebabCase","input","replace","toLowerCase","camelToDashCase","firstChar","charAt","restOfString","slice","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","assert","condition","message","Error","isNull","isNil","isNilOrEmptyString","isDefined","isString","isNumber","isBool","isObject","isEmptyObject","keys","isArray","Array","isEmptyArray","isFunction","isPromise","then","isDate","Date","isValidDate","isNaN","getTime","isRegExp","RegExp","isMap","Map","isSet","Set","isSymbol","isUndefined","undefined","isFiniteNumber","isFinite","isInteger","Number","boolFilter","array","unique","chunk","size","from","Math","ceil","_","index","intersection","arrays","first","rest","item","every","includes","difference","exclude","forAsync","async","predicate","results","push","mapAsync","Promise","all","map","filterAsync","someAsync","everyAsync","reduceAsync","initialValue","accumulator","findAsync","pipe","fns","arg","reduce","prev","fn","compose","reduceRight","noop","invokeIfFunction","args","delay","delayMs","resolve","setTimeout","retry","task","maxAttempts","backoff","onRetry","lastError","attempt","e","delayTime","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","parse2DMatrix","element","matrixMatch","window","getComputedStyle","getPropertyValue","match","translateX","translateY","scaleX","scaleY","skewX","skewY","parseFloat","cloneBlob","blob","Blob","type","convertBlobToFile","fileName","File"],"sourceRoot":""}
|
package/dist/index.dev.cjs
CHANGED
|
@@ -12,6 +12,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
12
12
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
13
13
|
/* harmony export */ boolFilter: () => (/* binding */ boolFilter),
|
|
14
14
|
/* harmony export */ chunk: () => (/* binding */ chunk),
|
|
15
|
+
/* harmony export */ compose: () => (/* binding */ compose),
|
|
15
16
|
/* harmony export */ difference: () => (/* binding */ difference),
|
|
16
17
|
/* harmony export */ everyAsync: () => (/* binding */ everyAsync),
|
|
17
18
|
/* harmony export */ filterAsync: () => (/* binding */ filterAsync),
|
|
@@ -19,6 +20,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
19
20
|
/* harmony export */ forAsync: () => (/* binding */ forAsync),
|
|
20
21
|
/* harmony export */ intersection: () => (/* binding */ intersection),
|
|
21
22
|
/* harmony export */ mapAsync: () => (/* binding */ mapAsync),
|
|
23
|
+
/* harmony export */ pipe: () => (/* binding */ pipe),
|
|
22
24
|
/* harmony export */ reduceAsync: () => (/* binding */ reduceAsync),
|
|
23
25
|
/* harmony export */ someAsync: () => (/* binding */ someAsync),
|
|
24
26
|
/* harmony export */ unique: () => (/* binding */ unique)
|
|
@@ -130,9 +132,9 @@ const difference = (array, exclude) => array.filter(item => !exclude.includes(it
|
|
|
130
132
|
* Useful when order or timing matters (e.g., rate limits, UI updates, animations).
|
|
131
133
|
*
|
|
132
134
|
* @param array - The array of items to iterate over.
|
|
133
|
-
* @param
|
|
135
|
+
* @param predicate - An async function to execute for each item. Must return a value.
|
|
134
136
|
*
|
|
135
|
-
* @returns A promise that resolves with an array of results from each
|
|
137
|
+
* @returns A promise that resolves with an array of results from each predicate call.
|
|
136
138
|
*
|
|
137
139
|
* @example
|
|
138
140
|
* ```ts
|
|
@@ -145,10 +147,10 @@ const difference = (array, exclude) => array.filter(item => !exclude.includes(it
|
|
|
145
147
|
* console.log(results); // [2, 4, 6]
|
|
146
148
|
* ```
|
|
147
149
|
*/
|
|
148
|
-
const forAsync = async (array,
|
|
150
|
+
const forAsync = async (array, predicate) => {
|
|
149
151
|
const results = [];
|
|
150
152
|
for (let i = 0; i < array.length; i++) {
|
|
151
|
-
results.push(await
|
|
153
|
+
results.push(await predicate(array[i], i, array));
|
|
152
154
|
}
|
|
153
155
|
return results;
|
|
154
156
|
};
|
|
@@ -156,11 +158,11 @@ const forAsync = async (array, callbackFn) => {
|
|
|
156
158
|
* Executes an asynchronous operation on each element of an array and waits for all promises to resolve.
|
|
157
159
|
*
|
|
158
160
|
* @param array - The array of items to operate on.
|
|
159
|
-
* @param
|
|
161
|
+
* @param predicate - The asynchronous operation to perform on each item.
|
|
160
162
|
*
|
|
161
163
|
* @returns A promise that resolves with an array of results after all operations are completed.
|
|
162
164
|
*/
|
|
163
|
-
const mapAsync = async (array,
|
|
165
|
+
const mapAsync = async (array, predicate) => Promise.all(array.map(predicate));
|
|
164
166
|
/**
|
|
165
167
|
* A generic function that processes an array asynchronously and filters the results
|
|
166
168
|
* based on the provided async condition.
|
|
@@ -169,25 +171,25 @@ const mapAsync = async (array, callbackFn) => Promise.all(array.map(callbackFn))
|
|
|
169
171
|
* @template Return - The type of the items returned by the condition.
|
|
170
172
|
*
|
|
171
173
|
* @param array - An array of items to be processed.
|
|
172
|
-
* @param
|
|
174
|
+
* @param predicate - An async function that returns a condition for each item.
|
|
173
175
|
*
|
|
174
176
|
* @returns A Promise that resolves to an array of items that match the condition.
|
|
175
177
|
*/
|
|
176
|
-
const filterAsync = async (array,
|
|
177
|
-
const results = await mapAsync(array, async (item, index, array) => (await
|
|
178
|
+
const filterAsync = async (array, predicate) => {
|
|
179
|
+
const results = await mapAsync(array, async (item, index, array) => (await predicate(item, index, array)) ? item : false);
|
|
178
180
|
return boolFilter(results);
|
|
179
181
|
};
|
|
180
182
|
/**
|
|
181
183
|
* Asynchronously checks if at least one element in the array satisfies the async condition.
|
|
182
184
|
*
|
|
183
185
|
* @param array - The array of items to check.
|
|
184
|
-
* @param
|
|
186
|
+
* @param predicate - An async function that returns a boolean.
|
|
185
187
|
*
|
|
186
188
|
* @returns A promise that resolves to true if any item passes the condition.
|
|
187
189
|
*/
|
|
188
|
-
const someAsync = async (array,
|
|
190
|
+
const someAsync = async (array, predicate) => {
|
|
189
191
|
for (let i = 0; i < array.length; i++) {
|
|
190
|
-
if (await
|
|
192
|
+
if (await predicate(array[i], i, array)) {
|
|
191
193
|
return true;
|
|
192
194
|
}
|
|
193
195
|
}
|
|
@@ -197,13 +199,13 @@ const someAsync = async (array, callbackFn) => {
|
|
|
197
199
|
* Asynchronously checks if all elements in the array satisfy the async condition.
|
|
198
200
|
*
|
|
199
201
|
* @param array - The array of items to check.
|
|
200
|
-
* @param
|
|
202
|
+
* @param predicate - An async function that returns a boolean.
|
|
201
203
|
*
|
|
202
204
|
* @returns A promise that resolves to true if all items pass the condition.
|
|
203
205
|
*/
|
|
204
|
-
const everyAsync = async (array,
|
|
206
|
+
const everyAsync = async (array, predicate) => {
|
|
205
207
|
for (let i = 0; i < array.length; i++) {
|
|
206
|
-
if (!(await
|
|
208
|
+
if (!(await predicate(array[i], i, array))) {
|
|
207
209
|
return false;
|
|
208
210
|
}
|
|
209
211
|
}
|
|
@@ -216,15 +218,15 @@ const everyAsync = async (array, callbackFn) => {
|
|
|
216
218
|
* @template Accumulator - The type of the accumulated result.
|
|
217
219
|
*
|
|
218
220
|
* @param array - The array to reduce.
|
|
219
|
-
* @param
|
|
221
|
+
* @param predicate - The async reducer function that processes each item and returns the updated accumulator.
|
|
220
222
|
* @param initialValue - The initial accumulator value.
|
|
221
223
|
*
|
|
222
224
|
* @returns A promise that resolves to the final accumulated result.
|
|
223
225
|
*/
|
|
224
|
-
const reduceAsync = async (array,
|
|
226
|
+
const reduceAsync = async (array, predicate, initialValue) => {
|
|
225
227
|
let accumulator = initialValue;
|
|
226
228
|
for (let i = 0; i < array.length; i++) {
|
|
227
|
-
accumulator = await
|
|
229
|
+
accumulator = await predicate(accumulator, array[i], i, array);
|
|
228
230
|
}
|
|
229
231
|
return accumulator;
|
|
230
232
|
};
|
|
@@ -232,18 +234,61 @@ const reduceAsync = async (array, callbackFn, initialValue) => {
|
|
|
232
234
|
* Asynchronously finds the first element that satisfies the async condition.
|
|
233
235
|
*
|
|
234
236
|
* @param array - The array of items to search.
|
|
235
|
-
* @param
|
|
237
|
+
* @param predicate - An async function that returns a boolean.
|
|
236
238
|
*
|
|
237
239
|
* @returns A promise that resolves to the found item or null if none match.
|
|
238
240
|
*/
|
|
239
|
-
const findAsync = async (array,
|
|
241
|
+
const findAsync = async (array, predicate) => {
|
|
240
242
|
for (let i = 0; i < array.length; i++) {
|
|
241
|
-
if (await
|
|
243
|
+
if (await predicate(array[i], i, array)) {
|
|
242
244
|
return array[i];
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
247
|
return null;
|
|
246
248
|
};
|
|
249
|
+
/**
|
|
250
|
+
* Composes multiple unary functions into a single function, applying them from left to right.
|
|
251
|
+
*
|
|
252
|
+
* Useful for building a data processing pipeline where the output of one function becomes the input of the next.
|
|
253
|
+
*
|
|
254
|
+
* Types are inferred up to 5 chained functions for full type safety. Beyond that, it falls back to the unknown.
|
|
255
|
+
*
|
|
256
|
+
* @param fns - A list of unary functions to compose.
|
|
257
|
+
*
|
|
258
|
+
* @returns A new function that applies all functions from left to right.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* const add = (x: number) => x + 1;
|
|
263
|
+
* const double = (x: number) => x * 2;
|
|
264
|
+
* const toStr = (x: number) => `Result: ${x}`;
|
|
265
|
+
*
|
|
266
|
+
* const result = pipe(add, double, toStr)(2);
|
|
267
|
+
* // => 'Result: 6'
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
const pipe = (...fns) => (arg) => fns.reduce((prev, fn) => fn(prev), arg);
|
|
271
|
+
/**
|
|
272
|
+
* Composes multiple unary functions into a single function, applying them from **right to left**.
|
|
273
|
+
*
|
|
274
|
+
* Often used for building functional pipelines where the innermost function runs first.
|
|
275
|
+
* Types are inferred up to 5 chained functions for full type safety.
|
|
276
|
+
*
|
|
277
|
+
* @param fns - A list of unary functions to compose.
|
|
278
|
+
*
|
|
279
|
+
* @returns A new function that applies all functions from right to left.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* const add = (x: number) => x + 1;
|
|
284
|
+
* const double = (x: number) => x * 2;
|
|
285
|
+
* const toStr = (x: number) => `Result: ${x}`;
|
|
286
|
+
*
|
|
287
|
+
* const result = compose(toStr, double, add)(2);
|
|
288
|
+
* // => 'Result: 6'
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
const compose = (...fns) => (arg) => fns.reduceRight((prev, fn) => fn(prev), arg);
|
|
247
292
|
|
|
248
293
|
|
|
249
294
|
/***/ }),
|
|
@@ -464,6 +509,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
464
509
|
/* harmony export */ isArray: () => (/* binding */ isArray),
|
|
465
510
|
/* harmony export */ isBool: () => (/* binding */ isBool),
|
|
466
511
|
/* harmony export */ isDate: () => (/* binding */ isDate),
|
|
512
|
+
/* harmony export */ isDefined: () => (/* binding */ isDefined),
|
|
467
513
|
/* harmony export */ isEmptyArray: () => (/* binding */ isEmptyArray),
|
|
468
514
|
/* harmony export */ isEmptyObject: () => (/* binding */ isEmptyObject),
|
|
469
515
|
/* harmony export */ isFiniteNumber: () => (/* binding */ isFiniteNumber),
|
|
@@ -496,6 +542,35 @@ function assert(condition, message) {
|
|
|
496
542
|
* @returns `true` if the value is null; otherwise, `false`.
|
|
497
543
|
*/
|
|
498
544
|
const isNull = (value) => value === null;
|
|
545
|
+
/**
|
|
546
|
+
* Checks if a value is null or undefined.
|
|
547
|
+
*
|
|
548
|
+
* @param value - The value to check.
|
|
549
|
+
*
|
|
550
|
+
* @returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
551
|
+
*/
|
|
552
|
+
const isNil = (value) => value === undefined || value === null;
|
|
553
|
+
/**
|
|
554
|
+
* Checks whether the provided value is considered "empty".
|
|
555
|
+
*
|
|
556
|
+
* A value is considered empty if it is:
|
|
557
|
+
* - `null`
|
|
558
|
+
* - `undefined`
|
|
559
|
+
* - `''`
|
|
560
|
+
*
|
|
561
|
+
* @param value - The value to check.
|
|
562
|
+
*
|
|
563
|
+
* @returns `true` if the value is empty; otherwise, `false`.
|
|
564
|
+
*/
|
|
565
|
+
const isNilOrEmptyString = (value) => value === '' || isNil(value);
|
|
566
|
+
/**
|
|
567
|
+
* Checks if a value is neither `null` nor `undefined`.
|
|
568
|
+
*
|
|
569
|
+
* @param value - The value to check.
|
|
570
|
+
*
|
|
571
|
+
* @returns `true` if the value is defined (not `null` or `undefined`); otherwise, `false`.
|
|
572
|
+
*/
|
|
573
|
+
const isDefined = (value) => value !== null && value !== undefined;
|
|
499
574
|
/**
|
|
500
575
|
* Checks if a value is a string.
|
|
501
576
|
*
|
|
@@ -570,27 +645,6 @@ const isFunction = (value) => typeof value === 'function';
|
|
|
570
645
|
* @returns `true` if the value is a Promise; otherwise, `false`.
|
|
571
646
|
*/
|
|
572
647
|
const isPromise = (value) => isFunction(value?.then);
|
|
573
|
-
/**
|
|
574
|
-
* Checks if a value is null or undefined.
|
|
575
|
-
*
|
|
576
|
-
* @param value - The value to check.
|
|
577
|
-
*
|
|
578
|
-
* @returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
579
|
-
*/
|
|
580
|
-
const isNil = (value) => value === undefined || value === null;
|
|
581
|
-
/**
|
|
582
|
-
* Checks whether the provided value is considered "empty".
|
|
583
|
-
*
|
|
584
|
-
* A value is considered empty if it is:
|
|
585
|
-
* - `null`
|
|
586
|
-
* - `undefined`
|
|
587
|
-
* - `''`
|
|
588
|
-
*
|
|
589
|
-
* @param value - The value to check.
|
|
590
|
-
*
|
|
591
|
-
* @returns `true` if the value is empty; otherwise, `false`.
|
|
592
|
-
*/
|
|
593
|
-
const isNilOrEmptyString = (value) => value === '' || isNil(value);
|
|
594
648
|
/**
|
|
595
649
|
* Checks if a value is a Date object.
|
|
596
650
|
*
|
|
@@ -893,6 +947,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
893
947
|
/* harmony export */ camelToDashCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.camelToDashCase),
|
|
894
948
|
/* harmony export */ chunk: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.chunk),
|
|
895
949
|
/* harmony export */ cloneBlob: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_5__.cloneBlob),
|
|
950
|
+
/* harmony export */ compose: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.compose),
|
|
896
951
|
/* harmony export */ convertBlobToFile: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_5__.convertBlobToFile),
|
|
897
952
|
/* harmony export */ delay: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.delay),
|
|
898
953
|
/* harmony export */ difference: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.difference),
|
|
@@ -906,6 +961,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
906
961
|
/* harmony export */ isArray: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isArray),
|
|
907
962
|
/* harmony export */ isBool: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isBool),
|
|
908
963
|
/* harmony export */ isDate: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isDate),
|
|
964
|
+
/* harmony export */ isDefined: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isDefined),
|
|
909
965
|
/* harmony export */ isEmptyArray: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isEmptyArray),
|
|
910
966
|
/* harmony export */ isEmptyObject: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isEmptyObject),
|
|
911
967
|
/* harmony export */ isFiniteNumber: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isFiniteNumber),
|
|
@@ -927,6 +983,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
927
983
|
/* harmony export */ mapAsync: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.mapAsync),
|
|
928
984
|
/* harmony export */ noop: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.noop),
|
|
929
985
|
/* harmony export */ parse2DMatrix: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_5__.parse2DMatrix),
|
|
986
|
+
/* harmony export */ pipe: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.pipe),
|
|
930
987
|
/* harmony export */ reduceAsync: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.reduceAsync),
|
|
931
988
|
/* harmony export */ retry: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.retry),
|
|
932
989
|
/* harmony export */ someAsync: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.someAsync),
|