|
1 | 1 | export type LuaType = |
2 | | - | "nil" |
3 | | - | ("boolean" | "bool") |
4 | | - | "number" |
5 | | - | "string" |
6 | | - | "table" |
7 | | - | ("tuple" | "...") |
8 | | - | ("userdata" | "proxy"); |
| 2 | + | "nil" |
| 3 | + | ("boolean" | "bool") |
| 4 | + | "number" |
| 5 | + | "string" |
| 6 | + | "table" |
| 7 | + | ("tuple" | "...") |
| 8 | + | ("userdata" | "proxy"); |
9 | 9 |
|
10 | 10 | export type LuaParam = { |
11 | | - name: string; |
12 | | - type: LuaType | string; |
| 11 | + name: string; |
| 12 | + type: LuaType | string; |
13 | 13 | }; |
14 | 14 |
|
15 | 15 | export const luaTypeDocs: Record<LuaType, string> = { |
16 | | - nil: "2.1", |
17 | | - boolean: "2.2", |
18 | | - bool: "2.2", |
19 | | - number: "2.3", |
20 | | - string: "2.4", |
21 | | - table: "2.5", |
22 | | - tuple: "5.1", |
23 | | - "...": "5.1", |
24 | | - userdata: "28.1", |
25 | | - proxy: "28.1", |
| 16 | + nil: "2.1", |
| 17 | + boolean: "2.2", |
| 18 | + bool: "2.2", |
| 19 | + number: "2.3", |
| 20 | + string: "2.4", |
| 21 | + table: "2.5", |
| 22 | + tuple: "5.1", |
| 23 | + "...": "5.1", |
| 24 | + userdata: "28.1", |
| 25 | + proxy: "28.1", |
26 | 26 | }; |
27 | 27 |
|
28 | 28 | export const removeTypeModifiers = (type: string) => { |
29 | | - return type.replaceAll(/\?/g, "") as LuaType; |
| 29 | + return type.replaceAll(/\?/g, "") as LuaType; |
30 | 30 | }; |
31 | 31 |
|
32 | | -export const getLuaDocs = (luaType: LuaType | string) => { |
33 | | - const normalizedType = removeTypeModifiers(luaType); |
34 | | - const luaDocsBaseUrl = new URL("https://www.lua.org/pil"); |
35 | | - luaDocsBaseUrl.pathname += "/" + luaTypeDocs[normalizedType] + ".html"; |
| 32 | +export const getLuaDocs = (luaType: LuaType) => { |
| 33 | + const luaDocsBaseUrl = new URL("https://www.lua.org/pil"); |
| 34 | + luaDocsBaseUrl.pathname += "/" + luaTypeDocs[luaType] + ".html"; |
36 | 35 |
|
37 | | - return luaDocsBaseUrl.toString(); |
| 36 | + return luaDocsBaseUrl.toString(); |
38 | 37 | }; |
39 | 38 |
|
40 | 39 | export const getCustomTypeDocs = (type: string) => { |
41 | | - if (type == "()" || type == "any") { |
42 | | - return null; |
43 | | - } |
| 40 | + if (type == "()" || type == "any") { |
| 41 | + return null; |
| 42 | + } |
44 | 43 |
|
45 | | - const path = |
46 | | - "/classes/" + |
47 | | - type |
48 | | - .split(".") |
49 | | - .map((component) => component.toLocaleLowerCase()) |
50 | | - .join("/"); |
| 44 | + const path = |
| 45 | + "/classes/" + |
| 46 | + type |
| 47 | + .split(".") |
| 48 | + .map((component) => component.toLocaleLowerCase()) |
| 49 | + .join("/"); |
51 | 50 |
|
52 | | - return path; |
| 51 | + return path; |
53 | 52 | }; |
54 | 53 |
|
55 | 54 | export const getTypeDocs = (type: string) => { |
56 | | - return type in luaTypeDocs |
57 | | - ? getLuaDocs(type as LuaType) |
58 | | - : getCustomTypeDocs(type); |
| 55 | + const normalizedType = removeTypeModifiers(type); |
| 56 | + return normalizedType in luaTypeDocs |
| 57 | + ? getLuaDocs(normalizedType) |
| 58 | + : getCustomTypeDocs(type); |
59 | 59 | }; |
60 | 60 |
|
61 | 61 | export const typeOrDefault = (type?: string) => { |
62 | | - return type ?? "()"; |
| 62 | + return type ?? "()"; |
63 | 63 | }; |
64 | 64 |
|
65 | 65 | export const getKvPairs = (tblInner: string) => { |
66 | | - tblInner = tblInner.trim(); |
67 | | - const pairs = tblInner |
68 | | - .split(",") |
69 | | - .map((pair) => pair.split(":").map((elem) => elem.trim())); |
| 66 | + tblInner = tblInner.trim(); |
| 67 | + const pairs = tblInner |
| 68 | + .split(",") |
| 69 | + .map((pair) => pair.split(":").map((elem) => elem.trim())); |
70 | 70 |
|
71 | | - return pairs; |
| 71 | + return pairs; |
72 | 72 | }; |
73 | 73 |
|
74 | 74 | export const isObject = (tblInner: string) => { |
75 | | - return tblInner.match(/(.*):(.*)/) !== null; |
| 75 | + return tblInner.match(/(.*):(.*)/) !== null; |
76 | 76 | }; |
0 commit comments