Skip to content

Commit 567cdbc

Browse files
committed
feat: add lodash
1 parent fd04fd0 commit 567cdbc

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
"commander": "^10.0.0",
6565
"fs-extra": "^11.1.1",
6666
"handlebars": "^4.7.7",
67-
"json-schema-ref-parser": "^9.0.9"
67+
"json-schema-ref-parser": "^9.0.9",
68+
"lodash": "^4.17.21"
6869
},
6970
"devDependencies": {
7071
"@angular-devkit/build-angular": "15.2.5",
@@ -90,6 +91,7 @@
9091
"@types/fs-extra": "^11.0.1",
9192
"@types/glob": "8.1.0",
9293
"@types/jest": "29.5.1",
94+
"@types/lodash": "^4.14.195",
9395
"@types/node": "18.16.3",
9496
"@types/node-fetch": "2.6.3",
9597
"@types/qs": "6.9.7",

src/Case.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { camelCase, snakeCase } from 'lodash';
2+
13
import { Enum } from './client/interfaces/Enum';
24
import { Model } from './client/interfaces/Model';
35
import { OperationResponse } from './client/interfaces/OperationResponse';
@@ -8,19 +10,10 @@ export enum Case {
810
CAMEL = 'camel',
911
SNAKE = 'snake',
1012
}
11-
// Convert a string from snake case to camel case.
12-
const toCamelCase = (str: string): string => {
13-
return str.replace(/_([a-z])/g, match => match[1].toUpperCase());
14-
};
15-
16-
// Convert a string from camel case or pascal case to snake case.
17-
const toSnakeCase = (str: string): string => {
18-
return str.replace(/([A-Z])/g, match => `_${match.toLowerCase()}`);
19-
};
2013

2114
const transforms = {
22-
[Case.CAMEL]: toCamelCase,
23-
[Case.SNAKE]: toSnakeCase,
15+
[Case.CAMEL]: camelCase,
16+
[Case.SNAKE]: snakeCase,
2417
};
2518

2619
// A recursive function that looks at the models and their properties and

0 commit comments

Comments
 (0)