Skip to content

Commit 6645325

Browse files
committed
stripLeadingNonAlphabetChars option
1 parent 8c56b20 commit 6645325

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/casing/src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ export function toPascalCase(str: string) {
66
.replace(/[_\s-]/g, '');
77
}
88

9-
export function toCamelCase(key: string) {
9+
export function toCamelCase(
10+
key: string,
11+
stripLeadingNonAlphabetChars: boolean = false
12+
) {
13+
if (stripLeadingNonAlphabetChars) {
14+
// First, remove all leading non-alphabet characters
15+
key = key.replace(/^[^a-zA-Z]+/, '');
16+
}
1017
return (
1118
key
12-
// First, remove all leading non-alphabet characters
13-
.replace(/^[^a-zA-Z]+/, '')
1419
// Convert what follows a separator into upper case
1520
.replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))
1621
// Ensure the first character of the result is always lowercase

0 commit comments

Comments
 (0)