@react-hive/honey-utils 1.5.0 → 1.6.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","mappings":"AAiBO,MAAMA,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,EAAMgB,OAAQD,IAChCD,EAAe,GAAPA,EAAad,EAAMiB,WAAWF,GAGxC,OAAQD,IAAS,GAAGI,SAAS,KC7FxB,SAASC,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,CASO,MAAME,EAAUC,GAA4C,OAAVA,EAS5CC,EAAYD,GAAqD,iBAAVA,EASvDE,EAAYF,GAAqD,iBAAVA,EASvDG,EAAUH,GAAsD,kBAAVA,EAStDI,EAAYJ,GAAqD,iBAAVA,EASvDK,EAAiBL,GAC5BI,EAASJ,KAAWD,EAAOC,IAAwC,IAA9BM,OAAOC,KAAKP,GAAOR,OAS7CgB,EAAWR,GAAuCS,MAAMD,QAAQR,GAShEU,EAAgBV,GAAgCQ,EAAQR,IAA2B,IAAjBA,EAAMR,OASxEmB,EAAcX,GAAoC,mBAAVA,EAWxCY,EAA0BZ,GACrCW,EAAYX,GAAsBa,MASvBC,EAASd,GACpBA,QAcWe,EAAsBf,GACvB,KAAVA,GAAgBc,EAAMd,GASXgB,EAAUhB,GAAkCA,aAAiBiB,KAS7DC,EAAelB,GAC1BgB,EAAOhB,KAAWmB,MAAMnB,EAAMoB,WAS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AYE,EAERD,EAAUL,EAAa,CACzBE,IAAUG,EAASC,GAEnB,MAAMC,EAAYN,EAAUP,EAAU,IAAMW,EAAU,GAAKX,QACrDD,EAAMc,EACd,CACF,CAGF,MAAMH,GClIGI,EAA6B,CACxCC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASF,EAAOF,EAChBK,EAASF,EAAOF,EAEtB,OAAOjC,KAAKsC,KAAKF,GAAU,EAAIC,GAAU,IAW9BE,EAAuB,CAACC,EAAeC,IAClDzC,KAAK0C,IAAIF,EAAQC,GAUNE,EAAsB,CAACnF,EAAeoF,IACzCpF,EAAQoF,EAAc,IC9BnBC,EAA2BC,IACtC,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEzBC,MAAM,oBACpC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,GAIhB,MAAMC,EAAkBP,EAAO,GAAGrG,MAAM,MAKxC,MAAO,CACL0G,WAJiBG,WAAWD,EAAgB,IAK5CD,WAJiBE,WAAWD,EAAgB,a","sources":["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":["/**\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","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}\n\n/**\n * Get various transformation values from the transformation matrix of an element.\n *\n * @param element - The element with a transformation applied.\n *\n * @returns An object containing transformation values.\n */\nexport const getTransformationValues = (element: HTMLElement): HTMLElementTransformationValues => {\n const computedStyles = window.getComputedStyle(element);\n const transformValue = computedStyles.getPropertyValue('transform');\n\n const matrix = transformValue.match(/^matrix\\((.+)\\)$/);\n if (!matrix) {\n return {\n translateX: 0,\n translateY: 0,\n };\n }\n\n const transformMatrix = matrix[1].split(', ');\n\n const translateX = parseFloat(transformMatrix[4]);\n const translateY = parseFloat(transformMatrix[5]);\n\n return {\n translateX,\n translateY,\n };\n};\n"],"names":["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","value","isString","isNumber","isBool","isObject","isEmptyObject","Object","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","noop","invokeIfFunction","args","delay","delayMs","Promise","resolve","setTimeout","retry","task","maxAttempts","backoff","onRetry","async","lastError","attempt","e","delayTime","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","getTransformationValues","element","matrix","window","getComputedStyle","getPropertyValue","match","translateX","translateY","transformMatrix","parseFloat"],"sourceRoot":""}
1
+ {"version":3,"file":"index.mjs","mappings":"AAiBO,MAAMA,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,G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OAAQ,EACRC,MAAO,EACPC,MAAO,GAIX,MAAOH,EAAQG,EAAOD,EAAOD,EAAQH,EAAYC,GAAcN,EAAY,GACxEnH,MAAM,MACN2E,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,c","sources":["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":["/**\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":["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","value","isString","isNumber","isBool","isObject","isEmptyObject","Object","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":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-hive/honey-utils",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks",
5
5
  "keywords": [
6
6
  "utils",