UNPKG

@react-hive/honey-utils

Version:

A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks

72 lines (71 loc) 2.59 kB
/** * Converts a string to kebab-case format. * * This function transforms camelCase or PascalCase strings into kebab-case by inserting * hyphens between lowercase and uppercase letters, then converting everything to lowercase. * * @param input - The string to convert to kebab-case. * * @returns The kebab-case formatted string. * * @example * ```ts * toKebabCase('helloWorld'); // → 'hello-world' * toKebabCase('HelloWorld'); // → 'hello-world' * toKebabCase('hello123World'); // → 'hello123-world' * ``` */ export declare const toKebabCase: (input: string) => string; /** * Converts a camelCase string to dash-case format. * * This function transforms camelCase strings into dash-case by inserting * hyphens before uppercase letters and converting them to lowercase. * The function ensures that no hyphen is added at the start of the output string, * even if the input begins with an uppercase letter. * * @param input - The camelCase string to convert to dash-case. * * @returns The dash-case formatted string. * * @example * ```ts * camelToDashCase('helloWorld'); // → 'hello-world' * camelToDashCase('HelloWorld'); // → 'hello-world' * camelToDashCase('backgroundColor'); // → 'background-color' * ``` */ export declare const camelToDashCase: (input: string) => string; /** * Splits a string into an array of filtered from redundant spaces words. * * @param input - The input string to be split. * * @returns An array of words from the input string. */ export declare const splitStringIntoWords: (input: string) => string[]; /** * Generates a short, consistent hash string from an input string using a DJB2-inspired algorithm. * * This function uses a variation of the DJB2 algorithm, which is a simple yet effective hashing algorithm * based on bitwise XOR (`^`) and multiplication by 33. It produces a non-negative 32-bit integer, * which is then converted to a base-36 string (digits + lowercase letters) to produce a compact output. * * Useful for: * - Generating stable class names in CSS-in-JS libraries. * - Producing consistent cache keys. * - Quick and lightweight hashing needs where cryptographic security is not required. * * ⚠️ This is not cryptographically secure and should not be used for hashing passwords or sensitive data. * * @param input - The input string to hash. * * @returns A short, base-36 encoded hash string. * * @example * ```ts * const className = hashString('background-color: red;'); * // → 'e4k1z0x' * ``` */ export declare const hashString: (input: string) => string;