@eternl/tools 0.1.0
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.
- package/README.md +36 -0
- package/dist/index.cjs +72 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +13 -0
- package/dist/lib/array.cjs +53 -0
- package/dist/lib/array.cjs.map +1 -0
- package/dist/lib/array.d.cts +10 -0
- package/dist/lib/array.d.cts.map +1 -0
- package/dist/lib/array.d.mts +10 -0
- package/dist/lib/array.d.mts.map +1 -0
- package/dist/lib/array.mjs +46 -0
- package/dist/lib/array.mjs.map +1 -0
- package/dist/lib/crc8.cjs +270 -0
- package/dist/lib/crc8.cjs.map +1 -0
- package/dist/lib/crc8.d.cts +5 -0
- package/dist/lib/crc8.d.cts.map +1 -0
- package/dist/lib/crc8.d.mts +5 -0
- package/dist/lib/crc8.d.mts.map +1 -0
- package/dist/lib/crc8.mjs +268 -0
- package/dist/lib/crc8.mjs.map +1 -0
- package/dist/lib/hex.cjs +87 -0
- package/dist/lib/hex.cjs.map +1 -0
- package/dist/lib/hex.d.cts +26 -0
- package/dist/lib/hex.d.cts.map +1 -0
- package/dist/lib/hex.d.mts +26 -0
- package/dist/lib/hex.d.mts.map +1 -0
- package/dist/lib/hex.mjs +64 -0
- package/dist/lib/hex.mjs.map +1 -0
- package/dist/lib/id.cjs +10 -0
- package/dist/lib/id.cjs.map +1 -0
- package/dist/lib/id.d.cts +6 -0
- package/dist/lib/id.d.cts.map +1 -0
- package/dist/lib/id.d.mts +6 -0
- package/dist/lib/id.d.mts.map +1 -0
- package/dist/lib/id.mjs +7 -0
- package/dist/lib/id.mjs.map +1 -0
- package/dist/lib/json.cjs +92 -0
- package/dist/lib/json.cjs.map +1 -0
- package/dist/lib/json.d.cts +14 -0
- package/dist/lib/json.d.cts.map +1 -0
- package/dist/lib/json.d.mts +14 -0
- package/dist/lib/json.d.mts.map +1 -0
- package/dist/lib/json.mjs +87 -0
- package/dist/lib/json.mjs.map +1 -0
- package/dist/lib/math.cjs +25 -0
- package/dist/lib/math.cjs.map +1 -0
- package/dist/lib/math.d.cts +8 -0
- package/dist/lib/math.d.cts.map +1 -0
- package/dist/lib/math.d.mts +8 -0
- package/dist/lib/math.d.mts.map +1 -0
- package/dist/lib/math.mjs +23 -0
- package/dist/lib/math.mjs.map +1 -0
- package/dist/lib/number.cjs +8 -0
- package/dist/lib/number.cjs.map +1 -0
- package/dist/lib/number.d.cts +5 -0
- package/dist/lib/number.d.cts.map +1 -0
- package/dist/lib/number.d.mts +5 -0
- package/dist/lib/number.d.mts.map +1 -0
- package/dist/lib/number.mjs +6 -0
- package/dist/lib/number.mjs.map +1 -0
- package/dist/lib/sleep.cjs +19 -0
- package/dist/lib/sleep.cjs.map +1 -0
- package/dist/lib/sleep.d.cts +10 -0
- package/dist/lib/sleep.d.cts.map +1 -0
- package/dist/lib/sleep.d.mts +10 -0
- package/dist/lib/sleep.d.mts.map +1 -0
- package/dist/lib/sleep.mjs +13 -0
- package/dist/lib/sleep.mjs.map +1 -0
- package/dist/lib/string.cjs +64 -0
- package/dist/lib/string.cjs.map +1 -0
- package/dist/lib/string.d.cts +18 -0
- package/dist/lib/string.d.cts.map +1 -0
- package/dist/lib/string.d.mts +18 -0
- package/dist/lib/string.d.mts.map +1 -0
- package/dist/lib/string.mjs +56 -0
- package/dist/lib/string.mjs.map +1 -0
- package/dist/lib/time.cjs +27 -0
- package/dist/lib/time.cjs.map +1 -0
- package/dist/lib/time.d.cts +7 -0
- package/dist/lib/time.d.cts.map +1 -0
- package/dist/lib/time.d.mts +7 -0
- package/dist/lib/time.d.mts.map +1 -0
- package/dist/lib/time.mjs +23 -0
- package/dist/lib/time.mjs.map +1 -0
- package/dist/log/index.cjs +23 -0
- package/dist/log/index.cjs.map +1 -0
- package/dist/log/index.d.cts +11 -0
- package/dist/log/index.d.cts.map +1 -0
- package/dist/log/index.d.mts +11 -0
- package/dist/log/index.d.mts.map +1 -0
- package/dist/log/index.mjs +17 -0
- package/dist/log/index.mjs.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
//#region src/lib/crc8.ts
|
|
2
|
+
let TABLE = [
|
|
3
|
+
0,
|
|
4
|
+
7,
|
|
5
|
+
14,
|
|
6
|
+
9,
|
|
7
|
+
28,
|
|
8
|
+
27,
|
|
9
|
+
18,
|
|
10
|
+
21,
|
|
11
|
+
56,
|
|
12
|
+
63,
|
|
13
|
+
54,
|
|
14
|
+
49,
|
|
15
|
+
36,
|
|
16
|
+
35,
|
|
17
|
+
42,
|
|
18
|
+
45,
|
|
19
|
+
112,
|
|
20
|
+
119,
|
|
21
|
+
126,
|
|
22
|
+
121,
|
|
23
|
+
108,
|
|
24
|
+
107,
|
|
25
|
+
98,
|
|
26
|
+
101,
|
|
27
|
+
72,
|
|
28
|
+
79,
|
|
29
|
+
70,
|
|
30
|
+
65,
|
|
31
|
+
84,
|
|
32
|
+
83,
|
|
33
|
+
90,
|
|
34
|
+
93,
|
|
35
|
+
224,
|
|
36
|
+
231,
|
|
37
|
+
238,
|
|
38
|
+
233,
|
|
39
|
+
252,
|
|
40
|
+
251,
|
|
41
|
+
242,
|
|
42
|
+
245,
|
|
43
|
+
216,
|
|
44
|
+
223,
|
|
45
|
+
214,
|
|
46
|
+
209,
|
|
47
|
+
196,
|
|
48
|
+
195,
|
|
49
|
+
202,
|
|
50
|
+
205,
|
|
51
|
+
144,
|
|
52
|
+
151,
|
|
53
|
+
158,
|
|
54
|
+
153,
|
|
55
|
+
140,
|
|
56
|
+
139,
|
|
57
|
+
130,
|
|
58
|
+
133,
|
|
59
|
+
168,
|
|
60
|
+
175,
|
|
61
|
+
166,
|
|
62
|
+
161,
|
|
63
|
+
180,
|
|
64
|
+
179,
|
|
65
|
+
186,
|
|
66
|
+
189,
|
|
67
|
+
199,
|
|
68
|
+
192,
|
|
69
|
+
201,
|
|
70
|
+
206,
|
|
71
|
+
219,
|
|
72
|
+
220,
|
|
73
|
+
213,
|
|
74
|
+
210,
|
|
75
|
+
255,
|
|
76
|
+
248,
|
|
77
|
+
241,
|
|
78
|
+
246,
|
|
79
|
+
227,
|
|
80
|
+
228,
|
|
81
|
+
237,
|
|
82
|
+
234,
|
|
83
|
+
183,
|
|
84
|
+
176,
|
|
85
|
+
185,
|
|
86
|
+
190,
|
|
87
|
+
171,
|
|
88
|
+
172,
|
|
89
|
+
165,
|
|
90
|
+
162,
|
|
91
|
+
143,
|
|
92
|
+
136,
|
|
93
|
+
129,
|
|
94
|
+
134,
|
|
95
|
+
147,
|
|
96
|
+
148,
|
|
97
|
+
157,
|
|
98
|
+
154,
|
|
99
|
+
39,
|
|
100
|
+
32,
|
|
101
|
+
41,
|
|
102
|
+
46,
|
|
103
|
+
59,
|
|
104
|
+
60,
|
|
105
|
+
53,
|
|
106
|
+
50,
|
|
107
|
+
31,
|
|
108
|
+
24,
|
|
109
|
+
17,
|
|
110
|
+
22,
|
|
111
|
+
3,
|
|
112
|
+
4,
|
|
113
|
+
13,
|
|
114
|
+
10,
|
|
115
|
+
87,
|
|
116
|
+
80,
|
|
117
|
+
89,
|
|
118
|
+
94,
|
|
119
|
+
75,
|
|
120
|
+
76,
|
|
121
|
+
69,
|
|
122
|
+
66,
|
|
123
|
+
111,
|
|
124
|
+
104,
|
|
125
|
+
97,
|
|
126
|
+
102,
|
|
127
|
+
115,
|
|
128
|
+
116,
|
|
129
|
+
125,
|
|
130
|
+
122,
|
|
131
|
+
137,
|
|
132
|
+
142,
|
|
133
|
+
135,
|
|
134
|
+
128,
|
|
135
|
+
149,
|
|
136
|
+
146,
|
|
137
|
+
155,
|
|
138
|
+
156,
|
|
139
|
+
177,
|
|
140
|
+
182,
|
|
141
|
+
191,
|
|
142
|
+
184,
|
|
143
|
+
173,
|
|
144
|
+
170,
|
|
145
|
+
163,
|
|
146
|
+
164,
|
|
147
|
+
249,
|
|
148
|
+
254,
|
|
149
|
+
247,
|
|
150
|
+
240,
|
|
151
|
+
229,
|
|
152
|
+
226,
|
|
153
|
+
235,
|
|
154
|
+
236,
|
|
155
|
+
193,
|
|
156
|
+
198,
|
|
157
|
+
207,
|
|
158
|
+
200,
|
|
159
|
+
221,
|
|
160
|
+
218,
|
|
161
|
+
211,
|
|
162
|
+
212,
|
|
163
|
+
105,
|
|
164
|
+
110,
|
|
165
|
+
103,
|
|
166
|
+
96,
|
|
167
|
+
117,
|
|
168
|
+
114,
|
|
169
|
+
123,
|
|
170
|
+
124,
|
|
171
|
+
81,
|
|
172
|
+
86,
|
|
173
|
+
95,
|
|
174
|
+
88,
|
|
175
|
+
77,
|
|
176
|
+
74,
|
|
177
|
+
67,
|
|
178
|
+
68,
|
|
179
|
+
25,
|
|
180
|
+
30,
|
|
181
|
+
23,
|
|
182
|
+
16,
|
|
183
|
+
5,
|
|
184
|
+
2,
|
|
185
|
+
11,
|
|
186
|
+
12,
|
|
187
|
+
33,
|
|
188
|
+
38,
|
|
189
|
+
47,
|
|
190
|
+
40,
|
|
191
|
+
61,
|
|
192
|
+
58,
|
|
193
|
+
51,
|
|
194
|
+
52,
|
|
195
|
+
78,
|
|
196
|
+
73,
|
|
197
|
+
64,
|
|
198
|
+
71,
|
|
199
|
+
82,
|
|
200
|
+
85,
|
|
201
|
+
92,
|
|
202
|
+
91,
|
|
203
|
+
118,
|
|
204
|
+
113,
|
|
205
|
+
120,
|
|
206
|
+
127,
|
|
207
|
+
106,
|
|
208
|
+
109,
|
|
209
|
+
100,
|
|
210
|
+
99,
|
|
211
|
+
62,
|
|
212
|
+
57,
|
|
213
|
+
48,
|
|
214
|
+
55,
|
|
215
|
+
34,
|
|
216
|
+
37,
|
|
217
|
+
44,
|
|
218
|
+
43,
|
|
219
|
+
6,
|
|
220
|
+
1,
|
|
221
|
+
8,
|
|
222
|
+
15,
|
|
223
|
+
26,
|
|
224
|
+
29,
|
|
225
|
+
20,
|
|
226
|
+
19,
|
|
227
|
+
174,
|
|
228
|
+
169,
|
|
229
|
+
160,
|
|
230
|
+
167,
|
|
231
|
+
178,
|
|
232
|
+
181,
|
|
233
|
+
188,
|
|
234
|
+
187,
|
|
235
|
+
150,
|
|
236
|
+
145,
|
|
237
|
+
152,
|
|
238
|
+
159,
|
|
239
|
+
138,
|
|
240
|
+
141,
|
|
241
|
+
132,
|
|
242
|
+
131,
|
|
243
|
+
222,
|
|
244
|
+
217,
|
|
245
|
+
208,
|
|
246
|
+
215,
|
|
247
|
+
194,
|
|
248
|
+
197,
|
|
249
|
+
204,
|
|
250
|
+
203,
|
|
251
|
+
230,
|
|
252
|
+
225,
|
|
253
|
+
232,
|
|
254
|
+
239,
|
|
255
|
+
250,
|
|
256
|
+
253,
|
|
257
|
+
244,
|
|
258
|
+
243
|
|
259
|
+
];
|
|
260
|
+
function crc8(current, previous = 0) {
|
|
261
|
+
let crc = ~~previous;
|
|
262
|
+
for (let index = 0; index < current.length; index++) crc = TABLE[(crc ^ current[index]) & 255] & 255;
|
|
263
|
+
return crc;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
//#endregion
|
|
267
|
+
export { crc8 };
|
|
268
|
+
//# sourceMappingURL=crc8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc8.mjs","names":[],"sources":["../../src/lib/crc8.ts"],"sourcesContent":["// This is a partial reimplementation of CRC-8 (node-crc) in Deno: https://github.com/alexgorbatchev/node-crc\n\nlet TABLE: Array<number> | Int32Array = [\n 0x00,\n 0x07,\n 0x0e,\n 0x09,\n 0x1c,\n 0x1b,\n 0x12,\n 0x15,\n 0x38,\n 0x3f,\n 0x36,\n 0x31,\n 0x24,\n 0x23,\n 0x2a,\n 0x2d,\n 0x70,\n 0x77,\n 0x7e,\n 0x79,\n 0x6c,\n 0x6b,\n 0x62,\n 0x65,\n 0x48,\n 0x4f,\n 0x46,\n 0x41,\n 0x54,\n 0x53,\n 0x5a,\n 0x5d,\n 0xe0,\n 0xe7,\n 0xee,\n 0xe9,\n 0xfc,\n 0xfb,\n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\n 0x4a,\n 0x43,\n 0x44,\n 0x19,\n 0x1e,\n 0x17,\n 0x10,\n 0x05,\n 0x02,\n 0x0b,\n 0x0c,\n 0x21,\n 0x26,\n 0x2f,\n 0x28,\n 0x3d,\n 0x3a,\n 0x33,\n 0x34,\n 0x4e,\n 0x49,\n 0x40,\n 0x47,\n 0x52,\n 0x55,\n 0x5c,\n 0x5b,\n 0x76,\n 0x71,\n 0x78,\n 0x7f,\n 0x6a,\n 0x6d,\n 0x64,\n 0x63,\n 0x3e,\n 0x39,\n 0x30,\n 0x37,\n 0x22,\n 0x25,\n 0x2c,\n 0x2b,\n 0x06,\n 0x01,\n 0x08,\n 0x0f,\n 0x1a,\n 0x1d,\n 0x14,\n 0x13,\n 0xae,\n 0xa9,\n 0xa0,\n 0xa7,\n 0xb2,\n 0xb5,\n 0xbc,\n 0xbb,\n 0x96,\n 0x91,\n 0x98,\n 0x9f,\n 0x8a,\n 0x8d,\n 0x84,\n 0x83,\n 0xde,\n 0xd9,\n 0xd0,\n 0xd7,\n 0xc2,\n 0xc5,\n 0xcc,\n 0xcb,\n 0xe6,\n 0xe1,\n 0xe8,\n 0xef,\n 0xfa,\n 0xfd,\n 0xf4,\n 0xf3,\n]\n\nexport function crc8(current: Uint8Array, previous = 0): number {\n\n let crc = ~~previous\n\n for (let index = 0; index < current.length; index++) {\n\n crc = TABLE[(crc ^ current[index]!) & 0xff]! & 0xff\n }\n\n return crc\n}\n"],"mappings":";AAEA,IAAI,QAAoC;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,KAAK,SAAqB,WAAW,GAAW;CAE9D,IAAI,MAAM,CAAC,CAAC;AAEZ,MAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,QAE1C,OAAM,OAAO,MAAM,QAAQ,UAAW,OAAS;AAGjD,QAAO"}
|
package/dist/lib/hex.cjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/lib/hex.ts
|
|
4
|
+
const byteaToHex = (bytea) => bytea.startsWith("\\x") ? bytea.substring(2) : bytea;
|
|
5
|
+
const hexToBytea = (hex) => hex.startsWith("\\x") ? hex : "\\x" + hex;
|
|
6
|
+
const prefix0x = (hex) => hex.startsWith("0x") ? hex : "0x" + hex;
|
|
7
|
+
const encodeHex = (str) => Buffer.from(str).toString("hex");
|
|
8
|
+
const toHexString = (arr) => arr ? Buffer.from(arr).toString("hex") : "";
|
|
9
|
+
const toB64String = (arr) => Buffer.from(arr).toString("base64");
|
|
10
|
+
const toBuffer = (hex) => Buffer.from(toHexBuffer(hex));
|
|
11
|
+
const toHexBuffer = (hex) => Buffer.from(byteaToHex(hex), "hex");
|
|
12
|
+
const toB64Buffer = (str) => Buffer.from(str, "base64");
|
|
13
|
+
const toBufferFromArray = (arr) => Buffer.from(arr);
|
|
14
|
+
const toHexArray = (hex) => Uint8Array.from(toHexBuffer(hex));
|
|
15
|
+
const toB64Array = (str) => Uint8Array.from(toB64Buffer(str));
|
|
16
|
+
const toStringArray = (str) => Uint8Array.from(toBuffer(str));
|
|
17
|
+
const hexToDataView = (hex) => new DataView(toHexArray(hex).buffer);
|
|
18
|
+
const dataViewToArray = (dv) => new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength);
|
|
19
|
+
const decodeHex = (str) => {
|
|
20
|
+
const decoded = toHexBuffer(str).toString();
|
|
21
|
+
return !isASCII(decoded) || hasUnicode(decoded) ? prefix0x(str) : decoded;
|
|
22
|
+
};
|
|
23
|
+
const isASCII = (str, ext = true) => (ext ? /^[\x00-\xFF]*$/ : /^[\x00-\x7F]*$/).test(str);
|
|
24
|
+
const isHexString = (str) => str.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(str);
|
|
25
|
+
const isTxHash = (str) => str.length === 64 && isHexString(str);
|
|
26
|
+
const hasUnicode = (str) => (JSON.stringify(str).match(/\\u[\dA-F]{4}/gi)?.length ?? 0) > 0;
|
|
27
|
+
const uint8ArrayToUtf8String = (array) => {
|
|
28
|
+
var out, i, len, c;
|
|
29
|
+
var char2, char3;
|
|
30
|
+
out = "";
|
|
31
|
+
len = array.length;
|
|
32
|
+
i = 0;
|
|
33
|
+
while (i < len) {
|
|
34
|
+
c = array[i++];
|
|
35
|
+
switch (c >> 4) {
|
|
36
|
+
case 0:
|
|
37
|
+
case 1:
|
|
38
|
+
case 2:
|
|
39
|
+
case 3:
|
|
40
|
+
case 4:
|
|
41
|
+
case 5:
|
|
42
|
+
case 6:
|
|
43
|
+
case 7:
|
|
44
|
+
out += String.fromCharCode(c);
|
|
45
|
+
break;
|
|
46
|
+
case 12:
|
|
47
|
+
case 13:
|
|
48
|
+
char2 = array[i++];
|
|
49
|
+
out += String.fromCharCode((c & 31) << 6 | char2 & 63);
|
|
50
|
+
break;
|
|
51
|
+
case 14:
|
|
52
|
+
char2 = array[i++];
|
|
53
|
+
char3 = array[i++];
|
|
54
|
+
out += String.fromCharCode((c & 15) << 12 | (char2 & 63) << 6 | (char3 & 63) << 0);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
};
|
|
60
|
+
const isSameArray = (a1, a2) => {
|
|
61
|
+
return a1.length === a2.length && a1.every((v, i) => v === a2[i]);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.byteaToHex = byteaToHex;
|
|
66
|
+
exports.dataViewToArray = dataViewToArray;
|
|
67
|
+
exports.decodeHex = decodeHex;
|
|
68
|
+
exports.encodeHex = encodeHex;
|
|
69
|
+
exports.hasUnicode = hasUnicode;
|
|
70
|
+
exports.hexToBytea = hexToBytea;
|
|
71
|
+
exports.hexToDataView = hexToDataView;
|
|
72
|
+
exports.isASCII = isASCII;
|
|
73
|
+
exports.isHexString = isHexString;
|
|
74
|
+
exports.isSameArray = isSameArray;
|
|
75
|
+
exports.isTxHash = isTxHash;
|
|
76
|
+
exports.prefix0x = prefix0x;
|
|
77
|
+
exports.toB64Array = toB64Array;
|
|
78
|
+
exports.toB64Buffer = toB64Buffer;
|
|
79
|
+
exports.toB64String = toB64String;
|
|
80
|
+
exports.toBuffer = toBuffer;
|
|
81
|
+
exports.toBufferFromArray = toBufferFromArray;
|
|
82
|
+
exports.toHexArray = toHexArray;
|
|
83
|
+
exports.toHexBuffer = toHexBuffer;
|
|
84
|
+
exports.toHexString = toHexString;
|
|
85
|
+
exports.toStringArray = toStringArray;
|
|
86
|
+
exports.uint8ArrayToUtf8String = uint8ArrayToUtf8String;
|
|
87
|
+
//# sourceMappingURL=hex.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.cjs","names":[],"sources":["../../src/lib/hex.ts"],"sourcesContent":["export const byteaToHex = (bytea: string): string => bytea.startsWith('\\\\x') ? bytea.substring(2) : bytea\nexport const hexToBytea = ( hex: string): string => hex.startsWith('\\\\x') ? hex : ( '\\\\x' + hex )\nexport const prefix0x = ( hex: string): string => hex.startsWith( '0x') ? hex : ( '0x' + hex )\n\nexport const encodeHex = ( str: string): string => Buffer.from(str).toString('hex')\nexport const toHexString = ( arr: Uint8Array | null): string => arr ? Buffer.from(arr).toString('hex') : ''\nexport const toB64String = ( arr: Uint8Array): string => Buffer.from(arr).toString('base64')\nexport const toBuffer = ( hex: string): Buffer => Buffer.from(toHexBuffer(hex))\nexport const toHexBuffer = ( hex: string): Buffer => Buffer.from(byteaToHex(hex), 'hex')\nexport const toB64Buffer = ( str: string): Buffer => Buffer.from(str, 'base64')\nexport const toBufferFromArray= ( arr: Uint8Array): Buffer => Buffer.from(arr)\nexport const toHexArray = ( hex: string): Uint8Array => Uint8Array.from(toHexBuffer(hex))\nexport const toB64Array = ( str: string): Uint8Array => Uint8Array.from(toB64Buffer(str))\nexport const toStringArray = ( str: string): Uint8Array => Uint8Array.from(toBuffer(str))\n\nexport const hexToDataView = ( hex: string): DataView => new DataView(toHexArray(hex).buffer)\nexport const dataViewToArray = ( dv: DataView): Uint8Array => new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength)\n\nexport const decodeHex = ( str: string): string => {\n\n const decoded = toHexBuffer(str).toString()\n\n return !isASCII(decoded) || hasUnicode(decoded) ? prefix0x(str) : decoded\n}\nexport const isASCII = ( str: string, ext: boolean = true): boolean => (ext ? /^[\\x00-\\xFF]*$/ : /^[\\x00-\\x7F]*$/).test(str)\nexport const isHexString = ( str: string): boolean => str.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(str)\nexport const isTxHash = ( str: string): boolean => str.length === 64 && isHexString(str)\nexport const hasUnicode = ( str: string): boolean => (JSON.stringify(str).match(/\\\\u[\\dA-F]{4}/gi)?.length ?? 0) > 0\n\n\n// http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt\n\n/* utf.js - UTF-8 <=> UTF-16 convertion\n *\n * Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>\n * Version: 1.0\n * LastModified: Dec 25 1999\n * This library is free. You can redistribute it and/or modify it.\n */\n\nexport const uint8ArrayToUtf8String = (array: Uint8Array): string => {\n var out, i, len, c;\n var char2, char3;\n\n out = \"\";\n len = array.length;\n i = 0;\n while (i < len) {\n c = array[i++]!;\n switch (c >> 4)\n {\n case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:\n // 0xxxxxxx\n out += String.fromCharCode(c);\n break;\n case 12: case 13:\n // 110x xxxx 10xx xxxx\n char2 = array[i++]!;\n out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));\n break;\n case 14:\n // 1110 xxxx 10xx xxxx 10xx xxxx\n char2 = array[i++]!;\n char3 = array[i++]!;\n out += String.fromCharCode(((c & 0x0F) << 12) |\n ((char2 & 0x3F) << 6) |\n ((char3 & 0x3F) << 0));\n break;\n }\n }\n\n return out;\n}\n\nexport const isSameArray = (a1: number[], a2: number[]) => {\n return a1.length === a2.length && a1.every((v, i) => v === a2[i])\n}\n"],"mappings":";;;AAAA,MAAa,cAAoB,UAA2D,MAAM,WAAW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WAAW,MAAM,YAAY,IAAI;AAC1H,MAAa,cAAsB,SAAuD,KAAK,UAAU,IAAI,CAAC,MAAM,kBAAkB,EAAE,UAAU,KAAK;AAavJ,MAAa,0BAA0B,UAA8B;CACnE,IAAI,KAAK,GAAG,KAAK;CACjB,IAAI,OAAO;AAEX,OAAM;AACN,OAAM,MAAM;AACZ,KAAI;AACJ,QAAO,IAAI,KAAK;AACd,MAAI,MAAM;AACV,UAAQ,KAAK,GAAb;GAEE,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;AAE7D,WAAO,OAAO,aAAa,EAAE;AAC7B;GACA,KAAK;GAAI,KAAK;AAEd,YAAQ,MAAM;AACd,WAAO,OAAO,cAAe,IAAI,OAAS,IAAM,QAAQ,GAAM;AAC9D;GACA,KAAK;AAEH,YAAQ,MAAM;AACd,YAAQ,MAAM;AACd,WAAO,OAAO,cAAe,IAAI,OAAS,MACtC,QAAQ,OAAS,KACjB,QAAQ,OAAS,EAAG;AACxB;;;AAIN,QAAO;;AAGT,MAAa,eAAe,IAAc,OAAiB;AACzD,QAAO,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,MAAM,GAAG,GAAG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/lib/hex.d.ts
|
|
2
|
+
declare const byteaToHex: (bytea: string) => string;
|
|
3
|
+
declare const hexToBytea: (hex: string) => string;
|
|
4
|
+
declare const prefix0x: (hex: string) => string;
|
|
5
|
+
declare const encodeHex: (str: string) => string;
|
|
6
|
+
declare const toHexString: (arr: Uint8Array | null) => string;
|
|
7
|
+
declare const toB64String: (arr: Uint8Array) => string;
|
|
8
|
+
declare const toBuffer: (hex: string) => Buffer;
|
|
9
|
+
declare const toHexBuffer: (hex: string) => Buffer;
|
|
10
|
+
declare const toB64Buffer: (str: string) => Buffer;
|
|
11
|
+
declare const toBufferFromArray: (arr: Uint8Array) => Buffer;
|
|
12
|
+
declare const toHexArray: (hex: string) => Uint8Array;
|
|
13
|
+
declare const toB64Array: (str: string) => Uint8Array;
|
|
14
|
+
declare const toStringArray: (str: string) => Uint8Array;
|
|
15
|
+
declare const hexToDataView: (hex: string) => DataView;
|
|
16
|
+
declare const dataViewToArray: (dv: DataView) => Uint8Array;
|
|
17
|
+
declare const decodeHex: (str: string) => string;
|
|
18
|
+
declare const isASCII: (str: string, ext?: boolean) => boolean;
|
|
19
|
+
declare const isHexString: (str: string) => boolean;
|
|
20
|
+
declare const isTxHash: (str: string) => boolean;
|
|
21
|
+
declare const hasUnicode: (str: string) => boolean;
|
|
22
|
+
declare const uint8ArrayToUtf8String: (array: Uint8Array) => string;
|
|
23
|
+
declare const isSameArray: (a1: number[], a2: number[]) => boolean;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { byteaToHex, dataViewToArray, decodeHex, encodeHex, hasUnicode, hexToBytea, hexToDataView, isASCII, isHexString, isSameArray, isTxHash, prefix0x, toB64Array, toB64Buffer, toB64String, toBuffer, toBufferFromArray, toHexArray, toHexBuffer, toHexString, toStringArray, uint8ArrayToUtf8String };
|
|
26
|
+
//# sourceMappingURL=hex.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.d.cts","names":[],"sources":["../../src/lib/hex.ts"],"mappings":";cAAa,UAAA,GAAoB,KAAA;AAAA,cACpB,UAAA,GAAsB,GAAA;AAAA,cACtB,QAAA,GAAsB,GAAA;AAAA,cAEtB,SAAA,GAAsB,GAAA;AAAA,cACtB,WAAA,GAAsB,GAAA,EAAK,UAAA;AAAA,cAC3B,WAAA,GAAsB,GAAA,EAAK,UAAA;AAAA,cAC3B,QAAA,GAAsB,GAAA,aAAmC,MAAA;AAAA,cACzD,WAAA,GAAsB,GAAA,aAAmC,MAAA;AAAA,cACzD,WAAA,GAAsB,GAAA,aAAmC,MAAA;AAAA,cACzD,iBAAA,GAAsB,GAAA,EAAK,UAAA,KAA8B,MAAA;AAAA,cACzD,UAAA,GAAsB,GAAA,aAAmC,UAAA;AAAA,cACzD,UAAA,GAAsB,GAAA,aAAmC,UAAA;AAAA,cACzD,aAAA,GAAsB,GAAA,aAAmC,UAAA;AAAA,cAEzD,aAAA,GAAsB,GAAA,aAAmC,QAAA;AAAA,cACzD,eAAA,GAAuB,EAAA,EAAI,QAAA,KAA8B,UAAA;AAAA,cAEzD,SAAA,GAAsB,GAAA;AAAA,cAMtB,OAAA,GAAsB,GAAA,UAAa,GAAA;AAAA,cACnC,WAAA,GAAsB,GAAA;AAAA,cACtB,QAAA,GAAsB,GAAA;AAAA,cACtB,UAAA,GAAsB,GAAA;AAAA,cAatB,sBAAA,GAA0B,KAAA,EAAO,UAAA;AAAA,cAkCjC,WAAA,GAAe,EAAA,YAAc,EAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/lib/hex.d.ts
|
|
2
|
+
declare const byteaToHex: (bytea: string) => string;
|
|
3
|
+
declare const hexToBytea: (hex: string) => string;
|
|
4
|
+
declare const prefix0x: (hex: string) => string;
|
|
5
|
+
declare const encodeHex: (str: string) => string;
|
|
6
|
+
declare const toHexString: (arr: Uint8Array | null) => string;
|
|
7
|
+
declare const toB64String: (arr: Uint8Array) => string;
|
|
8
|
+
declare const toBuffer: (hex: string) => Buffer;
|
|
9
|
+
declare const toHexBuffer: (hex: string) => Buffer;
|
|
10
|
+
declare const toB64Buffer: (str: string) => Buffer;
|
|
11
|
+
declare const toBufferFromArray: (arr: Uint8Array) => Buffer;
|
|
12
|
+
declare const toHexArray: (hex: string) => Uint8Array;
|
|
13
|
+
declare const toB64Array: (str: string) => Uint8Array;
|
|
14
|
+
declare const toStringArray: (str: string) => Uint8Array;
|
|
15
|
+
declare const hexToDataView: (hex: string) => DataView;
|
|
16
|
+
declare const dataViewToArray: (dv: DataView) => Uint8Array;
|
|
17
|
+
declare const decodeHex: (str: string) => string;
|
|
18
|
+
declare const isASCII: (str: string, ext?: boolean) => boolean;
|
|
19
|
+
declare const isHexString: (str: string) => boolean;
|
|
20
|
+
declare const isTxHash: (str: string) => boolean;
|
|
21
|
+
declare const hasUnicode: (str: string) => boolean;
|
|
22
|
+
declare const uint8ArrayToUtf8String: (array: Uint8Array) => string;
|
|
23
|
+
declare const isSameArray: (a1: number[], a2: number[]) => boolean;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { byteaToHex, dataViewToArray, decodeHex, encodeHex, hasUnicode, hexToBytea, hexToDataView, isASCII, isHexString, isSameArray, isTxHash, prefix0x, toB64Array, toB64Buffer, toB64String, toBuffer, toBufferFromArray, toHexArray, toHexBuffer, toHexString, toStringArray, uint8ArrayToUtf8String };
|
|
26
|
+
//# sourceMappingURL=hex.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.d.mts","names":[],"sources":["../../src/lib/hex.ts"],"mappings":";cAAa,UAAA,GAAoB,KAAA;AAAA,cACpB,UAAA,GAAsB,GAAA;AAAA,cACtB,QAAA,GAAsB,GAAA;AAAA,cAEtB,SAAA,GAAsB,GAAA;AAAA,cACtB,WAAA,GAAsB,GAAA,EAAK,UAAA;AAAA,cAC3B,WAAA,GAAsB,GAAA,EAAK,UAAA;AAAA,cAC3B,QAAA,GAAsB,GAAA,aAAmC,MAAA;AAAA,cACzD,WAAA,GAAsB,GAAA,aAAmC,MAAA;AAAA,cACzD,WAAA,GAAsB,GAAA,aAAmC,MAAA;AAAA,cACzD,iBAAA,GAAsB,GAAA,EAAK,UAAA,KAA8B,MAAA;AAAA,cACzD,UAAA,GAAsB,GAAA,aAAmC,UAAA;AAAA,cACzD,UAAA,GAAsB,GAAA,aAAmC,UAAA;AAAA,cACzD,aAAA,GAAsB,GAAA,aAAmC,UAAA;AAAA,cAEzD,aAAA,GAAsB,GAAA,aAAmC,QAAA;AAAA,cACzD,eAAA,GAAuB,EAAA,EAAI,QAAA,KAA8B,UAAA;AAAA,cAEzD,SAAA,GAAsB,GAAA;AAAA,cAMtB,OAAA,GAAsB,GAAA,UAAa,GAAA;AAAA,cACnC,WAAA,GAAsB,GAAA;AAAA,cACtB,QAAA,GAAsB,GAAA;AAAA,cACtB,UAAA,GAAsB,GAAA;AAAA,cAatB,sBAAA,GAA0B,KAAA,EAAO,UAAA;AAAA,cAkCjC,WAAA,GAAe,EAAA,YAAc,EAAA"}
|
package/dist/lib/hex.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/lib/hex.ts
|
|
2
|
+
const byteaToHex = (bytea) => bytea.startsWith("\\x") ? bytea.substring(2) : bytea;
|
|
3
|
+
const hexToBytea = (hex) => hex.startsWith("\\x") ? hex : "\\x" + hex;
|
|
4
|
+
const prefix0x = (hex) => hex.startsWith("0x") ? hex : "0x" + hex;
|
|
5
|
+
const encodeHex = (str) => Buffer.from(str).toString("hex");
|
|
6
|
+
const toHexString = (arr) => arr ? Buffer.from(arr).toString("hex") : "";
|
|
7
|
+
const toB64String = (arr) => Buffer.from(arr).toString("base64");
|
|
8
|
+
const toBuffer = (hex) => Buffer.from(toHexBuffer(hex));
|
|
9
|
+
const toHexBuffer = (hex) => Buffer.from(byteaToHex(hex), "hex");
|
|
10
|
+
const toB64Buffer = (str) => Buffer.from(str, "base64");
|
|
11
|
+
const toBufferFromArray = (arr) => Buffer.from(arr);
|
|
12
|
+
const toHexArray = (hex) => Uint8Array.from(toHexBuffer(hex));
|
|
13
|
+
const toB64Array = (str) => Uint8Array.from(toB64Buffer(str));
|
|
14
|
+
const toStringArray = (str) => Uint8Array.from(toBuffer(str));
|
|
15
|
+
const hexToDataView = (hex) => new DataView(toHexArray(hex).buffer);
|
|
16
|
+
const dataViewToArray = (dv) => new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength);
|
|
17
|
+
const decodeHex = (str) => {
|
|
18
|
+
const decoded = toHexBuffer(str).toString();
|
|
19
|
+
return !isASCII(decoded) || hasUnicode(decoded) ? prefix0x(str) : decoded;
|
|
20
|
+
};
|
|
21
|
+
const isASCII = (str, ext = true) => (ext ? /^[\x00-\xFF]*$/ : /^[\x00-\x7F]*$/).test(str);
|
|
22
|
+
const isHexString = (str) => str.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(str);
|
|
23
|
+
const isTxHash = (str) => str.length === 64 && isHexString(str);
|
|
24
|
+
const hasUnicode = (str) => (JSON.stringify(str).match(/\\u[\dA-F]{4}/gi)?.length ?? 0) > 0;
|
|
25
|
+
const uint8ArrayToUtf8String = (array) => {
|
|
26
|
+
var out, i, len, c;
|
|
27
|
+
var char2, char3;
|
|
28
|
+
out = "";
|
|
29
|
+
len = array.length;
|
|
30
|
+
i = 0;
|
|
31
|
+
while (i < len) {
|
|
32
|
+
c = array[i++];
|
|
33
|
+
switch (c >> 4) {
|
|
34
|
+
case 0:
|
|
35
|
+
case 1:
|
|
36
|
+
case 2:
|
|
37
|
+
case 3:
|
|
38
|
+
case 4:
|
|
39
|
+
case 5:
|
|
40
|
+
case 6:
|
|
41
|
+
case 7:
|
|
42
|
+
out += String.fromCharCode(c);
|
|
43
|
+
break;
|
|
44
|
+
case 12:
|
|
45
|
+
case 13:
|
|
46
|
+
char2 = array[i++];
|
|
47
|
+
out += String.fromCharCode((c & 31) << 6 | char2 & 63);
|
|
48
|
+
break;
|
|
49
|
+
case 14:
|
|
50
|
+
char2 = array[i++];
|
|
51
|
+
char3 = array[i++];
|
|
52
|
+
out += String.fromCharCode((c & 15) << 12 | (char2 & 63) << 6 | (char3 & 63) << 0);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
};
|
|
58
|
+
const isSameArray = (a1, a2) => {
|
|
59
|
+
return a1.length === a2.length && a1.every((v, i) => v === a2[i]);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { byteaToHex, dataViewToArray, decodeHex, encodeHex, hasUnicode, hexToBytea, hexToDataView, isASCII, isHexString, isSameArray, isTxHash, prefix0x, toB64Array, toB64Buffer, toB64String, toBuffer, toBufferFromArray, toHexArray, toHexBuffer, toHexString, toStringArray, uint8ArrayToUtf8String };
|
|
64
|
+
//# sourceMappingURL=hex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.mjs","names":[],"sources":["../../src/lib/hex.ts"],"sourcesContent":["export const byteaToHex = (bytea: string): string => bytea.startsWith('\\\\x') ? bytea.substring(2) : bytea\nexport const hexToBytea = ( hex: string): string => hex.startsWith('\\\\x') ? hex : ( '\\\\x' + hex )\nexport const prefix0x = ( hex: string): string => hex.startsWith( '0x') ? hex : ( '0x' + hex )\n\nexport const encodeHex = ( str: string): string => Buffer.from(str).toString('hex')\nexport const toHexString = ( arr: Uint8Array | null): string => arr ? Buffer.from(arr).toString('hex') : ''\nexport const toB64String = ( arr: Uint8Array): string => Buffer.from(arr).toString('base64')\nexport const toBuffer = ( hex: string): Buffer => Buffer.from(toHexBuffer(hex))\nexport const toHexBuffer = ( hex: string): Buffer => Buffer.from(byteaToHex(hex), 'hex')\nexport const toB64Buffer = ( str: string): Buffer => Buffer.from(str, 'base64')\nexport const toBufferFromArray= ( arr: Uint8Array): Buffer => Buffer.from(arr)\nexport const toHexArray = ( hex: string): Uint8Array => Uint8Array.from(toHexBuffer(hex))\nexport const toB64Array = ( str: string): Uint8Array => Uint8Array.from(toB64Buffer(str))\nexport const toStringArray = ( str: string): Uint8Array => Uint8Array.from(toBuffer(str))\n\nexport const hexToDataView = ( hex: string): DataView => new DataView(toHexArray(hex).buffer)\nexport const dataViewToArray = ( dv: DataView): Uint8Array => new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength)\n\nexport const decodeHex = ( str: string): string => {\n\n const decoded = toHexBuffer(str).toString()\n\n return !isASCII(decoded) || hasUnicode(decoded) ? prefix0x(str) : decoded\n}\nexport const isASCII = ( str: string, ext: boolean = true): boolean => (ext ? /^[\\x00-\\xFF]*$/ : /^[\\x00-\\x7F]*$/).test(str)\nexport const isHexString = ( str: string): boolean => str.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(str)\nexport const isTxHash = ( str: string): boolean => str.length === 64 && isHexString(str)\nexport const hasUnicode = ( str: string): boolean => (JSON.stringify(str).match(/\\\\u[\\dA-F]{4}/gi)?.length ?? 0) > 0\n\n\n// http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt\n\n/* utf.js - UTF-8 <=> UTF-16 convertion\n *\n * Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>\n * Version: 1.0\n * LastModified: Dec 25 1999\n * This library is free. You can redistribute it and/or modify it.\n */\n\nexport const uint8ArrayToUtf8String = (array: Uint8Array): string => {\n var out, i, len, c;\n var char2, char3;\n\n out = \"\";\n len = array.length;\n i = 0;\n while (i < len) {\n c = array[i++]!;\n switch (c >> 4)\n {\n case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:\n // 0xxxxxxx\n out += String.fromCharCode(c);\n break;\n case 12: case 13:\n // 110x xxxx 10xx xxxx\n char2 = array[i++]!;\n out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));\n break;\n case 14:\n // 1110 xxxx 10xx xxxx 10xx xxxx\n char2 = array[i++]!;\n char3 = array[i++]!;\n out += String.fromCharCode(((c & 0x0F) << 12) |\n ((char2 & 0x3F) << 6) |\n ((char3 & 0x3F) << 0));\n break;\n }\n }\n\n return out;\n}\n\nexport const isSameArray = (a1: number[], a2: number[]) => {\n return a1.length === a2.length && a1.every((v, i) => v === a2[i])\n}\n"],"mappings":";AAAA,MAAa,cAAoB,UAA2D,MAAM,WAAW,MAAM,GAAG,MAAM,UAAU,EAAE,GAAG;AAC3I,MAAa,cAAsB,QAA2D,IAAI,WAAW,MAAM,GAAG,MAAuB,QAAQ;AACrJ,MAAa,YAAsB,QAA2D,IAAI,WAAY,KAAK,GAAG,MAAwB,OAAO;AAErJ,MAAa,aAAsB,QAAwD,OAAO,KAAK,IAAI,CAAC,SAAS,MAAM;AAC3H,MAAa,eAAsB,QAAk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AI,MAAM;AACV,UAAQ,KAAK,GAAb;GAEE,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;GAAG,KAAK;AAE7D,WAAO,OAAO,aAAa,EAAE;AAC7B;GACA,KAAK;GAAI,KAAK;AAEd,YAAQ,MAAM;AACd,WAAO,OAAO,cAAe,IAAI,OAAS,IAAM,QAAQ,GAAM;AAC9D;GACA,KAAK;AAEH,YAAQ,MAAM;AACd,YAAQ,MAAM;AACd,WAAO,OAAO,cAAe,IAAI,OAAS,MACtC,QAAQ,OAAS,KACjB,QAAQ,OAAS,EAAG;AACxB;;;AAIN,QAAO;;AAGT,MAAa,eAAe,IAAc,OAAiB;AACzD,QAAO,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,MAAM,GAAG,GAAG"}
|
package/dist/lib/id.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/lib/id.ts
|
|
4
|
+
const getRandomId = () => Math.floor(Math.random() * 999999) + "-" + Math.floor(Math.random() * 999999) + "-" + Math.floor(Math.random() * 999999);
|
|
5
|
+
const getShortId = () => Math.floor(Math.random() * 9999) + "-" + Math.floor(Math.random() * 9999);
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.getRandomId = getRandomId;
|
|
9
|
+
exports.getShortId = getShortId;
|
|
10
|
+
//# sourceMappingURL=id.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.cjs","names":[],"sources":["../../src/lib/id.ts"],"sourcesContent":["export const getRandomId = () => ( Math.floor(Math.random() * 999999) + '-' + Math.floor(Math.random() * 999999) + '-' + Math.floor(Math.random() * 999999) )\nexport const getShortId = () => ( Math.floor(Math.random() * 9999) + '-' + Math.floor(Math.random() * 9999) )\n"],"mappings":";;;AAAA,MAAa,oBAA2B,KAAK,MAAM,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,OAAO;AAChK,MAAa,mBAA2B,KAAK,MAAM,KAAK,QAAQ,GAAG,KAAK,GAAK,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.cts","names":[],"sources":["../../src/lib/id.ts"],"mappings":";cAAa,WAAA;AAAA,cACA,UAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.mts","names":[],"sources":["../../src/lib/id.ts"],"mappings":";cAAa,WAAA;AAAA,cACA,UAAA"}
|
package/dist/lib/id.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/lib/id.ts
|
|
2
|
+
const getRandomId = () => Math.floor(Math.random() * 999999) + "-" + Math.floor(Math.random() * 999999) + "-" + Math.floor(Math.random() * 999999);
|
|
3
|
+
const getShortId = () => Math.floor(Math.random() * 9999) + "-" + Math.floor(Math.random() * 9999);
|
|
4
|
+
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getRandomId, getShortId };
|
|
7
|
+
//# sourceMappingURL=id.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.mjs","names":[],"sources":["../../src/lib/id.ts"],"sourcesContent":["export const getRandomId = () => ( Math.floor(Math.random() * 999999) + '-' + Math.floor(Math.random() * 999999) + '-' + Math.floor(Math.random() * 999999) )\nexport const getShortId = () => ( Math.floor(Math.random() * 9999) + '-' + Math.floor(Math.random() * 9999) )\n"],"mappings":";AAAA,MAAa,oBAA2B,KAAK,MAAM,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,OAAO;AAChK,MAAa,mBAA2B,KAAK,MAAM,KAAK,QAAQ,GAAG,KAAK,GAAK,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,KAAK"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_lib_hex = require('./hex.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/lib/json.ts
|
|
5
|
+
const json = (obj) => JSON.parse(JSON.stringify(obj));
|
|
6
|
+
const getErrorMsg = (err) => err?.message ?? (typeof err === "string" ? err : JSON.stringify(err));
|
|
7
|
+
const deepMerge = (target, _objects = [], _options) => {
|
|
8
|
+
const options = { arrayBehaviour: _options?.arrayBehaviour ?? "replace" };
|
|
9
|
+
const objects = _objects.map((object) => object || {});
|
|
10
|
+
const output = target || {};
|
|
11
|
+
for (let i = 0; i < objects.length; i++) {
|
|
12
|
+
const object = objects[i];
|
|
13
|
+
const keys = Object.keys(object);
|
|
14
|
+
for (let k = 0; k < keys.length; k++) {
|
|
15
|
+
const key = keys[k];
|
|
16
|
+
const value = object[key];
|
|
17
|
+
const type = getTypeOf(value);
|
|
18
|
+
const existingValueType = getTypeOf(output[key]);
|
|
19
|
+
if (type === "object") if (existingValueType !== "undefined") output[key] = deepMerge({}, [existingValueType === "object" ? output[key] : {}, quickCloneObject(value)], options);
|
|
20
|
+
else output[key] = quickCloneObject(value);
|
|
21
|
+
else if (type === "array") if (existingValueType === "array") {
|
|
22
|
+
const newValue = quickCloneArray(value);
|
|
23
|
+
output[key] = options.arrayBehaviour === "merge" ? output[key].concat(newValue) : newValue;
|
|
24
|
+
} else output[key] = quickCloneArray(value);
|
|
25
|
+
else output[key] = value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return output;
|
|
29
|
+
};
|
|
30
|
+
const getTypeOf = (input) => {
|
|
31
|
+
if (input === null) return "null";
|
|
32
|
+
else if (typeof input === "undefined") return "undefined";
|
|
33
|
+
else if (typeof input === "object") return Array.isArray(input) ? "array" : "object";
|
|
34
|
+
return typeof input;
|
|
35
|
+
};
|
|
36
|
+
const quickCloneObject = (input) => {
|
|
37
|
+
const output = {};
|
|
38
|
+
for (const key in input) {
|
|
39
|
+
if (!input.hasOwnProperty(key)) continue;
|
|
40
|
+
output[key] = cloneValue(input[key]);
|
|
41
|
+
}
|
|
42
|
+
return output;
|
|
43
|
+
};
|
|
44
|
+
const quickCloneArray = (input) => {
|
|
45
|
+
return input.map(cloneValue);
|
|
46
|
+
};
|
|
47
|
+
const cloneValue = (value) => {
|
|
48
|
+
if (getTypeOf(value) === "object") return quickCloneObject(value);
|
|
49
|
+
else if (getTypeOf(value) === "array") return quickCloneArray(value);
|
|
50
|
+
return value;
|
|
51
|
+
};
|
|
52
|
+
const createJsonFromCborJson = (source, target, index, doDecodeHex = true) => {
|
|
53
|
+
try {
|
|
54
|
+
if ("bytes" in source && !Number.isNaN(index)) target[index] = doDecodeHex ? require_lib_hex.decodeHex(source.bytes) : require_lib_hex.prefix0x(source.bytes);
|
|
55
|
+
else if ("int" in source && !Number.isNaN(index)) target[index] = source.int;
|
|
56
|
+
else if ("string" in source && !Number.isNaN(index)) target[index] = source.string;
|
|
57
|
+
else if (source?.k?.bytes || source?.k?.string || source?.k?.int) {
|
|
58
|
+
const key = source?.k?.bytes ? doDecodeHex ? require_lib_hex.decodeHex(source.k.bytes) : source.k.bytes : source?.k?.string || source?.k?.int.toString();
|
|
59
|
+
const value = source.v;
|
|
60
|
+
if ("bytes" in value) target[key] = doDecodeHex ? require_lib_hex.decodeHex(value.bytes) : require_lib_hex.prefix0x(value.bytes);
|
|
61
|
+
else if ("int" in value) target[key] = value.int;
|
|
62
|
+
else if ("string" in value) target[key] = value.string;
|
|
63
|
+
else if ("list" in value) {
|
|
64
|
+
target[key] = new Array(value.list.length);
|
|
65
|
+
createJsonFromCborJson(value, target[key], index, doDecodeHex);
|
|
66
|
+
} else if ("map" in value) {
|
|
67
|
+
target[key] = {};
|
|
68
|
+
createJsonFromCborJson(value, target[key], index, doDecodeHex);
|
|
69
|
+
}
|
|
70
|
+
} else if ("map" in source) for (let i = 0; i < source.map.length; i++) createJsonFromCborJson(source.map[i], target, index, doDecodeHex);
|
|
71
|
+
else if ("list" in source) for (let i = 0; i < source.list.length; i++) if ("map" in source.list[i]) {
|
|
72
|
+
target[i] = {};
|
|
73
|
+
createJsonFromCborJson(source.list[i], target[i], index, doDecodeHex);
|
|
74
|
+
} else createJsonFromCborJson(source.list[i], target, i, doDecodeHex);
|
|
75
|
+
} catch (e) {}
|
|
76
|
+
};
|
|
77
|
+
const getKeyValue = (input) => {
|
|
78
|
+
if (!input) return null;
|
|
79
|
+
const value = input.match(/"(.*?)":"(.*)"/);
|
|
80
|
+
return value ? {
|
|
81
|
+
key: value[1],
|
|
82
|
+
value: value[2]
|
|
83
|
+
} : null;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
exports.createJsonFromCborJson = createJsonFromCborJson;
|
|
88
|
+
exports.deepMerge = deepMerge;
|
|
89
|
+
exports.getErrorMsg = getErrorMsg;
|
|
90
|
+
exports.getKeyValue = getKeyValue;
|
|
91
|
+
exports.json = json;
|
|
92
|
+
//# sourceMappingURL=json.cjs.map
|