Browse Source

feat: add toCameCase to strings utils.

pull/928/head
unknown 3 years ago
parent
commit
34383439e0
  1. 12
      apps/vue/src/utils/strings.ts

12
apps/vue/src/utils/strings.ts

@ -20,6 +20,18 @@ export function format(formatted: string, args: object | any[]) {
} }
return formatted; return formatted;
} }
/**
* 字符串转驼峰格式
* @param str 字符串
* @returns 字符串的驼峰表示法
* @example toCamelCase('hello-world') => helloWorld
* @example toCamelCase('my_variable_name') => myVariableName
*/
export function toCamelCase(str: string) {
return str.replace(/[-_\s](\w)/g, function (_, c) {
return c ? c.toUpperCase() : '';
});
}
/** /**
* *
* @param str 字符串是否为空或空格 * @param str 字符串是否为空或空格

Loading…
Cancel
Save