@lodestar/utils 1.35.0-dev.8ea34e52ba → 1.35.0-dev.91dadf81de

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/lib/assert.d.ts.map +1 -0
  2. package/lib/base64.d.ts.map +1 -0
  3. package/lib/bytes/browser.d.ts.map +1 -0
  4. package/lib/bytes/index.d.ts.map +1 -0
  5. package/lib/bytes/nodejs.d.ts.map +1 -0
  6. package/lib/bytes.d.ts.map +1 -0
  7. package/lib/command.d.ts.map +1 -0
  8. package/lib/diff.d.ts.map +1 -0
  9. package/lib/err.d.ts.map +1 -0
  10. package/lib/errors.d.ts.map +1 -0
  11. package/lib/ethConversion.d.ts.map +1 -0
  12. package/lib/fetch.d.ts.map +1 -0
  13. package/lib/format.d.ts.map +1 -0
  14. package/lib/index.d.ts +8 -8
  15. package/lib/index.d.ts.map +1 -0
  16. package/lib/index.js +6 -6
  17. package/lib/index.js.map +1 -1
  18. package/lib/iterator.d.ts.map +1 -0
  19. package/lib/logger.d.ts.map +1 -0
  20. package/lib/map.d.ts.map +1 -0
  21. package/lib/math.d.ts.map +1 -0
  22. package/lib/metrics.d.ts.map +1 -0
  23. package/lib/notNullish.d.ts.map +1 -0
  24. package/lib/objects.d.ts.map +1 -0
  25. package/lib/promise.d.ts.map +1 -0
  26. package/lib/retry.d.ts.map +1 -0
  27. package/lib/sleep.d.ts.map +1 -0
  28. package/lib/sort.d.ts.map +1 -0
  29. package/lib/timeout.d.ts.map +1 -0
  30. package/lib/types.d.ts.map +1 -0
  31. package/lib/url.d.ts.map +1 -0
  32. package/lib/verifyMerkleBranch.d.ts.map +1 -0
  33. package/lib/waitFor.d.ts.map +1 -0
  34. package/lib/yaml/index.d.ts.map +1 -0
  35. package/lib/yaml/int.d.ts.map +1 -0
  36. package/lib/yaml/schema.d.ts.map +1 -0
  37. package/lib/yaml/schema.js.map +1 -1
  38. package/package.json +11 -8
  39. package/src/assert.ts +86 -0
  40. package/src/base64.ts +9 -0
  41. package/src/bytes/browser.ts +123 -0
  42. package/src/bytes/index.ts +29 -0
  43. package/src/bytes/nodejs.ts +63 -0
  44. package/src/bytes.ts +84 -0
  45. package/src/command.ts +74 -0
  46. package/src/diff.ts +234 -0
  47. package/src/err.ts +105 -0
  48. package/src/errors.ts +73 -0
  49. package/src/ethConversion.ts +12 -0
  50. package/src/fetch.ts +188 -0
  51. package/src/format.ts +119 -0
  52. package/src/index.ts +28 -0
  53. package/src/iterator.ts +10 -0
  54. package/src/logger.ts +20 -0
  55. package/src/map.ts +108 -0
  56. package/src/math.ts +55 -0
  57. package/src/metrics.ts +73 -0
  58. package/src/notNullish.ts +11 -0
  59. package/src/objects.ts +102 -0
  60. package/src/promise.ts +163 -0
  61. package/src/retry.ts +75 -0
  62. package/src/sleep.ts +32 -0
  63. package/src/sort.ts +9 -0
  64. package/src/timeout.ts +27 -0
  65. package/src/types.ts +48 -0
  66. package/src/url.ts +29 -0
  67. package/src/verifyMerkleBranch.ts +27 -0
  68. package/src/waitFor.ts +87 -0
  69. package/src/yaml/index.ts +12 -0
  70. package/src/yaml/int.ts +190 -0
  71. package/src/yaml/schema.ts +8 -0
@@ -0,0 +1,190 @@
1
+ // Forked from https://github.com/nodeca/js-yaml/blob/master/lib/type/int.js
2
+ // Currently only supports loading ints
3
+ import yaml from "js-yaml";
4
+
5
+ const {Type} = yaml;
6
+
7
+ function isHexCode(c: number): boolean {
8
+ return (
9
+ // 0, 9
10
+ (0x30 <= c && c <= 0x39) ||
11
+ // A, F
12
+ (0x41 <= c && c <= 0x46) ||
13
+ // a, f
14
+ (0x61 <= c && c <= 0x66)
15
+ );
16
+ }
17
+
18
+ function isOctCode(c: number): boolean {
19
+ return 0x30 /* 0 */ <= c && c <= 0x37 /* 7 */;
20
+ }
21
+
22
+ function isDecCode(c: number): boolean {
23
+ return 0x30 /* 0 */ <= c && c <= 0x39 /* 9 */;
24
+ }
25
+
26
+ function resolveYamlInteger(data: string): boolean {
27
+ if (data === null) return false;
28
+
29
+ const max = data.length;
30
+ let ch: string,
31
+ index = 0,
32
+ hasDigits = false;
33
+
34
+ if (!max) return false;
35
+
36
+ ch = data[index];
37
+
38
+ // sign
39
+ if (ch === "-" || ch === "+") {
40
+ ch = data[++index];
41
+ }
42
+
43
+ if (ch === "0") {
44
+ // 0
45
+ if (index + 1 === max) return true;
46
+ ch = data[++index];
47
+
48
+ // base 2, base 8, base 16
49
+
50
+ if (ch === "b") {
51
+ // base 2
52
+ index++;
53
+
54
+ for (; index < max; index++) {
55
+ ch = data[index];
56
+ if (ch === "_") continue;
57
+ if (ch !== "0" && ch !== "1") return false;
58
+ hasDigits = true;
59
+ }
60
+ return hasDigits && ch !== "_";
61
+ }
62
+
63
+ if (ch === "x") {
64
+ // base 16
65
+ index++;
66
+
67
+ for (; index < max; index++) {
68
+ ch = data[index];
69
+ if (ch === "_") continue;
70
+ if (!isHexCode(data.charCodeAt(index))) return false;
71
+ hasDigits = true;
72
+ }
73
+ return hasDigits && ch !== "_";
74
+ }
75
+
76
+ // base 8
77
+ for (; index < max; index++) {
78
+ ch = data[index];
79
+ if (ch === "_") continue;
80
+ if (!isOctCode(data.charCodeAt(index))) return false;
81
+ hasDigits = true;
82
+ }
83
+ return hasDigits && ch !== "_";
84
+ }
85
+
86
+ // base 10 (except 0) or base 60
87
+
88
+ // value should not start with `_`;
89
+ if (ch === "_") return false;
90
+
91
+ for (; index < max; index++) {
92
+ ch = data[index];
93
+ if (ch === "_") continue;
94
+ if (ch === ":") break;
95
+ if (!isDecCode(data.charCodeAt(index))) {
96
+ return false;
97
+ }
98
+ hasDigits = true;
99
+ }
100
+
101
+ // Should have digits and should not end with `_`
102
+ if (!hasDigits || ch === "_") return false;
103
+
104
+ // if !base60 - done;
105
+ if (ch !== ":") return true;
106
+
107
+ // base60 almost not used, no needs to optimize
108
+ return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
109
+ }
110
+
111
+ function constructYamlInteger(data: string): bigint {
112
+ let value: string | bigint = data,
113
+ sign = 1,
114
+ ch: string,
115
+ base: number | bigint;
116
+ const digits: number[] = [];
117
+
118
+ if (value.indexOf("_") !== -1) {
119
+ value = value.replace(/_/g, "");
120
+ }
121
+
122
+ ch = value[0];
123
+
124
+ if (ch === "-" || ch === "+") {
125
+ if (ch === "-") sign = -1;
126
+ value = value.slice(1);
127
+ ch = value[0];
128
+ }
129
+
130
+ if (value === "0") return BigInt(0);
131
+
132
+ if (ch === "0") {
133
+ if (value[1] === "b" || value[1] === "x") return BigInt(value) * BigInt(sign);
134
+ return BigInt("0o" + value) * BigInt(sign);
135
+ }
136
+
137
+ if (value.indexOf(":") !== -1) {
138
+ for (const v of value.split(":")) {
139
+ digits.unshift(parseInt(v, 10));
140
+ }
141
+ value = BigInt(0);
142
+ base = BigInt(1);
143
+
144
+ for (const d of digits) {
145
+ value = (BigInt(value) + BigInt(base)) * BigInt(d);
146
+ base = BigInt(base) * BigInt(60);
147
+ }
148
+
149
+ return value * BigInt(sign);
150
+ }
151
+
152
+ return BigInt(value) * BigInt(sign);
153
+ }
154
+
155
+ function isInteger(object: unknown): boolean {
156
+ return typeof object === "bigint" || typeof object === "number";
157
+ }
158
+
159
+ export const intType = new Type("tag:yaml.org,2002:int", {
160
+ kind: "scalar",
161
+ resolve: resolveYamlInteger,
162
+ construct: constructYamlInteger,
163
+ predicate: isInteger,
164
+ instanceOf: BigInt,
165
+ represent: {
166
+ // @ts-expect-error
167
+ binary: function binary(obj: number) {
168
+ return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
169
+ },
170
+ // @ts-expect-error
171
+ octal: function octal(obj: number) {
172
+ return obj >= 0 ? "0" + obj.toString(8) : "-0" + obj.toString(8).slice(1);
173
+ },
174
+ // @ts-expect-error
175
+ decimal: function decimal(obj: number) {
176
+ return obj.toString(10);
177
+ },
178
+ // @ts-expect-error
179
+ hexadecimal: function hexadecimal(obj: number) {
180
+ return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
181
+ },
182
+ },
183
+ defaultStyle: "decimal",
184
+ styleAliases: {
185
+ binary: [2, "bin"],
186
+ octal: [8, "oct"],
187
+ decimal: [10, "dec"],
188
+ hexadecimal: [16, "hex"],
189
+ },
190
+ });
@@ -0,0 +1,8 @@
1
+ import yml, {FAILSAFE_SCHEMA, Type} from "js-yaml";
2
+ import {intType} from "./int.js";
3
+
4
+ export const schema = FAILSAFE_SCHEMA.extend({
5
+ // @ts-expect-error
6
+ implicit: [yml.types.null as Type, yml.types.bool as Type, intType, yml.types.float as Type],
7
+ explicit: [],
8
+ });