Skip to content

toKebabCase

Converts a string to kebab-case format (lowercase and words separated by hyphens).

Syntax

typescript
toKebabCase(str: string): string

Parameters

ParameterTypeDescription
strstringThe input string.

Returns

TypeDescription
stringThe string converted to kebab-case.

Example

typescript
toKebabCase("Exemplo de String"); // "exemplo-de-string"
toKebabCase("  Teste Kebab Case  "); // "teste-kebab-case"
toKebabCase(""); // ""

Notes

  • Throws TypeError if the argument is not a string.
  • Extra spaces are removed before conversion.

References

Released under the MIT License.