-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommon.util.ts
More file actions
92 lines (83 loc) · 2.17 KB
/
Copy pathcommon.util.ts
File metadata and controls
92 lines (83 loc) · 2.17 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {
anyExportable,
booleanExportable,
ExportableType,
FunctionExportable,
integerExportable,
LiteralExportable,
nullExportable,
numberExportable,
stringExportable,
tableExportable,
} from "./export-types";
/**
* Mappings from known LuaHelp types to corresponding Exportable.
*/
export const luaHelpTypeToExportable: Record<string, ExportableType> = {
String: stringExportable,
Int: integerExportable,
Number: numberExportable,
Boolean: booleanExportable,
Table: tableExportable,
// Blank anonymous function
Function: new FunctionExportable(),
Object: anyExportable,
};
/**
* Describes a generic type which has a documented description.
*/
export interface IDocFuncType {
type: ExportableType;
description: string;
additionalDescription: string[];
setDescription(description: string): void;
addDescription(desc: string): void;
setType(type: ExportableType): void;
}
/**
* Describes a parameter which has a documented description.
*/
export interface IDocFuncParam extends IDocFuncType {
name: string;
/**
* The overriden name to export instead of `name`
*/
overrideName?: string;
get displayName(): string;
setOverrideName(name: string): void;
}
/**
* Describes a doc function that can be altered.
*/
export interface IDocFunc {
params: Map<string, IDocFuncParam>;
addParam(param: IDocFuncParam): this;
setDescription(description: string | string[]): void;
pushDescription(description: string): this;
}
/**
* Batch utility function for param quick fixups.
*/
export function fixParam<T extends IDocFunc>(
lfnc: T,
replace: [name: string, desc?: string, overrideName?: string][]
) {
for (const [name, desc, overrideName] of replace) {
const par = lfnc.params.get(name);
if (desc) par.setDescription(desc);
if (overrideName) par.setOverrideName(overrideName);
}
}
/**
* Batch utility function for param fixups.
*/
export function forParams<
T extends IDocFunc,
S = T["params"] extends Map<infer _, infer V extends IDocFuncParam>
? V
: never
>(lfunc: T, handlers: [paramName: string, callback: (par: S) => void][]) {
for (const [name, cb] of handlers) {
cb(lfunc.params.get(name) as S);
}
}