Skip to content

Commit b0c08a5

Browse files
author
k.golikov
committed
Json-To-TypeScript: some fixes and improvements
1 parent b8b91e0 commit b0c08a5

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

src/pages/jsonToTypeScriptPage/JsonToTypeScriptPage.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import JsonToTypeScriptConversionSelectableOptions, {
1717
NameTransformer
1818
} from './types/JsonToTypeScriptConversionSelectableOptions';
1919
import JsonToTypeScriptConversionOptions from './types/JsonToTypeScriptConversionOptions';
20-
import { camelCase, snakeCase, upperCase } from 'lodash';
20+
import { camelCase, kebabCase, snakeCase } from 'lodash';
2121
import pascalCase from '../../utils/pascalCase';
2222
import JsonToTypeScriptSettings from './components/JsonToTypeScriptSettings';
23+
import screamingSnakeCase from '../../utils/screamingSnakeCase';
2324

2425
const jsonEditorOptions: editor.IStandaloneEditorConstructionOptions = {
2526
minimap: { enabled: false }
@@ -43,7 +44,8 @@ const nameTransformers: Readonly<Record<NameTransformer, (name: string) => strin
4344
[NameTransformer.CAMEL_CASE]: camelCase,
4445
[NameTransformer.PASCAL_CASE]: pascalCase,
4546
[NameTransformer.SNAKE_CASE]: snakeCase,
46-
[NameTransformer.SCREAMING_SNAKE_CASE]: (name) => upperCase(snakeCase(name))
47+
[NameTransformer.SCREAMING_SNAKE_CASE]: screamingSnakeCase,
48+
[NameTransformer.KEBAB_CASE]: kebabCase
4749
};
4850

4951
const getConversionOptions = (

src/pages/jsonToTypeScriptPage/components/JsonToTypeScriptSettings.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ const JsonToTypeScriptSettings: FunctionComponent<Props> = ({ options, setOption
4747
<Select.Option key={ExportType.NONE}>None</Select.Option>
4848
<Select.Option key={ExportType.ES_MODULE}>ES Module</Select.Option>
4949
<Select.Option key={ExportType.COMMONJS}>
50-
<Text type="danger">CommonJS</Text>
50+
<Text type="danger" title="CommonJS">
51+
CommonJS
52+
</Text>
5153
</Select.Option>
5254
</Select>
5355
</label>
@@ -63,6 +65,7 @@ const JsonToTypeScriptSettings: FunctionComponent<Props> = ({ options, setOption
6365
<Select.Option key={NameTransformer.PASCAL_CASE}>PascalCase</Select.Option>
6466
<Select.Option key={NameTransformer.SNAKE_CASE}>snake_case</Select.Option>
6567
<Select.Option key={NameTransformer.SCREAMING_SNAKE_CASE}>SCREAMING_SNAKE_CASE</Select.Option>
68+
<Select.Option key={NameTransformer.KEBAB_CASE}>kebab-case</Select.Option>
6669
</Select>
6770
</label>
6871
<label className={styles.formItem}>

src/pages/jsonToTypeScriptPage/types/JsonToTypeScriptConversionSelectableOptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export enum NameTransformer {
55
CAMEL_CASE = 'CAMEL_CASE',
66
PASCAL_CASE = 'PASCAL_CASE',
77
SNAKE_CASE = 'SNAKE_CASE',
8-
SCREAMING_SNAKE_CASE = 'SCREAMING_SNAKE_CASE'
8+
SCREAMING_SNAKE_CASE = 'SCREAMING_SNAKE_CASE',
9+
KEBAB_CASE = 'KEBAB_CASE'
910
}
1011

1112
interface JsonToTypeScriptConversionSelectableOptions {

src/utils/pascalCase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { camelCase } from 'lodash';
22
import capitalizeFirst from './capitalizeFirst';
33

4-
const pascalCase = (source: string) => {
5-
return capitalizeFirst(camelCase(source));
4+
const pascalCase = (string: string) => {
5+
return capitalizeFirst(camelCase(string));
66
};
77

88
export default pascalCase;

src/utils/screamingSnakeCase.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { snakeCase } from 'lodash';
2+
3+
const screamingSnakeCase = (string: string) => {
4+
return snakeCase(string).toLocaleUpperCase();
5+
};
6+
7+
export default screamingSnakeCase;

0 commit comments

Comments
 (0)