Skip to content

Commit d590449

Browse files
committed
fix(string): correct regex patterns in pascalCase and camelCase functions
1 parent 8a5cbc8 commit d590449

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/string.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const kebabCase = (str: string) => str.replace(/([a-z0-9])([A-Z])/g, '$1-
2020
* @param str - The string to convert
2121
* @returns String in PascalCase format
2222
*/
23-
export const pascalCase = (str: string) => str.replace(/(^\w|-\w)/g, char => char.replace('-', '').toUpperCase());
23+
export const pascalCase = (str: string) => str.replace(/(^\w|[-_]\w)/g, char => char.replace(/[-_]/, '').toUpperCase());
2424

2525
/**
2626
* Convert string to camelCase format (驼峰命名)
@@ -32,7 +32,7 @@ export const pascalCase = (str: string) => str.replace(/(^\w|-\w)/g, char => cha
3232
* @param str - The string to convert
3333
* @returns String in camelCase format
3434
*/
35-
export const camelCase = (str: string) => str.replace(/(-\w)/g, char => char.replace('-', '').toUpperCase());
35+
export const camelCase = (str: string) => str.replace(/([-_]\w)/g, char => char.replace(/[-_]/, '').toUpperCase());
3636

3737
/**
3838
* Convert string to snake_case format (蛇形命名)

0 commit comments

Comments
 (0)