generated from Himenon/template-js
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathutils.ts
35 lines (31 loc) · 1.28 KB
/
utils.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
33
34
35
export const parameterName = (operationId: string): string => `Parameter$${operationId}`;
export const requestBodyName = (operationId: string): string => `RequestBody$${operationId}`;
export const argumentParamsTypeDeclaration = (operationId: string): string => `Params$${operationId}`;
export const responseName = (operationId: string, statusCode: string): string => `Response$${operationId}$Status$${statusCode}`;
export const requestContentType = (operationId: string): string => `RequestContentType$${operationId}`;
export const responseContentType = (operationId: string): string => `ResponseContentType$${operationId}`;
export const isAvailableVariableName = (text: string): boolean => {
return /^[A-Za-z_0-9]+$/.test(text);
};
export const isFirstCharacterIsValidText = (text: string): boolean => {
return /^[A-Za-z]+/.test(text);
};
export const escapeText = (text: string): string => {
if (isAvailableVariableName(text) && isFirstCharacterIsValidText(text)) {
return text;
}
return `"${text}"`;
};
/** TODO escapeTextにマージする */
export const escapeText2 = (text: string): { escaped: boolean; text: string } => {
if (isAvailableVariableName(text)) {
return {
escaped: false,
text: text,
};
}
return {
escaped: true,
text: `"${text}"`,
};
};