toKebabCase

str 转换为短横线命名法(kebab-case),单词之间用连字符分隔,所有字母小写。

使用场景

  • 文件命名:在编程中,将字符串转换为短横线命名法用于文件名。
  • 数据标准化:在数据处理中标准化字符串格式。

示例

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'

函数签名

function toKebabCase(str: string): string

参数

  • str ( string ): 输入的字符串。

返回值

  • ( string ): 一个新的短横线命名法格式的字符串。