-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.js
More file actions
84 lines (80 loc) · 1.51 KB
/
types.js
File metadata and controls
84 lines (80 loc) · 1.51 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
// hyperschema/lib/types.js
const BitwiseNumericTypes = new Set([
"uint1",
"uint2",
"uint3",
"uint4",
"uint5",
"uint6",
"uint7",
]);
const NumericTypes = new Set([
"uint",
...BitwiseNumericTypes,
"uint8",
"uint16",
"uint24",
"uint32",
"uint40",
"uint48",
"uint56",
"uint64",
"int",
"int8",
"int16",
"int24",
"int32",
"int40",
"int48",
"int56",
"int64",
"float32",
"float64",
"port",
"lexint",
]);
const StringTypes = new Set(["string", "utf8", "ascii", "hex"]);
const BigIntTypes = new Set(["bigint", "biguint64", "bigint64"]);
const ObjectTypes = new Set(["fixed32", "fixed64", "buffer", "date"]);
const BooleanTypes = new Set(["bool"]);
const NetworkTypes = new Set([
"ip",
"ipv4",
"ipv6",
"ipAddress",
"ipv4Address",
"ipv6Address",
]);
const SupportedTypes = new Set([
...NumericTypes,
...StringTypes,
...BigIntTypes,
...ObjectTypes,
...BooleanTypes,
...NetworkTypes,
"none",
"raw",
"json",
]);
function getBitwiseSize(type) {
if (type === "uint1") return 1;
if (type === "uint2") return 2;
if (type === "uint3") return 3;
if (type === "uint4") return 4;
if (type === "uint5") return 5;
if (type === "uint6") return 6;
if (type === "uint7") return 7;
return 0;
}
function getDefaultValue(type) {
if (NumericTypes.has(type)) return 0;
if (BigIntTypes.has(type)) return 0n;
if (BooleanTypes.has(type)) return false;
return null;
}
module.exports = {
SupportedTypes,
BitwiseNumericTypes,
getDefaultValue,
getBitwiseSize,
};