-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreference.js
43 lines (31 loc) · 1.14 KB
/
reference.js
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
// name.includes("<-") && (options.ref = name.match(/<-(.*)/)?.[1] || null) && ( name = name.replace(/<-(.*)/, "") );
/* // remove modifiers from name
name = name.replace(/[\!\*\#]/g, "");
// remove reference from name
name = name.replace(/<-(.*)/, "");
options.default = name.match(/=(.*)/)?.[1] || null;
name = name.replace(/=(.*)/, "");
if (fields.length == 1) {
options.type = Schema.Types.Mixed ;
}
if (modifiers) {
if (modifiers.includes("[") && modifiers.includes("]")) {
// extract [...] array using regex
options.enum = modifiers.match(/\[(.*?)\]/)[1].split(",");
}
if (modifiers.includes("<=>")) {
// set min and max min<=>max parse lhs and rhs integers using regex
const [min, max] = modifiers.match(/(\d+)<=>(\d+)/).slice(1);
if (type == Schema.Types.Number) { // if type is number use min and max
options.min = parseInt(min);
options.max = parseInt(max);
}
if (type == Schema.Types.String) { // if type is string use length instead
options.minlength = parseInt(min);
options.maxlength = parseInt(max);
}
}
}
options.type = type;
results[name] = options;
return results; */