API
@agape/string

toKebabCase Function

Converts a string to kebab-case.

API

function toKebabCase(  input: string): string

toKebabCase

string

Converts a string to kebab-case.

@paraminput:  string
A string to be converted to kebab-case.
@returnsstring

Description

Converts a string to kebab-case.

Replaces spaces, underscores, camelCase transitions, and other separators with dashes. It also preserves version tokens like "v2" and lowercases the result.

Usage

toKebabCase("hello world"); // "hello-world"
toKebabCase("first_name"); // "first-name"
toKebabCase("userProfile42"); // "user-profile-42"
toKebabCase("APIResponseV2"); // "api-response-v2"
toKebabCase("HTML5_Parser v3"); // "html-5-parser-v3"
toKebabCase("  Leading_and trailing   "); // "leading-and-trailing"