UNPKG

stringzy

Version:

A versatile string manipulation library providing a range of text utilities for JavaScript and Node.js applications.

28 lines (27 loc) 978 B
/** * Converts a given string to kebab-case format. * * The conversion process includes: * - Trimming whitespace from both ends. * - Replacing spaces and underscores with hyphens. * - Inserting hyphens between lowercase and uppercase letter boundaries (e.g., `fooBar` → `foo-bar`). * - Replacing all non-word characters (except hyphens) with hyphens. * - Converting the entire string to lowercase. * - Collapsing multiple consecutive hyphens into a single one. * - Removing leading and trailing hyphens. * * If the input is `null` or `undefined`, an empty string is returned. * * @param {string} text - The input string to convert. * @returns {string} The kebab-case formatted string. * * @example * kebabCase("Hello World"); // "hello-world" * * @example * kebabCase("camelCaseText"); // "camel-case-text" * * @example * kebabCase(" convert_to--kebab.case! "); // "convert-to-kebab-case" */ export declare function kebabCase(text: string): string;