Skip to content

Commit

Permalink
fix: support field name with period (#1148)
Browse files Browse the repository at this point in the history
* feat: support field name with period
  • Loading branch information
summer-ji-eng committed Jan 6, 2022
1 parent 590ef70 commit 80c9146
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function capitalize(str: string) {
export function snakeToCamelCase(str: string) {
// split on spaces, non-alphanumeric, or capital letters
const splitted = str
.split(/(?=[A-Z])|[\s\W_]+/)
.split(/(?=[A-Z])|(?:(?!\.)[\s\W_])+/)
.filter(w => w.length > 0)
// Keep the capitalization for the first split.
.map((word, index) => (index === 0 ? word : word.toLowerCase()));
Expand Down
6 changes: 6 additions & 0 deletions test/unit/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ describe('util.ts', () => {
assert.strictEqual(camelToSnakeCase('testAbcDef'), 'test_abc_def');
assert.strictEqual(camelToSnakeCase('IPProtocol'), 'I_p_protocol');
assert.strictEqual(camelToSnakeCase('iPProtocol'), 'i_p_protocol');
assert.strictEqual(camelToSnakeCase('a.1'), 'a.1');
assert.strictEqual(camelToSnakeCase('abc.1Foo'), 'abc.1_foo');
assert.strictEqual(camelToSnakeCase('abc.foo'), 'abc.foo');
});

it('snakeToCamelCase', () => {
Expand All @@ -34,5 +37,8 @@ describe('util.ts', () => {
assert.strictEqual(snakeToCamelCase('test_abc'), 'testAbc');
assert.strictEqual(snakeToCamelCase('test_abc_def'), 'testAbcDef');
assert.strictEqual(snakeToCamelCase('I_p_protocol'), 'IPProtocol');
assert.strictEqual(snakeToCamelCase('a.1'), 'a.1');
assert.strictEqual(snakeToCamelCase('abc.1_foo'), 'abc.1Foo');
assert.strictEqual(snakeToCamelCase('abc.foo'), 'abc.foo');
});
});

0 comments on commit 80c9146

Please sign in to comment.