-
-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathcase.ts
32 lines (28 loc) · 908 Bytes
/
case.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import ts from 'typescript';
import type { IR } from '../../../ir/types';
import { numberRegExp } from '../../../utils/regexp';
import { stringCase } from '../../../utils/stringCase';
/**
* Returns final field name for object properties. This might differ from the
* original value as applying case transform function might alter it.
*/
export const fieldName = ({
context,
name,
}: {
context: IR.Context;
name: string;
}) => {
numberRegExp.lastIndex = 0;
if (numberRegExp.test(name)) {
// For negative numbers, use string literals instead
if (name.startsWith('-')) {
return ts.factory.createStringLiteral(name);
}
return ts.factory.createNumericLiteral(name);
}
// if (typeof context.config.output.case === 'function') {
// return context.config.output.case({ value: name });
// }
return stringCase({ case: context.config.output.case, value: name });
};