@react-hive/honey-utils 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +292 -0
- package/dist/README.md +292 -0
- package/dist/dom.d.ts +13 -0
- package/dist/guards.d.ts +148 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.dev.cjs +291 -6
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/math.d.ts +29 -0
- package/dist/string.d.ts +12 -3
- package/package.json +11 -3
package/dist/index.dev.cjs.map
CHANGED
|
@@ -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,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;ACjB5F,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEhF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEhF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAoB,EAAE,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC;AAEhF,MAAM,QAA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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":[],"sourceRoot":""}
|
|
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;;;;;;;;;;;;;;;ACR/B;;;;;;GAMG;AACI,MAAM,uBAAuB,GAAG,CAAC,OAAoB,EAAmC,EAAE;IAC/F,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACxD,MAAM,cAAc,GAAG,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ACA;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;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","/**\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","/**\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
|
|
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()}`),n=t=>t.split(" ").filter(Boolean),o=t=>{let e=5381;for(let n=0;n<t.length;n++)e=33*e^t.charCodeAt(n);return(e>>>0).toString(36)},r=t=>t.filter(Boolean),a=()=>{},s=(t,...e)=>"function"==typeof t?t(...e):t,l=t=>null===t,i=t=>"string"==typeof t,f=t=>"number"==typeof t,p=t=>"boolean"==typeof t,c=t=>"object"==typeof t,u=t=>c(t)&&!l(t)&&0===Object.keys(t).length,y=t=>Array.isArray(t),g=t=>y(t)&&0===t.length,h=t=>"function"==typeof t,m=t=>h(t?.then),b=t=>null==t,w=t=>""===t||b(t),A=t=>t instanceof Date,d=t=>A(t)&&!isNaN(t.getTime()),C=t=>t instanceof RegExp,$=t=>t instanceof Map,x=t=>t instanceof Set,F=t=>"symbol"==typeof t,M=t=>void 0===t,N=t=>f(t)&&isFinite(t),S=t=>f(t)&&Number.isInteger(t),j=(t,e,n,o)=>{const r=n-t,a=o-e;return Math.sqrt(r**2+a**2)},B=(t,e)=>Math.abs(t/e),E=(t,e)=>t*e/100,L=t=>{const e=window.getComputedStyle(t).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!e)return{translateX:0,translateY:0};const n=e[1].split(", ");return{translateX:parseFloat(n[4]),translateY:parseFloat(n[5])}};function X(t,e){if(!t)throw new Error(e)}export{X as assert,r as boolFilter,j as calculateEuclideanDistance,B as calculateMovingSpeed,E as calculatePercentage,e as camelToDashCase,L as getTransformationValues,o as hashString,s as invokeIfFunction,y as isArray,p as isBool,A as isDate,g as isEmptyArray,u as isEmptyObject,N as isFiniteNumber,h as isFunction,S as isInteger,$ as isMap,b as isNil,w as isNilOrEmptyString,l as isNull,f as isNumber,c as isObject,m as isPromise,C as isRegExp,x as isSet,i as isString,F as isSymbol,M as isUndefined,d as isValidDate,a as noop,n as splitStringIntoWords,t as toKebabCase};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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,ECV/EoB,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,GAAOT,OAS7CiB,EAAWR,GAAuCS,MAAMD,QAAQR,GAShEU,EAAgBV,GAAgCQ,EAAQR,IAA2B,IAAjBA,EAAMT,OASxEoB,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,WASnBC,EAAYrB,GAAoCA,aAAiBsB,OASjEC,EAASvB,GAAmDA,aAAiBwB,IAS7EC,EAASzB,GAA0CA,aAAiB0B,IASpEC,EAAY3B,GAAqD,iBAAVA,EASvD4B,EAAe5B,QAAiD6B,IAAV7B,EAStD8B,EAAkB9B,GAC7BE,EAASF,IAAU+B,SAAS/B,GASjBgC,EAAahC,GACxBE,EAASF,IAAUiC,OAAOD,UAAUhC,GC/LzBkC,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,CAAC/C,EAAegD,IACzChD,EAAQgD,EAAc,IC9BnBC,EAA2BC,IACtC,MAGMC,EAHiBC,OAAOC,iBAAiBH,GACTI,iBAAiB,aAEzBC,MAAM,oBACpC,IAAKJ,EACH,MAAO,CACLK,WAAY,EACZC,WAAY,GAIhB,MAAMC,EAAkBP,EAAO,GAAGlE,MAAM,MAKxC,MAAO,CACLuE,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","/**\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","/**\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","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","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: (
|
|
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
|
|
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: (
|
|
35
|
+
export declare const hashString: (input: string) => string;
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-hive/honey-utils",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"utils",
|
|
7
|
-
"typescript"
|
|
7
|
+
"typescript",
|
|
8
|
+
"type-guards",
|
|
9
|
+
"string-utils",
|
|
10
|
+
"array-utils",
|
|
11
|
+
"math-utils",
|
|
12
|
+
"function-utils",
|
|
13
|
+
"dom-utils",
|
|
14
|
+
"helpers",
|
|
15
|
+
"utility-functions"
|
|
8
16
|
],
|
|
9
17
|
"homepage": "https://github.com/React-Hive/honey-utils",
|
|
10
18
|
"bugs": {
|