字符串工具
toCamelCase
将短横线命名(kebab-case)转换为驼峰命名(camelCase)。
ts
declare function toCamelCase(str: string): stringtsx
import { toCamelCase } from 'vitarx'
toCamelCase('hello-world') // 'helloWorld'
toCamelCase('font-size') // 'fontSize'
toCamelCase('border-radius') // 'borderRadius'toKebabCase
将驼峰命名(camelCase)转换为短横线命名(kebab-case)。
ts
declare function toKebabCase(str: string): stringtsx
import { toKebabCase } from 'vitarx'
toKebabCase('helloWorld') // 'hello-world'
toKebabCase('fontSize') // 'font-size'
toKebabCase('borderRadius') // 'border-radius'toCapitalize
将字符串首字母大写。
ts
declare function toCapitalize<T extends string>(str: T): Capitalize<T>tsx
import { toCapitalize } from 'vitarx'
toCapitalize('hello') // 'Hello'
toCapitalize('world') // 'World'
toCapitalize('hello world') // 'Hello world'下一步
- 对象工具 — 了解对象操作工具函数