-
Notifications
You must be signed in to change notification settings - Fork 168
/
formatParams.ts
43 lines (35 loc) · 901 Bytes
/
formatParams.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
36
37
38
39
40
41
42
43
import { applyType, escapeValue } from '.';
import type { FunctionParam } from '../operations/functions';
import type { MigrationOptions } from '../types';
function formatParam(
mOptions: MigrationOptions
): (param: FunctionParam) => string {
return (param) => {
const {
mode,
name,
type,
default: defaultValue,
} = applyType(param, mOptions.typeShorthands);
const options: string[] = [];
if (mode) {
options.push(mode);
}
if (name) {
options.push(mOptions.literal(name));
}
if (type) {
options.push(type);
}
if (defaultValue) {
options.push(`DEFAULT ${escapeValue(defaultValue)}`);
}
return options.join(' ');
};
}
export function formatParams(
params: ReadonlyArray<FunctionParam>,
mOptions: MigrationOptions
): string {
return `(${params.map(formatParam(mOptions)).join(', ')})`;
}