camelCase()
function camelCase(str): string;
Defined in: string/camelCase.ts:25
将字符串转换为驼峰命名格式 驼峰命名规则:首字母小写,后续每个单词首字母大写,单词间无分隔符 支持处理包含连字符(-)、下划线(_)、空格或大小写混合的字符串
Parameters
| Parameter | Type | Description |
|---|---|---|
str | string | 输入字符串,可以包含各种分隔符或混合大小写 |
Returns
string
转换后的驼峰式字符串
Examples
camelCase('hello-world'); // 返回 'helloWorld'
camelCase('Hello_World'); // 返回 'helloWorld'
camelCase('hello world'); // 返回 'helloWorld'
camelCase('HelloWorld'); // 返回 'helloWorld'
camelCase(' hello--world '); // 返回 'helloWorld'(自动去除首尾空格)
camelCase(''); // 返回 ''(空字符串输入返回空字符串)
**Note:** 内部使用getWords()函数拆分单词,使用capitalize()函数处理单词首字母