export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.slice(1); } export function camelCase(str: string): string { return str .replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : "")) .replace(/^(.)/, m => m.toLowerCase()); } export function kebabCase(str: string): string { return str .replace(/([a-z])([A-Z])/g, "$1-$2") .replace(/\s+/g, "-") .toLowerCase(); } /** * 将字符串转换为 snake_case(小写并以 _ 连接)。 * @param str 源字符串(支持空格和驼峰拆分) * @returns snake_case 形式的字符串 * @example * snakeCase('HelloWorld text') // => 'hello_world_text' */ export function snakeCase(str: string): string { return str .replace(/([a-z])([A-Z])/g, "$1_$2") .replace(/\s+/g, "_") .toLowerCase(); }