@react-hive/honey-utils 1.1.0 → 1.2.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/dist/dom.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ interface HTMLElementTransformationValues {
2
+ translateX: number;
3
+ translateY: number;
4
+ }
5
+ /**
6
+ * Get various transformation values from the transformation matrix of an element.
7
+ *
8
+ * @param element - The element with a transformation applied.
9
+ *
10
+ * @returns An object containing transformation values.
11
+ */
12
+ export declare const getTransformationValues: (element: HTMLElement) => HTMLElementTransformationValues;
13
+ export {};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- (()=>{"use strict";var e={d:(o,t)=>{for(var r in t)e.o(t,r)&&!e.o(o,r)&&Object.defineProperty(o,r,{enumerable:!0,get:t[r]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{assert:()=>g,boolFilter:()=>n,hashString:()=>r,invokeIfFunction:()=>l,isBool:()=>f,isFunction:()=>u,isNil:()=>c,isNilOrEmptyString:()=>y,isNumber:()=>a,isObject:()=>p,isPromise:()=>b,isString:()=>s,noop:()=>i,toKebabCase:()=>t});const t=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),r=e=>{let o=5381;for(let t=0;t<e.length;t++)o=33*o^e.charCodeAt(t);return(o>>>0).toString(36)},n=e=>e.filter(Boolean),i=()=>{},l=(e,...o)=>"function"==typeof e?e(...o):e,s=e=>"string"==typeof e,a=e=>"number"==typeof e,f=e=>"boolean"==typeof e,p=e=>"object"==typeof e,u=e=>"function"==typeof e,b=e=>u(e?.then),c=e=>null==e,y=e=>""===e||c(e);function g(e,o){if(!e)throw new Error(o)}module.exports=o})();
1
+ (()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},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:()=>O,boolFilter:()=>l,calculateEuclideanDistance:()=>m,calculateMovingSpeed:()=>S,calculatePercentage:()=>h,camelToDashCase:()=>r,getTransformationValues:()=>w,hashString:()=>a,invokeIfFunction:()=>s,isBool:()=>p,isFunction:()=>g,isNil:()=>b,isNilOrEmptyString:()=>d,isNumber:()=>u,isObject:()=>f,isPromise:()=>y,isString:()=>c,noop:()=>i,splitStringIntoWords:()=>n,toKebabCase:()=>o});const o=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),r=e=>e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),n=e=>e.split(" ").filter(Boolean),a=e=>{let t=5381;for(let o=0;o<e.length;o++)t=33*t^e.charCodeAt(o);return(t>>>0).toString(36)},l=e=>e.filter(Boolean),i=()=>{},s=(e,...t)=>"function"==typeof e?e(...t):e,c=e=>"string"==typeof e,u=e=>"number"==typeof e,p=e=>"boolean"==typeof e,f=e=>"object"==typeof e,g=e=>"function"==typeof e,y=e=>g(e?.then),b=e=>null==e,d=e=>""===e||b(e),m=(e,t,o,r)=>{const n=o-e,a=r-t;return Math.sqrt(n**2+a**2)},S=(e,t)=>Math.abs(e/t),h=(e,t)=>e*t/100,w=e=>{const t=window.getComputedStyle(e).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!t)return{translateX:0,translateY:0};const o=t[1].split(", ");return{translateX:parseFloat(o[4]),translateY:parseFloat(o[5])}};function O(e,t){if(!e)throw new Error(t)}module.exports=t})();
2
2
  //# sourceMappingURL=index.cjs.map
@@ -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,wPCLhD,MAAMC,EAAeC,GAC1BA,EAAIC,QAAQ,qBAAsB,SAASC,cA0BhCC,EAAcH,IACzB,IAAII,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAIM,OAAQD,IAC9BD,EAAe,GAAPA,EAAaJ,EAAIO,WAAWF,GAGtC,OAAQD,IAAS,GAAGI,SAAS,KCtBlBC,EAAiBC,GAC5BA,EAAMC,OAAOC,SCbFC,EAAO,OAcPC,EAAmB,CAC9BC,KACGC,IAC0B,mBAAVD,EAAwBA,KAAuCC,GAAQD,ECjB/EE,EAAYnB,GAAqD,iBAAVA,EAEvDoB,EAAYpB,GAAqD,iBAAVA,EAEvDqB,EAAUrB,GAAsD,kBAAVA,EAEtDsB,EAAYtB,GAAqD,iBAAVA,EAEvDuB,EAAcvB,GAAoC,mBAAVA,EAExCwB,EAA0BxB,GACrCuB,EAAYvB,GAAsByB,MASvBC,EAAS1B,GACpBA,QAcW2B,EAAsB3B,GACvB,KAAVA,GAAgB0B,EAAM1B,GC/BjB,SAAS4B,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,C","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/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/index.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};","export const toKebabCase = (str: string): string =>\n str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\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 str - 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 = (str: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < str.length; i++) {\n hash = (hash * 33) ^ str.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\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","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 any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\nexport const isFunction = (value: unknown) => typeof value === 'function';\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","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","toKebabCase","str","replace","toLowerCase","hashString","hash","i","length","charCodeAt","toString","boolFilter","array","filter","Boolean","noop","invokeIfFunction","input","args","isString","isNumber","isBool","isObject","isFunction","isPromise","then","isNil","isNilOrEmptyString","assert","condition","message","Error"],"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,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,6ZCLhD,MAAMC,EAAeC,GAC1BA,EAAMC,QAAQ,qBAAsB,SAASC,cAElCC,EAAmBH,GAC9BA,EAAMC,QAAQ,SAAUG,GAAU,IAAIA,EAAOF,iBASlCG,EAAwBL,GAA4BA,EAAMM,MAAM,KAAKC,OAAOC,SA0B5EC,EAAcT,IACzB,IAAIU,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIX,EAAMY,OAAQD,IAChCD,EAAe,GAAPA,EAAaV,EAAMa,WAAWF,GAGxC,OAAQD,IAAS,GAAGI,SAAS,KClClBC,EAAiBC,GAC5BA,EAAMT,OAAOC,SCbFS,EAAO,OAcPC,EAAmB,CAC9BlB,KACGmB,IAC0B,mBAAVnB,EAAwBA,KAAuCmB,GAAQnB,ECjB/EoB,EAAYtB,GAAqD,iBAAVA,EAEvDuB,EAAYvB,GAAqD,iBAAVA,EAEvDwB,EAAUxB,GAAsD,kBAAVA,EAEtDyB,EAAYzB,GAAqD,iBAAVA,EAEvD0B,EAAc1B,GAAoC,mBAAVA,EAExC2B,EAA0B3B,GACrC0B,EAAY1B,GAAsB4B,MASvBC,EAAS7B,GACpBA,QAcW8B,EAAsB9B,GACvB,KAAVA,GAAgB6B,EAAM7B,GC1BX+B,EAA6B,CACxCC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASF,EAAOF,EAChBK,EAASF,EAAOF,EAEtB,OAAOK,KAAKC,KAAKH,GAAU,EAAIC,GAAU,IAW9BG,EAAuB,CAACC,EAAeC,IAClDJ,KAAKK,IAAIF,EAAQC,GAUNE,EAAsB,CAAC5C,EAAe6C,IACzC7C,EAAQ6C,EAAc,IC9BnBC,EAA2BC,IACtC,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEzBC,MAAM,oBACpC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,GAIhB,MAAMC,EAAkBP,EAAO,GAAGxC,MAAM,MAKxC,MAAO,CACL6C,WAJiBG,WAAWD,EAAgB,IAK5CD,WAJiBE,WAAWD,EAAgB,MCpBzC,SAASE,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,C","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/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts","webpack://@react-hive/honey-utils/./src/index.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};","export const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const camelToDashCase = (input: string): string =>\n input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\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","/**\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","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 any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\nexport const isFunction = (value: unknown) => typeof value === 'function';\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 * 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","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\nexport * from './math';\nexport * from './dom';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\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","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","boolFilter","array","noop","invokeIfFunction","args","isString","isNumber","isBool","isObject","isFunction","isPromise","then","isNil","isNilOrEmptyString","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","Math","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","getTransformationValues","element","matrix","window","getComputedStyle","getPropertyValue","match","translateX","translateY","transformMatrix","parseFloat","assert","condition","message","Error"],"sourceRoot":""}
package/dist/index.d.ts CHANGED
@@ -2,4 +2,6 @@ export * from './string';
2
2
  export * from './array';
3
3
  export * from './function';
4
4
  export * from './guards';
5
+ export * from './math';
6
+ export * from './dom';
5
7
  export declare function assert(condition: any, message: string): asserts condition;
@@ -27,6 +27,45 @@ __webpack_require__.r(__webpack_exports__);
27
27
  const boolFilter = (array) => array.filter(Boolean);
28
28
 
29
29
 
30
+ /***/ }),
31
+
32
+ /***/ "./src/dom.ts":
33
+ /*!********************!*\
34
+ !*** ./src/dom.ts ***!
35
+ \********************/
36
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
37
+
38
+ __webpack_require__.r(__webpack_exports__);
39
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
40
+ /* harmony export */ getTransformationValues: () => (/* binding */ getTransformationValues)
41
+ /* harmony export */ });
42
+ /**
43
+ * Get various transformation values from the transformation matrix of an element.
44
+ *
45
+ * @param element - The element with a transformation applied.
46
+ *
47
+ * @returns An object containing transformation values.
48
+ */
49
+ const getTransformationValues = (element) => {
50
+ const computedStyles = window.getComputedStyle(element);
51
+ const transformValue = computedStyles.getPropertyValue('transform');
52
+ const matrix = transformValue.match(/^matrix\((.+)\)$/);
53
+ if (!matrix) {
54
+ return {
55
+ translateX: 0,
56
+ translateY: 0,
57
+ };
58
+ }
59
+ const transformMatrix = matrix[1].split(', ');
60
+ const translateX = parseFloat(transformMatrix[4]);
61
+ const translateY = parseFloat(transformMatrix[5]);
62
+ return {
63
+ translateX,
64
+ translateY,
65
+ };
66
+ };
67
+
68
+
30
69
  /***/ }),
31
70
 
32
71
  /***/ "./src/function.ts":
@@ -104,6 +143,57 @@ const isNil = (value) => value === undefined || value === null;
104
143
  const isNilOrEmptyString = (value) => value === '' || isNil(value);
105
144
 
106
145
 
146
+ /***/ }),
147
+
148
+ /***/ "./src/math.ts":
149
+ /*!*********************!*\
150
+ !*** ./src/math.ts ***!
151
+ \*********************/
152
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
153
+
154
+ __webpack_require__.r(__webpack_exports__);
155
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
156
+ /* harmony export */ calculateEuclideanDistance: () => (/* binding */ calculateEuclideanDistance),
157
+ /* harmony export */ calculateMovingSpeed: () => (/* binding */ calculateMovingSpeed),
158
+ /* harmony export */ calculatePercentage: () => (/* binding */ calculatePercentage)
159
+ /* harmony export */ });
160
+ /**
161
+ * Calculates the Euclidean distance between two points in 2D space.
162
+ *
163
+ * @param startX - The X coordinate of the starting point.
164
+ * @param startY - The Y coordinate of the starting point.
165
+ * @param endX - The X coordinate of the ending point.
166
+ * @param endY - The Y coordinate of the ending point.
167
+ *
168
+ * @returns The Euclidean distance between the two points.
169
+ */
170
+ const calculateEuclideanDistance = (startX, startY, endX, endY) => {
171
+ const deltaX = endX - startX;
172
+ const deltaY = endY - startY;
173
+ return Math.sqrt(deltaX ** 2 + deltaY ** 2);
174
+ };
175
+ /**
176
+ * Calculates the moving speed.
177
+ *
178
+ * @param delta - The change in position (distance).
179
+ * @param elapsedTime - The time taken to move the distance.
180
+ *
181
+ * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.
182
+ */
183
+ const calculateMovingSpeed = (delta, elapsedTime) => Math.abs(delta / elapsedTime);
184
+ /**
185
+ * Calculates the specified percentage of a given value.
186
+ *
187
+ * @param value - The value to calculate the percentage of.
188
+ * @param percentage - The percentage to calculate.
189
+ *
190
+ * @returns The calculated percentage of the value.
191
+ */
192
+ const calculatePercentage = (value, percentage) => {
193
+ return (value * percentage) / 100;
194
+ };
195
+
196
+
107
197
  /***/ }),
108
198
 
109
199
  /***/ "./src/string.ts":
@@ -114,10 +204,21 @@ const isNilOrEmptyString = (value) => value === '' || isNil(value);
114
204
 
115
205
  __webpack_require__.r(__webpack_exports__);
116
206
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
207
+ /* harmony export */ camelToDashCase: () => (/* binding */ camelToDashCase),
117
208
  /* harmony export */ hashString: () => (/* binding */ hashString),
209
+ /* harmony export */ splitStringIntoWords: () => (/* binding */ splitStringIntoWords),
118
210
  /* harmony export */ toKebabCase: () => (/* binding */ toKebabCase)
119
211
  /* harmony export */ });
120
- const toKebabCase = (str) => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
212
+ const toKebabCase = (input) => input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
213
+ const camelToDashCase = (input) => input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);
214
+ /**
215
+ * Splits a string into an array of filtered from redundant spaces words.
216
+ *
217
+ * @param input - The input string to be split.
218
+ *
219
+ * @returns An array of words from the input string.
220
+ */
221
+ const splitStringIntoWords = (input) => input.split(' ').filter(Boolean);
121
222
  /**
122
223
  * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.
123
224
  *
@@ -132,7 +233,7 @@ const toKebabCase = (str) => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerC
132
233
  *
133
234
  * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.
134
235
  *
135
- * @param str - The input string to hash.
236
+ * @param input - The input string to hash.
136
237
  *
137
238
  * @returns A short, base-36 encoded hash string.
138
239
  *
@@ -142,10 +243,10 @@ const toKebabCase = (str) => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerC
142
243
  * // → 'e4k1z0x'
143
244
  * ```
144
245
  */
145
- const hashString = (str) => {
246
+ const hashString = (input) => {
146
247
  let hash = 5381;
147
- for (let i = 0; i < str.length; i++) {
148
- hash = (hash * 33) ^ str.charCodeAt(i);
248
+ for (let i = 0; i < input.length; i++) {
249
+ hash = (hash * 33) ^ input.charCodeAt(i);
149
250
  }
150
251
  return (hash >>> 0).toString(36);
151
252
  };
@@ -219,6 +320,11 @@ __webpack_require__.r(__webpack_exports__);
219
320
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
220
321
  /* harmony export */ assert: () => (/* binding */ assert),
221
322
  /* harmony export */ boolFilter: () => (/* reexport safe */ _array__WEBPACK_IMPORTED_MODULE_1__.boolFilter),
323
+ /* harmony export */ calculateEuclideanDistance: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculateEuclideanDistance),
324
+ /* harmony export */ calculateMovingSpeed: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculateMovingSpeed),
325
+ /* harmony export */ calculatePercentage: () => (/* reexport safe */ _math__WEBPACK_IMPORTED_MODULE_4__.calculatePercentage),
326
+ /* harmony export */ camelToDashCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.camelToDashCase),
327
+ /* harmony export */ getTransformationValues: () => (/* reexport safe */ _dom__WEBPACK_IMPORTED_MODULE_5__.getTransformationValues),
222
328
  /* harmony export */ hashString: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.hashString),
223
329
  /* harmony export */ invokeIfFunction: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.invokeIfFunction),
224
330
  /* harmony export */ isBool: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isBool),
@@ -230,12 +336,17 @@ __webpack_require__.r(__webpack_exports__);
230
336
  /* harmony export */ isPromise: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isPromise),
231
337
  /* harmony export */ isString: () => (/* reexport safe */ _guards__WEBPACK_IMPORTED_MODULE_3__.isString),
232
338
  /* harmony export */ noop: () => (/* reexport safe */ _function__WEBPACK_IMPORTED_MODULE_2__.noop),
339
+ /* harmony export */ splitStringIntoWords: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.splitStringIntoWords),
233
340
  /* harmony export */ toKebabCase: () => (/* reexport safe */ _string__WEBPACK_IMPORTED_MODULE_0__.toKebabCase)
234
341
  /* harmony export */ });
235
342
  /* harmony import */ var _string__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./string */ "./src/string.ts");
236
343
  /* harmony import */ var _array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./array */ "./src/array.ts");
237
344
  /* harmony import */ var _function__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./function */ "./src/function.ts");
238
345
  /* harmony import */ var _guards__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./guards */ "./src/guards.ts");
346
+ /* harmony import */ var _math__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./math */ "./src/math.ts");
347
+ /* harmony import */ var _dom__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./dom */ "./src/dom.ts");
348
+
349
+
239
350
 
240
351
 
241
352
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.dev.cjs","mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;;GAWG;AACI,MAAM,UAAU,GAAG,CAAI,KAAuC,EAAO,EAAE,CAC5E,KAAK,CAAC,MAAM,CAAC,OAAO,CAAQ,CAAC;;;;;;;;;;;;;;;;ACbxB,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAE7B;;;;;;;;;;;GAWG;AACI,MAAM,gBAAgB,GAAG,CAC9B,KAA2C,EAC3C,GAAG,IAAU,EACL,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAE,KAAmC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EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC;;;;;;;UCnCF;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACNyB;AACD;AACG;AACF;AAElB,SAAS,MAAM,CAAC,SAAc,EAAE,OAAe;IACpD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC","sources":["webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/string.ts","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/index.ts"],"sourcesContent":["/**\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","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 any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\nexport const isFunction = (value: unknown) => typeof value === 'function';\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","export const toKebabCase = (str: string): string =>\n str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\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 str - 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 = (str: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < str.length; i++) {\n hash = (hash * 33) ^ str.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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};","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":[],"source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WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACNyB;AACD;AACG;AACF;AACF;AACD;AAEf,SAAS,MAAM,CAAC,SAAc,EAAE,OAAe;IACpD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC","sources":["webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/dom.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/string.ts","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/index.ts"],"sourcesContent":["/**\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","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","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 any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\nexport const isFunction = (value: unknown) => typeof value === 'function';\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 * 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","export const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const camelToDashCase = (input: string): string =>\n input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\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","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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};","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\nexport * from './math';\nexport * from './dom';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":[],"sourceRoot":""}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- const t=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),e=t=>{let e=5381;for(let o=0;o<t.length;o++)e=33*e^t.charCodeAt(o);return(e>>>0).toString(36)},o=t=>t.filter(Boolean),n=()=>{},r=(t,...e)=>"function"==typeof t?t(...e):t,f=t=>"string"==typeof t,l=t=>"number"==typeof t,p=t=>"boolean"==typeof t,c=t=>"object"==typeof t,i=t=>"function"==typeof t,a=t=>i(t?.then),u=t=>null==t,y=t=>""===t||u(t);function g(t,e){if(!t)throw new Error(e)}export{g as assert,o as boolFilter,e as hashString,r as invokeIfFunction,p as isBool,i as isFunction,u as isNil,y as isNilOrEmptyString,l as isNumber,c as isObject,a as isPromise,f as isString,n as noop,t as toKebabCase};
1
+ const t=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),e=t=>t.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`),o=t=>t.split(" ").filter(Boolean),r=t=>{let e=5381;for(let o=0;o<t.length;o++)e=33*e^t.charCodeAt(o);return(e>>>0).toString(36)},n=t=>t.filter(Boolean),a=()=>{},l=(t,...e)=>"function"==typeof t?t(...e):t,s=t=>"string"==typeof t,f=t=>"number"==typeof t,p=t=>"boolean"==typeof t,i=t=>"object"==typeof t,c=t=>"function"==typeof t,u=t=>c(t?.then),y=t=>null==t,g=t=>""===t||y(t),h=(t,e,o,r)=>{const n=o-t,a=r-e;return Math.sqrt(n**2+a**2)},w=(t,e)=>Math.abs(t/e),m=(t,e)=>t*e/100,b=t=>{const e=window.getComputedStyle(t).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!e)return{translateX:0,translateY:0};const o=e[1].split(", ");return{translateX:parseFloat(o[4]),translateY:parseFloat(o[5])}};function C(t,e){if(!t)throw new Error(e)}export{C as assert,n as boolFilter,h as calculateEuclideanDistance,w as calculateMovingSpeed,m as calculatePercentage,e as camelToDashCase,b as getTransformationValues,r as hashString,l as invokeIfFunction,p as isBool,c as isFunction,y as isNil,g as isNilOrEmptyString,f as isNumber,i as isObject,u as isPromise,s as isString,a as noop,o as splitStringIntoWords,t as toKebabCase};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","mappings":"AAAO,MAAMA,EAAeC,GAC1BA,EAAIC,QAAQ,qBAAsB,SAASC,cA0BhCC,EAAcH,IACzB,IAAII,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAIM,OAAQD,IAC9BD,EAAe,GAAPA,EAAaJ,EAAIO,WAAWF,GAGtC,OAAQD,IAAS,GAAGI,SAAS,KCtBlBC,EAAiBC,GAC5BA,EAAMC,OAAOC,SCbFC,EAAO,OAcPC,EAAmB,CAC9BC,KACGC,IAC0B,mBAAVD,EAAwBA,KAAuCC,GAAQD,ECjB/EE,EAAYC,GAAqD,iBAAVA,EAEvDC,EAAYD,GAAqD,iBAAVA,EAEvDE,EAAUF,GAAsD,kBAAVA,EAEtDG,EAAYH,GAAqD,iBAAVA,EAEvDI,EAAcJ,GAAoC,mBAAVA,EAExCK,EAA0BL,GACrCI,EAAYJ,GAAsBM,MASvBC,EAASP,GACpBA,QAcWQ,EAAsBR,GACvB,KAAVA,GAAgBO,EAAMP,GC/BjB,SAASS,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,Q","sources":["webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/index.ts"],"sourcesContent":["export const toKebabCase = (str: string): string =>\n str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\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 str - 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 = (str: string): string => {\n let hash = 5381;\n\n for (let i = 0; i < str.length; i++) {\n hash = (hash * 33) ^ str.charCodeAt(i);\n }\n\n return (hash >>> 0).toString(36);\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","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 any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\nexport const isFunction = (value: unknown) => typeof value === 'function';\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","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":["toKebabCase","str","replace","toLowerCase","hashString","hash","i","length","charCodeAt","toString","boolFilter","array","filter","Boolean","noop","invokeIfFunction","input","args","isString","value","isNumber","isBool","isObject","isFunction","isPromise","then","isNil","isNilOrEmptyString","assert","condition","message","Error"],"sourceRoot":""}
1
+ {"version":3,"file":"index.mjs","mappings":"AAAO,MAAMA,EAAeC,GAC1BA,EAAMC,QAAQ,qBAAsB,SAASC,cAElCC,EAAmBH,GAC9BA,EAAMC,QAAQ,SAAUG,GAAU,IAAIA,EAAOF,iBASlCG,EAAwBL,GAA4BA,EAAMM,MAAM,KAAKC,OAAOC,SA0B5EC,EAAcT,IACzB,IAAIU,EAAO,KAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIX,EAAMY,OAAQD,IAChCD,EAAe,GAAPA,EAAaV,EAAMa,WAAWF,GAGxC,OAAQD,IAAS,GAAGI,SAAS,KClClBC,EAAiBC,GAC5BA,EAAMT,OAAOC,SCbFS,EAAO,OAcPC,EAAmB,CAC9BlB,KACGmB,IAC0B,mBAAVnB,EAAwBA,KAAuCmB,GAAQnB,ECjB/EoB,EAAYC,GAAqD,iBAAVA,EAEvDC,EAAYD,GAAqD,iBAAVA,EAEvDE,EAAUF,GAAsD,kBAAVA,EAEtDG,EAAYH,GAAqD,iBAAVA,EAEvDI,EAAcJ,GAAoC,mBAAVA,EAExCK,EAA0BL,GACrCI,EAAYJ,GAAsBM,MASvBC,EAASP,GACpBA,QAcWQ,EAAsBR,GACvB,KAAVA,GAAgBO,EAAMP,GC1BXS,EAA6B,CACxCC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASF,EAAOF,EAChBK,EAASF,EAAOF,EAEtB,OAAOK,KAAKC,KAAKH,GAAU,EAAIC,GAAU,IAW9BG,EAAuB,CAACC,EAAeC,IAClDJ,KAAKK,IAAIF,EAAQC,GAUNE,EAAsB,CAACtB,EAAeuB,IACzCvB,EAAQuB,EAAc,IC9BnBC,EAA2BC,IACtC,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEzBC,MAAM,oBACpC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,GAIhB,MAAMC,EAAkBP,EAAO,GAAGzC,MAAM,MAKxC,MAAO,CACL8C,WAJiBG,WAAWD,EAAgB,IAK5CD,WAJiBE,WAAWD,EAAgB,MCpBzC,SAASE,EAAOC,EAAgBC,GACrC,IAAKD,EACH,MAAM,IAAIE,MAAMD,EAEpB,Q","sources":["webpack://@react-hive/honey-utils/./src/string.ts","webpack://@react-hive/honey-utils/./src/array.ts","webpack://@react-hive/honey-utils/./src/function.ts","webpack://@react-hive/honey-utils/./src/guards.ts","webpack://@react-hive/honey-utils/./src/math.ts","webpack://@react-hive/honey-utils/./src/dom.ts","webpack://@react-hive/honey-utils/./src/index.ts"],"sourcesContent":["export const toKebabCase = (input: string): string =>\n input.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\nexport const camelToDashCase = (input: string): string =>\n input.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\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","/**\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","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 any[], Result>(\n input: ((...args: Args) => Result) | Result,\n ...args: Args\n): Result => (typeof input === 'function' ? (input as (...args: Args) => Result)(...args) : input);\n","export const isString = (value: unknown): value is string => typeof value === 'string';\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const isBool = (value: unknown): value is boolean => typeof value === 'boolean';\n\nexport const isObject = (value: unknown): value is object => typeof value === 'object';\n\nexport const isFunction = (value: unknown) => typeof value === 'function';\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 * 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","export * from './string';\nexport * from './array';\nexport * from './function';\nexport * from './guards';\nexport * from './math';\nexport * from './dom';\n\nexport function assert(condition: any, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"names":["toKebabCase","input","replace","toLowerCase","camelToDashCase","letter","splitStringIntoWords","split","filter","Boolean","hashString","hash","i","length","charCodeAt","toString","boolFilter","array","noop","invokeIfFunction","args","isString","value","isNumber","isBool","isObject","isFunction","isPromise","then","isNil","isNilOrEmptyString","calculateEuclideanDistance","startX","startY","endX","endY","deltaX","deltaY","Math","sqrt","calculateMovingSpeed","delta","elapsedTime","abs","calculatePercentage","percentage","getTransformationValues","element","matrix","window","getComputedStyle","getPropertyValue","match","translateX","translateY","transformMatrix","parseFloat","assert","condition","message","Error"],"sourceRoot":""}
package/dist/math.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Calculates the Euclidean distance between two points in 2D space.
3
+ *
4
+ * @param startX - The X coordinate of the starting point.
5
+ * @param startY - The Y coordinate of the starting point.
6
+ * @param endX - The X coordinate of the ending point.
7
+ * @param endY - The Y coordinate of the ending point.
8
+ *
9
+ * @returns The Euclidean distance between the two points.
10
+ */
11
+ export declare const calculateEuclideanDistance: (startX: number, startY: number, endX: number, endY: number) => number;
12
+ /**
13
+ * Calculates the moving speed.
14
+ *
15
+ * @param delta - The change in position (distance).
16
+ * @param elapsedTime - The time taken to move the distance.
17
+ *
18
+ * @returns The calculated speed, which is the absolute value of delta divided by elapsed time.
19
+ */
20
+ export declare const calculateMovingSpeed: (delta: number, elapsedTime: number) => number;
21
+ /**
22
+ * Calculates the specified percentage of a given value.
23
+ *
24
+ * @param value - The value to calculate the percentage of.
25
+ * @param percentage - The percentage to calculate.
26
+ *
27
+ * @returns The calculated percentage of the value.
28
+ */
29
+ export declare const calculatePercentage: (value: number, percentage: number) => number;
package/dist/string.d.ts CHANGED
@@ -1,4 +1,13 @@
1
- export declare const toKebabCase: (str: string) => string;
1
+ export declare const toKebabCase: (input: string) => string;
2
+ export declare const camelToDashCase: (input: string) => string;
3
+ /**
4
+ * Splits a string into an array of filtered from redundant spaces words.
5
+ *
6
+ * @param input - The input string to be split.
7
+ *
8
+ * @returns An array of words from the input string.
9
+ */
10
+ export declare const splitStringIntoWords: (input: string) => string[];
2
11
  /**
3
12
  * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm.
4
13
  *
@@ -13,7 +22,7 @@ export declare const toKebabCase: (str: string) => string;
13
22
  *
14
23
  * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data.
15
24
  *
16
- * @param str - The input string to hash.
25
+ * @param input - The input string to hash.
17
26
  *
18
27
  * @returns A short, base-36 encoded hash string.
19
28
  *
@@ -23,4 +32,4 @@ export declare const toKebabCase: (str: string) => string;
23
32
  * // → 'e4k1z0x'
24
33
  * ```
25
34
  */
26
- export declare const hashString: (str: string) => string;
35
+ export declare const hashString: (input: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-hive/honey-utils",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "utils",