Browse Source

Merge pull request #928 from colinin/add-toCameCase

feat: add toCameCase to strings utils.
pull/930/head
yx lin 2 years ago
committed by GitHub
parent
commit
519ec2312c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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