Skip to content

kebabCase

Import from @varavel/vdl-plugin-sdk/utils/strings.

function kebabCase(str, upperCase?): string;

Converts a string to kebab-case.

The function tokenizes the input with words, lowercases every token, and joins the result with hyphens. This allows mixed casing conventions and noisy separators to converge into a consistent kebab-cased string.

When upperCase is true, the same tokenization and joining rules are used, but the final tokens are uppercased instead. This is useful for constants, identifiers, or file names that still need kebab separators.

Empty or separator-only inputs return an empty string.

Parameters

Parameter Type Default value Description
str string undefined String to normalize.
upperCase boolean false When true, uppercases each token before joining.

Returns

string

The kebab-case representation of str.

Examples

kebabCase("UserProfileName")
// "user-profile-name"
kebabCase("UserProfileName", true)
// "USER-PROFILE-NAME"