@cbortech/cbor 0.25.10 → 0.26.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.ja.md +86 -27
- package/README.md +87 -28
- package/assets/cbor-cdn-js.png +0 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cdn/index.cjs +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/tokenizer.d.ts +8 -5
- package/dist/extensions/concat.d.ts +5 -0
- package/dist/extensions/ilstrings.d.ts +5 -0
- package/dist/index.cjs +6 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +147 -308
- package/dist/index.js.map +1 -1
- package/dist/{mapEntries-B8riGPMD.js → mapEntries-BdzS6bFp.js} +970 -665
- package/dist/mapEntries-BdzS6bFp.js.map +1 -0
- package/dist/mapEntries-DJtvWpWq.cjs +14 -0
- package/dist/mapEntries-DJtvWpWq.cjs.map +1 -0
- package/dist/{tokenizer-DkLlZ1gc.js → tokenizer-CeuixxXi.js} +20 -19
- package/dist/tokenizer-CeuixxXi.js.map +1 -0
- package/dist/{tokenizer-CVcIyZZa.cjs → tokenizer-EciPlN0n.cjs} +3 -3
- package/dist/tokenizer-EciPlN0n.cjs.map +1 -0
- package/dist/types.d.ts +29 -19
- package/package.json +3 -2
- package/dist/mapEntries-B-INYL6l.cjs +0 -11
- package/dist/mapEntries-B-INYL6l.cjs.map +0 -1
- package/dist/mapEntries-B8riGPMD.js.map +0 -1
- package/dist/tokenizer-CVcIyZZa.cjs.map +0 -1
- package/dist/tokenizer-DkLlZ1gc.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,49 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/utils/strip-comments.ts
|
|
4
|
-
function v(e) {
|
|
5
|
-
let t = "", n = 0;
|
|
6
|
-
for (; n < e.length;) {
|
|
7
|
-
let r = e[n];
|
|
8
|
-
if (r === " " || r === "\n" || r === "\r") {
|
|
9
|
-
n++;
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
if (r === "#") {
|
|
13
|
-
for (; n < e.length && e[n] !== "\n";) n++;
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
if (r === "/") {
|
|
17
|
-
let t = e[n + 1] ?? "";
|
|
18
|
-
if (t === "/") {
|
|
19
|
-
for (; n < e.length && e[n] !== "\n";) n++;
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (t === "*") {
|
|
23
|
-
for (n += 2; n < e.length && !(e[n] === "*" && (e[n + 1] ?? "") === "/");) n++;
|
|
24
|
-
if (n >= e.length) throw SyntaxError("unterminated block comment");
|
|
25
|
-
n += 2;
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
for (n++; n < e.length && e[n] !== "/";) n++;
|
|
29
|
-
if (n >= e.length) throw SyntaxError("unterminated block comment");
|
|
30
|
-
n++;
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
t += r, n++;
|
|
34
|
-
}
|
|
35
|
-
return t;
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
1
|
+
import { o as e } from "./tokenizer-CeuixxXi.js";
|
|
2
|
+
import { A as t, M as n, N as r, O as i, S as a, a as o, c as s, d as c, i as l, j as u, k as d, l as f, n as p, o as m, p as h, r as g, s as _, t as v, u as y } from "./mapEntries-BdzS6bFp.js";
|
|
38
3
|
//#region src/extensions/b32.ts
|
|
39
|
-
var
|
|
40
|
-
function
|
|
4
|
+
var b = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", x = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
5
|
+
function S(e) {
|
|
41
6
|
let t = e.length;
|
|
42
7
|
for (; t > 0 && e.charCodeAt(t - 1) === 61;) t--;
|
|
43
8
|
return e.slice(0, t);
|
|
44
9
|
}
|
|
45
|
-
function
|
|
46
|
-
let r =
|
|
10
|
+
function C(e, t, n) {
|
|
11
|
+
let r = S(e).toUpperCase(), i = r.length % 8;
|
|
47
12
|
if (i === 1 || i === 3 || i === 6) throw SyntaxError(`invalid base32 length: ${r.length} characters`);
|
|
48
13
|
let a = (/* @__PURE__ */ new Uint8Array(128)).fill(255);
|
|
49
14
|
for (let e = 0; e < t.length; e++) a[t.charCodeAt(e)] = e;
|
|
@@ -60,169 +25,43 @@ function S(e, t, n) {
|
|
|
60
25
|
}
|
|
61
26
|
return o;
|
|
62
27
|
}
|
|
63
|
-
var
|
|
28
|
+
var w = {
|
|
64
29
|
appStringPrefixes: ["b32"],
|
|
65
30
|
parseAppString(e, t, n) {
|
|
66
|
-
return new
|
|
31
|
+
return new a(C(o(t), b, n), { ednEncoding: "base32" });
|
|
67
32
|
}
|
|
68
|
-
},
|
|
33
|
+
}, T = {
|
|
69
34
|
appStringPrefixes: ["h32"],
|
|
70
35
|
parseAppString(e, t, n) {
|
|
71
|
-
return new
|
|
72
|
-
}
|
|
73
|
-
}, T = class extends g {
|
|
74
|
-
_bits;
|
|
75
|
-
constructor(e) {
|
|
76
|
-
super(o(e), { precision: "half" }), this._bits = e & 65535;
|
|
77
|
-
}
|
|
78
|
-
_toCBOR() {
|
|
79
|
-
return new Uint8Array([
|
|
80
|
-
249,
|
|
81
|
-
this._bits >> 8 & 255,
|
|
82
|
-
this._bits & 255
|
|
83
|
-
]);
|
|
84
|
-
}
|
|
85
|
-
}, E = class extends g {
|
|
86
|
-
_raw;
|
|
87
|
-
constructor(e) {
|
|
88
|
-
super(new DataView(e.buffer, e.byteOffset).getFloat32(0, !1), { precision: "single" }), this._raw = e.slice();
|
|
89
|
-
}
|
|
90
|
-
_toCBOR() {
|
|
91
|
-
let e = /* @__PURE__ */ new Uint8Array(5);
|
|
92
|
-
return e[0] = 250, e.set(this._raw, 1), e;
|
|
93
|
-
}
|
|
94
|
-
}, D = class extends g {
|
|
95
|
-
_raw;
|
|
96
|
-
constructor(e) {
|
|
97
|
-
super(new DataView(e.buffer, e.byteOffset).getFloat64(0, !1), { precision: "double" }), this._raw = e.slice();
|
|
98
|
-
}
|
|
99
|
-
_toCBOR() {
|
|
100
|
-
let e = /* @__PURE__ */ new Uint8Array(9);
|
|
101
|
-
return e[0] = 251, e.set(this._raw, 1), e;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
function O(e) {
|
|
105
|
-
if (e.length === 2) return new T(e[0] << 8 | e[1]);
|
|
106
|
-
if (e.length === 4) return new E(e);
|
|
107
|
-
if (e.length === 8) return new D(e);
|
|
108
|
-
throw SyntaxError(`float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${e.length} bytes`);
|
|
109
|
-
}
|
|
110
|
-
function k(e) {
|
|
111
|
-
let t = e >>> 15 & 1, n = e >>> 10 & 31, r = e & 1023, i;
|
|
112
|
-
if (n === 31) i = t << 31 | 2139095040 | r << 13;
|
|
113
|
-
else if (n === 0 && r === 0) i = t << 31;
|
|
114
|
-
else if (n === 0) {
|
|
115
|
-
let e = r, n = 0;
|
|
116
|
-
for (; !(e & 512);) e <<= 1, n++;
|
|
117
|
-
i = t << 31 | 112 - n << 23 | (e & 511) << 14;
|
|
118
|
-
} else i = t << 31 | n + 112 << 23 | r << 13;
|
|
119
|
-
let a = /* @__PURE__ */ new Uint8Array(4);
|
|
120
|
-
return new DataView(a.buffer).setUint32(0, i >>> 0, !1), a;
|
|
121
|
-
}
|
|
122
|
-
function A(e) {
|
|
123
|
-
let t = e >>> 15 & 1, n = e >>> 10 & 31, r = e & 1023, i = /* @__PURE__ */ new Uint8Array(8), a = new DataView(i.buffer);
|
|
124
|
-
if (n === 31) a.setUint32(0, (t << 31 | 2146435072 | r << 10) >>> 0, !1), a.setUint32(4, 0, !1);
|
|
125
|
-
else if (n === 0 && r === 0) a.setUint32(0, t << 31 >>> 0, !1), a.setUint32(4, 0, !1);
|
|
126
|
-
else if (n === 0) {
|
|
127
|
-
let e = r, n = 0;
|
|
128
|
-
for (; !(e & 512);) e <<= 1, n++;
|
|
129
|
-
a.setUint32(0, (t << 31 | 1008 - n << 20 | (e & 511) << 11) >>> 0, !1), a.setUint32(4, 0, !1);
|
|
130
|
-
} else a.setUint32(0, (t << 31 | n + 1008 << 20 | r << 10) >>> 0, !1), a.setUint32(4, 0, !1);
|
|
131
|
-
return i;
|
|
132
|
-
}
|
|
133
|
-
function j(e) {
|
|
134
|
-
let t = new DataView(e.buffer, e.byteOffset).getUint32(0, !1), n = t >>> 31 & 1, r = t >>> 23 & 255, i = t & 8388607, a = /* @__PURE__ */ new Uint8Array(8), o = new DataView(a.buffer);
|
|
135
|
-
if (r === 255) o.setUint32(0, (n << 31 | 2146435072 | i >>> 3) >>> 0, !1), o.setUint32(4, (i & 7) << 29, !1);
|
|
136
|
-
else if (r === 0 && i === 0) o.setUint32(0, n << 31 >>> 0, !1), o.setUint32(4, 0, !1);
|
|
137
|
-
else {
|
|
138
|
-
let t = new DataView(e.buffer, e.byteOffset).getFloat32(0, !1);
|
|
139
|
-
o.setFloat64(0, t, !1);
|
|
140
|
-
}
|
|
141
|
-
return a;
|
|
142
|
-
}
|
|
143
|
-
function M(e, t, r) {
|
|
144
|
-
let i = e.length === 2 ? 1 : e.length === 4 ? 2 : 3;
|
|
145
|
-
if (i === 1) {
|
|
146
|
-
let n = e[0] << 8 | e[1];
|
|
147
|
-
if (t === 2) return new E(k(n));
|
|
148
|
-
if (t === 3) return new D(A(n));
|
|
149
|
-
}
|
|
150
|
-
if (i === 2) {
|
|
151
|
-
if (t === 3) return new D(j(e));
|
|
152
|
-
if (t === 1) {
|
|
153
|
-
let t = new DataView(e.buffer, e.byteOffset).getFloat32(0, !1), i = n(t);
|
|
154
|
-
return !Object.is(o(i), t) && !isNaN(t) && r("float'...' value cannot be exactly represented as float16 (_1)"), new T(i);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (i === 3) {
|
|
158
|
-
let i = new DataView(e.buffer, e.byteOffset).getFloat64(0, !1);
|
|
159
|
-
if (t === 1) {
|
|
160
|
-
let e = n(i);
|
|
161
|
-
return !Object.is(o(e), i) && !isNaN(i) && r("float'...' value cannot be exactly represented as float16 (_1)"), new T(e);
|
|
162
|
-
}
|
|
163
|
-
if (t === 2) {
|
|
164
|
-
let e = Math.fround(i);
|
|
165
|
-
!Object.is(e, i) && !isNaN(i) && r("float'...' value cannot be exactly represented as float32 (_2)");
|
|
166
|
-
let t = /* @__PURE__ */ new Uint8Array(4);
|
|
167
|
-
return new DataView(t.buffer).setFloat32(0, e, !1), new E(t);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return O(e);
|
|
171
|
-
}
|
|
172
|
-
var N = {
|
|
173
|
-
appStringPrefixes: ["float"],
|
|
174
|
-
parseAppString(t, n, r, i) {
|
|
175
|
-
let a = v(n);
|
|
176
|
-
if (!/^[0-9a-fA-F]*$/.test(a)) throw SyntaxError("float'...' contains non-hex characters");
|
|
177
|
-
if (a.length % 2 != 0) throw SyntaxError(`float'...' hex content has odd length (${a.length} digits)`);
|
|
178
|
-
let o = e(a), s = i?.encodingWidth;
|
|
179
|
-
if (s === void 0) return O(o);
|
|
180
|
-
if (s !== 1 && s !== 2 && s !== 3) {
|
|
181
|
-
let e = `float'...' encoding indicator _${s} is not valid; use _1, _2, or _3`;
|
|
182
|
-
if (r) return r(e), O(o);
|
|
183
|
-
throw SyntaxError(e);
|
|
184
|
-
}
|
|
185
|
-
return s === (o.length === 2 ? 1 : o.length === 4 ? 2 : 3) ? O(o) : M(o, s, r ?? ((e) => {
|
|
186
|
-
throw SyntaxError(e);
|
|
187
|
-
}));
|
|
188
|
-
},
|
|
189
|
-
parseAppSequence(e, t, n) {
|
|
190
|
-
if (t.length === 0) throw SyntaxError("float<<...>> requires exactly one byte-string item");
|
|
191
|
-
if (t.length > 1) {
|
|
192
|
-
let e = `float<<...>> expects 1 item; got ${t.length} — using first`;
|
|
193
|
-
if (n) n(e);
|
|
194
|
-
else throw SyntaxError(e);
|
|
195
|
-
}
|
|
196
|
-
if (!(t[0] instanceof l)) throw SyntaxError("float<<...>> item must be a byte string");
|
|
197
|
-
return O(t[0].value);
|
|
36
|
+
return new a(C(o(t), x, n), { ednEncoding: "base32hex" });
|
|
198
37
|
}
|
|
199
38
|
};
|
|
200
39
|
//#endregion
|
|
201
40
|
//#region src/extensions/same.ts
|
|
202
|
-
function
|
|
41
|
+
function E(e, t) {
|
|
203
42
|
if (e.length !== t.length) return !1;
|
|
204
43
|
for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
|
|
205
44
|
return !0;
|
|
206
45
|
}
|
|
207
|
-
var
|
|
46
|
+
var D = {
|
|
208
47
|
appStringPrefixes: ["same"],
|
|
209
48
|
preserveAppSeqSource: !0,
|
|
210
49
|
parseAppSequence(e, t, n) {
|
|
211
50
|
if (t.length === 0) throw SyntaxError("same<<...>> requires at least one item");
|
|
212
51
|
let r = t[0], i = r.toCBOR();
|
|
213
|
-
for (let e = 1; e < t.length; e++) if (!
|
|
52
|
+
for (let e = 1; e < t.length; e++) if (!E(i, t[e].toCBOR())) {
|
|
214
53
|
let t = `same<<...>>: item ${e} produces different CBOR bytes than item 0`;
|
|
215
54
|
if (n) n(t);
|
|
216
55
|
else throw SyntaxError(t);
|
|
217
56
|
}
|
|
218
57
|
return r;
|
|
219
58
|
}
|
|
220
|
-
},
|
|
221
|
-
static OMIT =
|
|
222
|
-
static TAG =
|
|
223
|
-
static Tag =
|
|
224
|
-
static Simple =
|
|
225
|
-
static MapEntries =
|
|
59
|
+
}, O = class r {
|
|
60
|
+
static OMIT = d;
|
|
61
|
+
static TAG = t;
|
|
62
|
+
static Tag = n;
|
|
63
|
+
static Simple = i;
|
|
64
|
+
static MapEntries = v;
|
|
226
65
|
static dt_as_Date = c;
|
|
227
66
|
#e;
|
|
228
67
|
constructor(e) {
|
|
@@ -234,110 +73,110 @@ var F = {
|
|
|
234
73
|
...e ?? {}
|
|
235
74
|
};
|
|
236
75
|
}
|
|
237
|
-
fromCBOR(
|
|
238
|
-
let
|
|
239
|
-
return
|
|
76
|
+
fromCBOR(e, t) {
|
|
77
|
+
let n = r.fromCBOR(e, this.#t(t));
|
|
78
|
+
return n._defaults = this.#e, n;
|
|
240
79
|
}
|
|
241
|
-
fromCDN(
|
|
242
|
-
let
|
|
243
|
-
return
|
|
80
|
+
fromCDN(e, t) {
|
|
81
|
+
let n = r.fromCDN(e, this.#t(t));
|
|
82
|
+
return n._defaults = this.#e, n;
|
|
244
83
|
}
|
|
245
84
|
fromEDN(e, t) {
|
|
246
85
|
return this.fromCDN(e, t);
|
|
247
86
|
}
|
|
248
|
-
fromJS(
|
|
249
|
-
let
|
|
250
|
-
return
|
|
87
|
+
fromJS(e, t) {
|
|
88
|
+
let n = r.fromJS(e, this.#t(t));
|
|
89
|
+
return n._defaults = this.#e, n;
|
|
251
90
|
}
|
|
252
|
-
fromHexDump(
|
|
253
|
-
let
|
|
254
|
-
return
|
|
91
|
+
fromHexDump(e, t) {
|
|
92
|
+
let n = r.fromHexDump(e, this.#t(t));
|
|
93
|
+
return n._defaults = this.#e, n;
|
|
255
94
|
}
|
|
256
|
-
*fromCBORSeq(
|
|
257
|
-
for (let
|
|
95
|
+
*fromCBORSeq(e, t) {
|
|
96
|
+
for (let n of r.fromCBORSeq(e, this.#t(t))) n._defaults = this.#e, yield n;
|
|
258
97
|
}
|
|
259
|
-
*fromCDNSeq(
|
|
260
|
-
for (let
|
|
98
|
+
*fromCDNSeq(e, t) {
|
|
99
|
+
for (let n of r.fromCDNSeq(e, this.#t(t))) n._defaults = this.#e, yield n;
|
|
261
100
|
}
|
|
262
|
-
*fromHexDumpSeq(
|
|
263
|
-
for (let
|
|
101
|
+
*fromHexDumpSeq(e, t) {
|
|
102
|
+
for (let n of r.fromHexDumpSeq(e, this.#t(t))) n._defaults = this.#e, yield n;
|
|
264
103
|
}
|
|
265
|
-
decode(
|
|
266
|
-
return
|
|
104
|
+
decode(e, t) {
|
|
105
|
+
return r.decode(e, this.#t(t));
|
|
267
106
|
}
|
|
268
|
-
*decodeSeq(
|
|
269
|
-
yield*
|
|
107
|
+
*decodeSeq(e, t) {
|
|
108
|
+
yield* r.decodeSeq(e, this.#t(t));
|
|
270
109
|
}
|
|
271
|
-
*parseSeq(
|
|
272
|
-
yield*
|
|
110
|
+
*parseSeq(e, t) {
|
|
111
|
+
yield* r.parseSeq(e, this.#t(t));
|
|
273
112
|
}
|
|
274
|
-
encode(
|
|
275
|
-
return
|
|
113
|
+
encode(e, t) {
|
|
114
|
+
return r.encode(e, this.#t(t));
|
|
276
115
|
}
|
|
277
|
-
compile(
|
|
278
|
-
return
|
|
116
|
+
compile(e, t) {
|
|
117
|
+
return r.compile(e, this.#t(t));
|
|
279
118
|
}
|
|
280
|
-
decompile(
|
|
281
|
-
return
|
|
119
|
+
decompile(e, t) {
|
|
120
|
+
return r.decompile(e, this.#t(t));
|
|
282
121
|
}
|
|
283
|
-
toHex(
|
|
284
|
-
return
|
|
122
|
+
toHex(e, t) {
|
|
123
|
+
return r.toHex(e, this.#t(t));
|
|
285
124
|
}
|
|
286
|
-
fromHex(
|
|
287
|
-
return
|
|
125
|
+
fromHex(e, t) {
|
|
126
|
+
return r.fromHex(e, this.#t(t));
|
|
288
127
|
}
|
|
289
128
|
cborToCborEdn(e, t) {
|
|
290
129
|
return this.cborToCdn(e, t);
|
|
291
130
|
}
|
|
292
|
-
cborToCdn(
|
|
293
|
-
let
|
|
294
|
-
return i._defaults = this.#e, i.toCDN(
|
|
131
|
+
cborToCdn(e, t) {
|
|
132
|
+
let n = this.#t(t), i = r.fromCBOR(e, n);
|
|
133
|
+
return i._defaults = this.#e, i.toCDN(n);
|
|
295
134
|
}
|
|
296
135
|
cborEdnToCbor(e, t) {
|
|
297
136
|
return this.cdnToCbor(e, t);
|
|
298
137
|
}
|
|
299
|
-
cdnToCbor(
|
|
300
|
-
let
|
|
301
|
-
return
|
|
138
|
+
cdnToCbor(e, t) {
|
|
139
|
+
let n = this.#t(t);
|
|
140
|
+
return r.fromCDN(e, n).toCBOR(n);
|
|
302
141
|
}
|
|
303
|
-
parse(
|
|
304
|
-
if (typeof
|
|
305
|
-
let
|
|
306
|
-
return
|
|
142
|
+
parse(e, t) {
|
|
143
|
+
if (typeof t == "function") {
|
|
144
|
+
let n = this.#t({ reviver: t });
|
|
145
|
+
return r.fromCDN(e, n).toJS(n);
|
|
307
146
|
}
|
|
308
|
-
let
|
|
309
|
-
return
|
|
147
|
+
let n = this.#t(t);
|
|
148
|
+
return r.fromCDN(e, n).toJS(n);
|
|
310
149
|
}
|
|
311
|
-
stringify(t, n
|
|
312
|
-
if (typeof
|
|
150
|
+
stringify(e, t, n) {
|
|
151
|
+
if (typeof t == "function" || Array.isArray(t) || t === null || t === void 0 && n !== void 0) {
|
|
313
152
|
let i = { ...this.#e };
|
|
314
|
-
return
|
|
153
|
+
return t === null ? i.replacer = void 0 : (typeof t == "function" || Array.isArray(t)) && (i.replacer = t), n !== void 0 && (i.indent = F(n)), r.stringify(e, i);
|
|
315
154
|
}
|
|
316
|
-
return
|
|
155
|
+
return r.stringify(e, this.#t(t ?? void 0));
|
|
317
156
|
}
|
|
318
|
-
format(
|
|
319
|
-
return
|
|
157
|
+
format(e, t) {
|
|
158
|
+
return r.format(e, this.#t(t));
|
|
320
159
|
}
|
|
321
160
|
static fromCBOR(e, t) {
|
|
322
|
-
return
|
|
161
|
+
return y(e, t);
|
|
323
162
|
}
|
|
324
163
|
static fromCDN(e, t) {
|
|
325
|
-
return
|
|
164
|
+
return h(e, t);
|
|
326
165
|
}
|
|
327
|
-
static fromEDN(
|
|
328
|
-
return
|
|
166
|
+
static fromEDN(e, t) {
|
|
167
|
+
return r.fromCDN(e, t);
|
|
329
168
|
}
|
|
330
|
-
static *fromHexDumpSeq(
|
|
331
|
-
let
|
|
332
|
-
for (let e of i) if (/^[0-9A-Fa-f]{2}$/.test(e))
|
|
333
|
-
else if (/^[0-9A-Fa-f]+$/.test(e) && e.length % 2 == 0) for (let t = 0; t < e.length; t += 2)
|
|
169
|
+
static *fromHexDumpSeq(e, t) {
|
|
170
|
+
let n = [], i = k(e).trim().split(/\s+/).filter(Boolean);
|
|
171
|
+
for (let e of i) if (/^[0-9A-Fa-f]{2}$/.test(e)) n.push(parseInt(e, 16));
|
|
172
|
+
else if (/^[0-9A-Fa-f]+$/.test(e) && e.length % 2 == 0) for (let t = 0; t < e.length; t += 2) n.push(parseInt(e.slice(t, t + 2), 16));
|
|
334
173
|
else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);
|
|
335
|
-
yield*
|
|
174
|
+
yield* r.fromCBORSeq(new Uint8Array(n), t);
|
|
336
175
|
}
|
|
337
176
|
static *fromCBORSeq(e, t) {
|
|
338
177
|
let n = e instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength), r = 0;
|
|
339
178
|
for (; r < n.byteLength;) {
|
|
340
|
-
let e =
|
|
179
|
+
let e = y(n, {
|
|
341
180
|
...t,
|
|
342
181
|
offset: r,
|
|
343
182
|
allowTrailing: !0
|
|
@@ -345,168 +184,168 @@ var F = {
|
|
|
345
184
|
yield e, r = e.end;
|
|
346
185
|
}
|
|
347
186
|
}
|
|
348
|
-
static *fromCDNSeq(
|
|
187
|
+
static *fromCDNSeq(t, n) {
|
|
349
188
|
let r = !!n?.preserveComments, i = 0, a = !0;
|
|
350
189
|
for (;;) {
|
|
351
|
-
let { offset: o, hadSeparator: s, commaOffset: c } =
|
|
190
|
+
let { offset: o, hadSeparator: s, commaOffset: c } = P(t, i, n, r ? a ? "all" : "after-newline" : "none");
|
|
352
191
|
if (a && c >= 0) {
|
|
353
192
|
let e = "leading comma in CDN sequence";
|
|
354
193
|
if (n?.strict !== !1) throw SyntaxError(e);
|
|
355
|
-
|
|
194
|
+
M(e, c, n);
|
|
356
195
|
}
|
|
357
|
-
if (o >=
|
|
196
|
+
if (o >= t.length || r && N(t, o) && P(t, o, n).offset >= t.length) break;
|
|
358
197
|
if (!a && !s) {
|
|
359
198
|
let e = "CDN sequence items must be separated by whitespace, comma, or comment";
|
|
360
199
|
if (n?.strict !== !1) throw SyntaxError(e);
|
|
361
|
-
|
|
200
|
+
M(e, o, n);
|
|
362
201
|
}
|
|
363
202
|
i = o;
|
|
364
203
|
let l;
|
|
365
204
|
try {
|
|
366
|
-
l =
|
|
205
|
+
l = h(t, {
|
|
367
206
|
...n,
|
|
368
207
|
offset: i,
|
|
369
208
|
allowTrailing: !0,
|
|
370
209
|
_skipRS: !0
|
|
371
210
|
});
|
|
372
|
-
} catch (
|
|
373
|
-
if (n?.strict !== !1) throw
|
|
374
|
-
|
|
211
|
+
} catch (t) {
|
|
212
|
+
if (n?.strict !== !1) throw t;
|
|
213
|
+
M(t instanceof Error ? t.message : String(t), i, n, !0, t instanceof e ? t : void 0);
|
|
375
214
|
break;
|
|
376
215
|
}
|
|
377
216
|
yield l, i = l.end, a = !1;
|
|
378
217
|
}
|
|
379
218
|
}
|
|
380
219
|
static fromJS(e, t) {
|
|
381
|
-
return
|
|
220
|
+
return g(e, t);
|
|
382
221
|
}
|
|
383
222
|
static fromHexDump(e, t) {
|
|
384
|
-
let n = [], r =
|
|
223
|
+
let n = [], r = k(e).trim().split(/\s+/).filter(Boolean);
|
|
385
224
|
for (let e of r) if (/^[0-9A-Fa-f]{2}$/.test(e)) n.push(parseInt(e, 16));
|
|
386
225
|
else if (/^[0-9A-Fa-f]+$/.test(e) && e.length % 2 == 0) for (let t = 0; t < e.length; t += 2) n.push(parseInt(e.slice(t, t + 2), 16));
|
|
387
226
|
else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);
|
|
388
|
-
return
|
|
227
|
+
return y(new Uint8Array(n), t);
|
|
389
228
|
}
|
|
390
|
-
static decode(
|
|
391
|
-
return
|
|
229
|
+
static decode(e, t) {
|
|
230
|
+
return r.fromCBOR(e, t).toJS(t);
|
|
392
231
|
}
|
|
393
|
-
static *decodeSeq(
|
|
394
|
-
for (let
|
|
232
|
+
static *decodeSeq(e, t) {
|
|
233
|
+
for (let n of r.fromCBORSeq(e, t)) yield n.toJS(t);
|
|
395
234
|
}
|
|
396
|
-
static *parseSeq(
|
|
397
|
-
for (let
|
|
235
|
+
static *parseSeq(e, t) {
|
|
236
|
+
for (let n of r.fromCDNSeq(e, t)) yield n.toJS(t);
|
|
398
237
|
}
|
|
399
|
-
static encode(
|
|
400
|
-
return
|
|
238
|
+
static encode(e, t) {
|
|
239
|
+
return r.fromJS(e, t).toCBOR(t);
|
|
401
240
|
}
|
|
402
|
-
static compile(
|
|
403
|
-
let
|
|
404
|
-
for (let e of
|
|
241
|
+
static compile(e, t) {
|
|
242
|
+
let n = [...r.fromCDNSeq(e, t)].map((e) => e.toCBOR(t)), i = n.reduce((e, t) => e + t.length, 0), a = new Uint8Array(i), o = 0;
|
|
243
|
+
for (let e of n) a.set(e, o), o += e.length;
|
|
405
244
|
return a;
|
|
406
245
|
}
|
|
407
|
-
static decompile(
|
|
408
|
-
return [...
|
|
246
|
+
static decompile(e, t) {
|
|
247
|
+
return [...r.fromCBORSeq(e, t)].map((e) => e.toCDN(t)).join("\n");
|
|
409
248
|
}
|
|
410
|
-
static toHex(
|
|
411
|
-
return [...
|
|
249
|
+
static toHex(e, t) {
|
|
250
|
+
return [...r.fromCBORSeq(e, t)].map((e) => e.toHexDump(t)).join("\n");
|
|
412
251
|
}
|
|
413
|
-
static fromHex(
|
|
414
|
-
let
|
|
415
|
-
for (let e of
|
|
252
|
+
static fromHex(e, t) {
|
|
253
|
+
let n = [...r.fromHexDumpSeq(e, t)].map((e) => e.toCBOR(t)), i = n.reduce((e, t) => e + t.length, 0), a = new Uint8Array(i), o = 0;
|
|
254
|
+
for (let e of n) a.set(e, o), o += e.length;
|
|
416
255
|
return a;
|
|
417
256
|
}
|
|
418
|
-
static cborToCdn(
|
|
419
|
-
return
|
|
257
|
+
static cborToCdn(e, t) {
|
|
258
|
+
return r.fromCBOR(e, t).toCDN(t);
|
|
420
259
|
}
|
|
421
|
-
static cborToCborEdn(
|
|
422
|
-
return
|
|
260
|
+
static cborToCborEdn(e, t) {
|
|
261
|
+
return r.fromCBOR(e, t).toCDN(t);
|
|
423
262
|
}
|
|
424
|
-
static cdnToCbor(
|
|
425
|
-
return
|
|
263
|
+
static cdnToCbor(e, t) {
|
|
264
|
+
return r.fromCDN(e, t).toCBOR(t);
|
|
426
265
|
}
|
|
427
|
-
static cborEdnToCbor(
|
|
428
|
-
return
|
|
266
|
+
static cborEdnToCbor(e, t) {
|
|
267
|
+
return r.fromCDN(e, t).toCBOR(t);
|
|
429
268
|
}
|
|
430
|
-
static parse(
|
|
431
|
-
return typeof
|
|
269
|
+
static parse(e, t) {
|
|
270
|
+
return typeof t == "function" ? r.fromCDN(e).toJS({ reviver: t }) : r.fromCDN(e, t).toJS(t);
|
|
432
271
|
}
|
|
433
272
|
static stringify(e, t, n) {
|
|
434
273
|
if (typeof t == "function" || Array.isArray(t) || t === null || t === void 0 && n !== void 0) {
|
|
435
|
-
let r = typeof t == "function" || Array.isArray(t) ? t : void 0, i =
|
|
274
|
+
let r = typeof t == "function" || Array.isArray(t) ? t : void 0, i = F(n);
|
|
436
275
|
if (r) {
|
|
437
|
-
let t =
|
|
438
|
-
return t === void 0 || t ===
|
|
276
|
+
let t = p(e, r);
|
|
277
|
+
return t === void 0 || t === d ? void 0 : g(t).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
439
278
|
}
|
|
440
|
-
return
|
|
279
|
+
return g(e).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
441
280
|
}
|
|
442
281
|
let r = t;
|
|
443
282
|
if (r?.replacer) {
|
|
444
|
-
let t =
|
|
445
|
-
if (t === void 0 || t ===
|
|
283
|
+
let t = p(e, r.replacer, r.extensions, r.undefinedOmits);
|
|
284
|
+
if (t === void 0 || t === d) return;
|
|
446
285
|
let { replacer: n, ...i } = r;
|
|
447
|
-
return
|
|
286
|
+
return g(t, Object.keys(i).length > 0 ? i : void 0).toCDN(r);
|
|
448
287
|
}
|
|
449
|
-
return
|
|
288
|
+
return g(e, r).toCDN(r);
|
|
450
289
|
}
|
|
451
|
-
static format(
|
|
452
|
-
return
|
|
290
|
+
static format(e, t) {
|
|
291
|
+
return r.fromCDN(e, t).toCDN(t);
|
|
453
292
|
}
|
|
454
293
|
};
|
|
455
|
-
function
|
|
294
|
+
function k(e) {
|
|
456
295
|
let t = "", n = 0;
|
|
457
296
|
for (; n < e.length;) {
|
|
458
297
|
let r = e[n], i = e[n + 1] ?? "";
|
|
459
298
|
if (r === "-" && i === "-") {
|
|
460
|
-
n =
|
|
299
|
+
n = A(e, n + 2), t += " ";
|
|
461
300
|
continue;
|
|
462
301
|
}
|
|
463
302
|
if (r === "—") {
|
|
464
|
-
n =
|
|
303
|
+
n = A(e, n + 1), t += " ";
|
|
465
304
|
continue;
|
|
466
305
|
}
|
|
467
306
|
if (r === "#") {
|
|
468
|
-
n =
|
|
307
|
+
n = A(e, n + 1), t += " ";
|
|
469
308
|
continue;
|
|
470
309
|
}
|
|
471
310
|
if (r === "/" && i === "/") {
|
|
472
|
-
n =
|
|
311
|
+
n = A(e, n + 2), t += " ";
|
|
473
312
|
continue;
|
|
474
313
|
}
|
|
475
314
|
if (r === "/" && i === "*") {
|
|
476
315
|
let r = e.indexOf("*/", n + 2);
|
|
477
316
|
if (r < 0) throw SyntaxError("Unterminated comment in hex dump");
|
|
478
|
-
t +=
|
|
317
|
+
t += j(e.slice(n, r + 2)), n = r + 2;
|
|
479
318
|
continue;
|
|
480
319
|
}
|
|
481
320
|
if (r === "/") {
|
|
482
321
|
let r = e.indexOf("/", n + 1);
|
|
483
322
|
if (r < 0) throw SyntaxError("Unterminated comment in hex dump");
|
|
484
|
-
t +=
|
|
323
|
+
t += j(e.slice(n, r + 1)), n = r + 1;
|
|
485
324
|
continue;
|
|
486
325
|
}
|
|
487
326
|
t += r, n++;
|
|
488
327
|
}
|
|
489
328
|
return t;
|
|
490
329
|
}
|
|
491
|
-
function
|
|
330
|
+
function A(e, t) {
|
|
492
331
|
let n = e.indexOf("\n", t);
|
|
493
332
|
return n < 0 ? e.length : n;
|
|
494
333
|
}
|
|
495
|
-
function
|
|
334
|
+
function j(e) {
|
|
496
335
|
return e.replace(/[^\r\n]/g, " ");
|
|
497
336
|
}
|
|
498
|
-
function
|
|
337
|
+
function M(e, t, n, r, i) {
|
|
499
338
|
let a = i?.offset ?? t, o = {
|
|
500
339
|
message: e,
|
|
501
340
|
offset: a
|
|
502
341
|
};
|
|
503
342
|
r && (o.fatal = !0), i?.offset !== void 0 && (o.line = i.line, o.column = i.column, o.endOffset = i.endOffset), n?.onWarning ? n.onWarning(o) : n?.silent || console.warn(`CDN sequence warning at offset ${a}: ${e}`);
|
|
504
343
|
}
|
|
505
|
-
function
|
|
344
|
+
function N(e, t) {
|
|
506
345
|
let n = e[t];
|
|
507
346
|
return n === "#" || n === "/";
|
|
508
347
|
}
|
|
509
|
-
function
|
|
348
|
+
function P(e, t, n, r = "none") {
|
|
510
349
|
let i = t, a = !1, o = !1, s = !1, c = -1, l = () => r === "all" || r === "after-newline" && s;
|
|
511
350
|
for (; i < e.length;) {
|
|
512
351
|
let t = e[i];
|
|
@@ -536,7 +375,7 @@ function H(e, t, n, r = "none") {
|
|
|
536
375
|
if (t < 0) {
|
|
537
376
|
let t = "unterminated /* comment in CDN sequence";
|
|
538
377
|
if (n?.strict !== !1) throw SyntaxError(t);
|
|
539
|
-
|
|
378
|
+
M(t, i, n, !0), i = e.length;
|
|
540
379
|
} else e.slice(i, t).includes("\n") && (s = !0), i = t + 2;
|
|
541
380
|
continue;
|
|
542
381
|
}
|
|
@@ -546,7 +385,7 @@ function H(e, t, n, r = "none") {
|
|
|
546
385
|
if (t < 0) {
|
|
547
386
|
let t = "unterminated / comment in CDN sequence";
|
|
548
387
|
if (n?.strict !== !1) throw SyntaxError(t);
|
|
549
|
-
|
|
388
|
+
M(t, i, n, !0), i = e.length;
|
|
550
389
|
} else e.slice(i, t).includes("\n") && (s = !0), i = t + 1;
|
|
551
390
|
continue;
|
|
552
391
|
}
|
|
@@ -562,7 +401,7 @@ function H(e, t, n, r = "none") {
|
|
|
562
401
|
commaOffset: c
|
|
563
402
|
};
|
|
564
403
|
}
|
|
565
|
-
function
|
|
404
|
+
function F(e) {
|
|
566
405
|
if (typeof e == "number") {
|
|
567
406
|
let t = Math.floor(Math.min(10, Math.max(0, e)));
|
|
568
407
|
return t === 0 ? void 0 : t;
|
|
@@ -570,6 +409,6 @@ function U(e) {
|
|
|
570
409
|
if (typeof e == "string") return e.slice(0, 10) || void 0;
|
|
571
410
|
}
|
|
572
411
|
//#endregion
|
|
573
|
-
export {
|
|
412
|
+
export { O as CBOR, O as default, d as CBOR_OMIT, t as CBOR_TAG, e as CdnSyntaxError, v as MapEntries, u as Null, i as Simple, n as Tag, r as Undefined, s as b1, w as b32, c as dt_as_Date, l as float, T as h32, m as ilbs, _ as ilts, D as same, f as t1 };
|
|
574
413
|
|
|
575
414
|
//# sourceMappingURL=index.js.map
|