toKebabCase

Converts the str to kebab-case, where words are separated by hyphens and all letters are lowercase.

Usage Scenarios

  • File Naming: In programming, convert strings to kebab-case for file names.
  • Data Standardization: Standardize string formats in data processing.

Example

import { toKebabCase } from 'funtool/string'

toKebabCase('helloWorld'); // ✅ 'hello-world'
toKebabCase('HelloWorld'); // ✅ 'hello-world'
toKebabCase('myXMLParser'); // ✅ 'my-xml-parser'
toKebabCase('MyXMLParser'); // ✅ 'my-xml-parser'
toKebabCase('hello_world'); // ✅ 'hello-world'
toKebabCase('userID_token'); // ✅ 'user-id-token'

Signature

function toKebabCase(str: string): string

Parameters

  • str ( string ): The input string.

Returns

  • ( string ): A new string in kebab-case format.