@cbortech/cbor 0.25.5 → 0.25.7
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/dist/ast/CborAppSeqResult.d.ts +4 -2
- package/dist/ast/CborArray.d.ts +1 -1
- package/dist/ast/CborByteString.d.ts +1 -1
- package/dist/ast/CborEmbeddedCBOR.d.ts +5 -2
- package/dist/ast/CborFloat.d.ts +1 -1
- package/dist/ast/CborIndefiniteTextString.d.ts +1 -1
- package/dist/ast/CborMap.d.ts +1 -1
- package/dist/ast/CborNint.d.ts +1 -1
- package/dist/ast/CborTag.d.ts +1 -1
- package/dist/ast/CborTextString.d.ts +1 -1
- package/dist/ast/CborUint.d.ts +1 -1
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cdn/index.cjs +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/serialize-utils.d.ts +14 -2
- package/dist/extensions/dt.d.ts +2 -2
- package/dist/extensions/types.d.ts +4 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +133 -62
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-C5S6uTIO.cjs +12 -0
- package/dist/mapEntries-C5S6uTIO.cjs.map +1 -0
- package/dist/{mapEntries-D6BfG4-1.js → mapEntries-bvRWFfqX.js} +755 -614
- package/dist/mapEntries-bvRWFfqX.js.map +1 -0
- package/dist/{tokenizer-C597LW89.js → tokenizer-BuRSmdyM.js} +3 -3
- package/dist/{tokenizer-C597LW89.js.map → tokenizer-BuRSmdyM.js.map} +1 -1
- package/dist/{tokenizer-C8NLHT2B.cjs → tokenizer-M2pf9ud0.cjs} +2 -2
- package/dist/{tokenizer-C8NLHT2B.cjs.map → tokenizer-M2pf9ud0.cjs.map} +1 -1
- package/dist/types.d.ts +49 -7
- package/package.json +7 -7
- package/dist/mapEntries-Chd4Qmgv.cjs +0 -12
- package/dist/mapEntries-Chd4Qmgv.cjs.map +0 -1
- package/dist/mapEntries-D6BfG4-1.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as e } from "./tokenizer-
|
|
2
|
-
import {
|
|
1
|
+
import { n as e } from "./tokenizer-BuRSmdyM.js";
|
|
2
|
+
import { A as t, C as n, D as r, E as i, O as a, S as o, T as s, a as c, g as l, i as u, k as d, n as f, r as p, s as m, t as h, v as g, w as _ } from "./mapEntries-bvRWFfqX.js";
|
|
3
3
|
//#region src/utils/strip-comments.ts
|
|
4
|
-
function
|
|
4
|
+
function v(e) {
|
|
5
5
|
let t = "", n = 0;
|
|
6
6
|
for (; n < e.length;) {
|
|
7
7
|
let r = e[n];
|
|
@@ -36,14 +36,14 @@ function _(e) {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/extensions/b32.ts
|
|
39
|
-
var
|
|
40
|
-
function
|
|
39
|
+
var y = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", b = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
40
|
+
function x(e) {
|
|
41
41
|
let t = e.length;
|
|
42
42
|
for (; t > 0 && e.charCodeAt(t - 1) === 61;) t--;
|
|
43
43
|
return e.slice(0, t);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
let r =
|
|
45
|
+
function S(e, t, n) {
|
|
46
|
+
let r = x(e).toUpperCase(), i = r.length % 8;
|
|
47
47
|
if (i === 1 || i === 3 || i === 6) throw SyntaxError(`invalid base32 length: ${r.length} characters`);
|
|
48
48
|
let a = new Uint8Array(128).fill(255);
|
|
49
49
|
for (let e = 0; e < t.length; e++) a[t.charCodeAt(e)] = e;
|
|
@@ -60,20 +60,20 @@ function x(e, t, n) {
|
|
|
60
60
|
}
|
|
61
61
|
return o;
|
|
62
62
|
}
|
|
63
|
-
var
|
|
63
|
+
var C = {
|
|
64
64
|
appStringPrefixes: ["b32"],
|
|
65
65
|
parseAppString(e, t, n) {
|
|
66
|
-
return new
|
|
66
|
+
return new l(S(v(t), y, n), { ednEncoding: "base32" });
|
|
67
67
|
}
|
|
68
|
-
},
|
|
68
|
+
}, w = {
|
|
69
69
|
appStringPrefixes: ["h32"],
|
|
70
70
|
parseAppString(e, t, n) {
|
|
71
|
-
return new
|
|
71
|
+
return new l(S(v(t), b, n), { ednEncoding: "base32hex" });
|
|
72
72
|
}
|
|
73
|
-
},
|
|
73
|
+
}, T = class extends g {
|
|
74
74
|
_bits;
|
|
75
75
|
constructor(e) {
|
|
76
|
-
super(
|
|
76
|
+
super(o(e), { precision: "half" }), this._bits = e & 65535;
|
|
77
77
|
}
|
|
78
78
|
_toCBOR() {
|
|
79
79
|
return new Uint8Array([
|
|
@@ -82,7 +82,7 @@ var S = {
|
|
|
82
82
|
this._bits & 255
|
|
83
83
|
]);
|
|
84
84
|
}
|
|
85
|
-
},
|
|
85
|
+
}, E = class extends g {
|
|
86
86
|
_raw;
|
|
87
87
|
constructor(e) {
|
|
88
88
|
super(new DataView(e.buffer, e.byteOffset).getFloat32(0, !1), { precision: "single" }), this._raw = e.slice();
|
|
@@ -91,7 +91,7 @@ var S = {
|
|
|
91
91
|
let e = new Uint8Array(5);
|
|
92
92
|
return e[0] = 250, e.set(this._raw, 1), e;
|
|
93
93
|
}
|
|
94
|
-
},
|
|
94
|
+
}, D = class extends g {
|
|
95
95
|
_raw;
|
|
96
96
|
constructor(e) {
|
|
97
97
|
super(new DataView(e.buffer, e.byteOffset).getFloat64(0, !1), { precision: "double" }), this._raw = e.slice();
|
|
@@ -101,19 +101,90 @@ var S = {
|
|
|
101
101
|
return e[0] = 251, e.set(this._raw, 1), e;
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
|
-
function
|
|
105
|
-
if (e.length === 2) return new
|
|
106
|
-
if (e.length === 4) return new
|
|
107
|
-
if (e.length === 8) return new
|
|
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
108
|
throw SyntaxError(`float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${e.length} bytes`);
|
|
109
109
|
}
|
|
110
|
-
|
|
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 = 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 = 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 = 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 = 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 = {
|
|
111
173
|
appStringPrefixes: ["float"],
|
|
112
|
-
parseAppString(e, n) {
|
|
113
|
-
let
|
|
114
|
-
if (!/^[0-9a-fA-F]*$/.test(
|
|
115
|
-
if (
|
|
116
|
-
|
|
174
|
+
parseAppString(e, t, n, r) {
|
|
175
|
+
let i = v(t);
|
|
176
|
+
if (!/^[0-9a-fA-F]*$/.test(i)) throw SyntaxError("float'...' contains non-hex characters");
|
|
177
|
+
if (i.length % 2 != 0) throw SyntaxError(`float'...' hex content has odd length (${i.length} digits)`);
|
|
178
|
+
let a = _(i), o = r?.encodingWidth;
|
|
179
|
+
if (o === void 0) return O(a);
|
|
180
|
+
if (o !== 1 && o !== 2 && o !== 3) {
|
|
181
|
+
let e = `float'...' encoding indicator _${o} is not valid; use _1, _2, or _3`;
|
|
182
|
+
if (n) return n(e), O(a);
|
|
183
|
+
throw SyntaxError(e);
|
|
184
|
+
}
|
|
185
|
+
return o === (a.length === 2 ? 1 : a.length === 4 ? 2 : 3) ? O(a) : M(a, o, n ?? ((e) => {
|
|
186
|
+
throw SyntaxError(e);
|
|
187
|
+
}));
|
|
117
188
|
},
|
|
118
189
|
parseAppSequence(e, t, n) {
|
|
119
190
|
if (t.length === 0) throw SyntaxError("float<<...>> requires exactly one byte-string item");
|
|
@@ -122,37 +193,37 @@ var O = {
|
|
|
122
193
|
if (n) n(e);
|
|
123
194
|
else throw SyntaxError(e);
|
|
124
195
|
}
|
|
125
|
-
if (!(t[0] instanceof
|
|
126
|
-
return
|
|
196
|
+
if (!(t[0] instanceof l)) throw SyntaxError("float<<...>> item must be a byte string");
|
|
197
|
+
return O(t[0].value);
|
|
127
198
|
}
|
|
128
199
|
};
|
|
129
200
|
//#endregion
|
|
130
201
|
//#region src/extensions/same.ts
|
|
131
|
-
function
|
|
202
|
+
function P(e, t) {
|
|
132
203
|
if (e.length !== t.length) return !1;
|
|
133
204
|
for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
|
|
134
205
|
return !0;
|
|
135
206
|
}
|
|
136
|
-
var
|
|
207
|
+
var F = {
|
|
137
208
|
appStringPrefixes: ["same"],
|
|
138
209
|
preserveAppSeqSource: !0,
|
|
139
210
|
parseAppSequence(e, t, n) {
|
|
140
211
|
if (t.length === 0) throw SyntaxError("same<<...>> requires at least one item");
|
|
141
212
|
let r = t[0], i = r.toCBOR();
|
|
142
|
-
for (let e = 1; e < t.length; e++) if (!
|
|
213
|
+
for (let e = 1; e < t.length; e++) if (!P(i, t[e].toCBOR())) {
|
|
143
214
|
let t = `same<<...>>: item ${e} produces different CBOR bytes than item 0`;
|
|
144
215
|
if (n) n(t);
|
|
145
216
|
else throw SyntaxError(t);
|
|
146
217
|
}
|
|
147
218
|
return r;
|
|
148
219
|
}
|
|
149
|
-
},
|
|
150
|
-
static OMIT =
|
|
220
|
+
}, I = class e {
|
|
221
|
+
static OMIT = i;
|
|
151
222
|
static TAG = r;
|
|
152
|
-
static Tag =
|
|
153
|
-
static Simple =
|
|
154
|
-
static MapEntries =
|
|
155
|
-
static dt_as_Date =
|
|
223
|
+
static Tag = d;
|
|
224
|
+
static Simple = s;
|
|
225
|
+
static MapEntries = h;
|
|
226
|
+
static dt_as_Date = c;
|
|
156
227
|
#e;
|
|
157
228
|
constructor(e) {
|
|
158
229
|
this.#e = e ?? {};
|
|
@@ -211,7 +282,7 @@ var A = {
|
|
|
211
282
|
stringify(t, n, r) {
|
|
212
283
|
if (typeof n == "function" || Array.isArray(n) || n === null || n === void 0 && r !== void 0) {
|
|
213
284
|
let i = { ...this.#e };
|
|
214
|
-
return n === null ? i.replacer = void 0 : (typeof n == "function" || Array.isArray(n)) && (i.replacer = n), r !== void 0 && (i.indent =
|
|
285
|
+
return n === null ? i.replacer = void 0 : (typeof n == "function" || Array.isArray(n)) && (i.replacer = n), r !== void 0 && (i.indent = B(r)), e.stringify(t, i);
|
|
215
286
|
}
|
|
216
287
|
return e.stringify(t, this.#t(n ?? void 0));
|
|
217
288
|
}
|
|
@@ -219,23 +290,23 @@ var A = {
|
|
|
219
290
|
return e.format(t, this.#t(n));
|
|
220
291
|
}
|
|
221
292
|
static fromCBOR(e, t) {
|
|
222
|
-
return
|
|
293
|
+
return u(e, t);
|
|
223
294
|
}
|
|
224
295
|
static fromCDN(e, t) {
|
|
225
|
-
return
|
|
296
|
+
return m(e, t);
|
|
226
297
|
}
|
|
227
298
|
static fromEDN(t, n) {
|
|
228
299
|
return e.fromCDN(t, n);
|
|
229
300
|
}
|
|
230
301
|
static fromJS(e, t) {
|
|
231
|
-
return
|
|
302
|
+
return p(e, t);
|
|
232
303
|
}
|
|
233
304
|
static fromHexDump(e, t) {
|
|
234
|
-
let n = [], r =
|
|
305
|
+
let n = [], r = L(e).trim().split(/\s+/).filter(Boolean);
|
|
235
306
|
for (let e of r) if (/^[0-9A-Fa-f]{2}$/.test(e)) n.push(parseInt(e, 16));
|
|
236
307
|
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));
|
|
237
308
|
else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);
|
|
238
|
-
return
|
|
309
|
+
return u(new Uint8Array(n), t);
|
|
239
310
|
}
|
|
240
311
|
static decode(t, n) {
|
|
241
312
|
return e.fromCBOR(t, n).toJS(n);
|
|
@@ -260,70 +331,70 @@ var A = {
|
|
|
260
331
|
}
|
|
261
332
|
static stringify(e, t, n) {
|
|
262
333
|
if (typeof t == "function" || Array.isArray(t) || t === null || t === void 0 && n !== void 0) {
|
|
263
|
-
let r = typeof t == "function" || Array.isArray(t) ? t : void 0,
|
|
334
|
+
let r = typeof t == "function" || Array.isArray(t) ? t : void 0, a = B(n);
|
|
264
335
|
if (r) {
|
|
265
|
-
let t =
|
|
266
|
-
return t === void 0 || t ===
|
|
336
|
+
let t = f(e, r);
|
|
337
|
+
return t === void 0 || t === i ? void 0 : p(t).toCDN(a === void 0 ? void 0 : { indent: a });
|
|
267
338
|
}
|
|
268
|
-
return
|
|
339
|
+
return p(e).toCDN(a === void 0 ? void 0 : { indent: a });
|
|
269
340
|
}
|
|
270
341
|
let r = t;
|
|
271
342
|
if (r?.replacer) {
|
|
272
|
-
let t =
|
|
273
|
-
if (t === void 0 || t ===
|
|
274
|
-
let { replacer: n, ...
|
|
275
|
-
return
|
|
343
|
+
let t = f(e, r.replacer, r.extensions, r.undefinedOmits);
|
|
344
|
+
if (t === void 0 || t === i) return;
|
|
345
|
+
let { replacer: n, ...a } = r;
|
|
346
|
+
return p(t, Object.keys(a).length > 0 ? a : void 0).toCDN(r);
|
|
276
347
|
}
|
|
277
|
-
return
|
|
348
|
+
return p(e, r).toCDN(r);
|
|
278
349
|
}
|
|
279
350
|
static format(t, n) {
|
|
280
351
|
return e.fromCDN(t, n).toCDN(n);
|
|
281
352
|
}
|
|
282
353
|
};
|
|
283
|
-
function
|
|
354
|
+
function L(e) {
|
|
284
355
|
let t = "", n = 0;
|
|
285
356
|
for (; n < e.length;) {
|
|
286
357
|
let r = e[n], i = e[n + 1] ?? "";
|
|
287
358
|
if (r === "-" && i === "-") {
|
|
288
|
-
n =
|
|
359
|
+
n = R(e, n + 2), t += " ";
|
|
289
360
|
continue;
|
|
290
361
|
}
|
|
291
362
|
if (r === "—") {
|
|
292
|
-
n =
|
|
363
|
+
n = R(e, n + 1), t += " ";
|
|
293
364
|
continue;
|
|
294
365
|
}
|
|
295
366
|
if (r === "#") {
|
|
296
|
-
n =
|
|
367
|
+
n = R(e, n + 1), t += " ";
|
|
297
368
|
continue;
|
|
298
369
|
}
|
|
299
370
|
if (r === "/" && i === "/") {
|
|
300
|
-
n =
|
|
371
|
+
n = R(e, n + 2), t += " ";
|
|
301
372
|
continue;
|
|
302
373
|
}
|
|
303
374
|
if (r === "/" && i === "*") {
|
|
304
375
|
let r = e.indexOf("*/", n + 2);
|
|
305
376
|
if (r < 0) throw SyntaxError("Unterminated comment in hex dump");
|
|
306
|
-
t +=
|
|
377
|
+
t += z(e.slice(n, r + 2)), n = r + 2;
|
|
307
378
|
continue;
|
|
308
379
|
}
|
|
309
380
|
if (r === "/") {
|
|
310
381
|
let r = e.indexOf("/", n + 1);
|
|
311
382
|
if (r < 0) throw SyntaxError("Unterminated comment in hex dump");
|
|
312
|
-
t +=
|
|
383
|
+
t += z(e.slice(n, r + 1)), n = r + 1;
|
|
313
384
|
continue;
|
|
314
385
|
}
|
|
315
386
|
t += r, n++;
|
|
316
387
|
}
|
|
317
388
|
return t;
|
|
318
389
|
}
|
|
319
|
-
function
|
|
390
|
+
function R(e, t) {
|
|
320
391
|
let n = e.indexOf("\n", t);
|
|
321
392
|
return n < 0 ? e.length : n;
|
|
322
393
|
}
|
|
323
|
-
function
|
|
394
|
+
function z(e) {
|
|
324
395
|
return e.replace(/[^\r\n]/g, " ");
|
|
325
396
|
}
|
|
326
|
-
function
|
|
397
|
+
function B(e) {
|
|
327
398
|
if (typeof e == "number") {
|
|
328
399
|
let t = Math.floor(Math.min(10, Math.max(0, e)));
|
|
329
400
|
return t === 0 ? void 0 : t;
|
|
@@ -331,6 +402,6 @@ function F(e) {
|
|
|
331
402
|
if (typeof e == "string") return e.slice(0, 10) || void 0;
|
|
332
403
|
}
|
|
333
404
|
//#endregion
|
|
334
|
-
export {
|
|
405
|
+
export { I as CBOR, I as default, i as CBOR_OMIT, r as CBOR_TAG, e as CdnSyntaxError, h as MapEntries, a as Null, s as Simple, d as Tag, t as Undefined, C as b32, c as dt_as_Date, N as float, w as h32, F as same };
|
|
335
406
|
|
|
336
407
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#defaults","#merge"],"sources":["../src/utils/strip-comments.ts","../src/extensions/b32.ts","../src/extensions/float.ts","../src/extensions/same.ts","../src/cbor.ts"],"sourcesContent":["/**\n * Strip whitespace and EDN §2.2 comments from app-string content.\n *\n * Used by extensions whose content allows the same comment syntax as byte\n * string literals (b32, h32, float, …):\n * SP / LF / CR — whitespace, skipped\n * # … LF — line comment\n * // … LF — line comment\n * /* … *\\/ — block comment (unterminated → SyntaxError)\n * / … / — block comment (unterminated → SyntaxError)\n */\nexport function stripComments(str: string): string {\n let out = '';\n let i = 0;\n while (i < str.length) {\n const ch = str[i];\n if (ch === ' ' || ch === '\\n' || ch === '\\r') {\n i++;\n continue;\n }\n if (ch === '#') {\n while (i < str.length && str[i] !== '\\n') i++;\n continue;\n }\n if (ch === '/') {\n const next = str[i + 1] ?? '';\n if (next === '/') {\n while (i < str.length && str[i] !== '\\n') i++;\n continue;\n }\n if (next === '*') {\n i += 2;\n while (\n i < str.length &&\n !(str[i] === '*' && (str[i + 1] ?? '') === '/')\n )\n i++;\n if (i >= str.length)\n throw new SyntaxError('unterminated block comment');\n i += 2; // consume */\n continue;\n }\n // / … / block comment\n i++;\n while (i < str.length && str[i] !== '/') i++;\n if (i >= str.length) throw new SyntaxError('unterminated block comment');\n i++; // consume closing /\n continue;\n }\n out += ch;\n i++;\n }\n return out;\n}\n","import type { CborExtension } from './types';\nimport { CborByteString } from '../ast/CborByteString';\nimport { stripComments } from '../utils/strip-comments';\n\nconst B32_ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';\nconst H32_ALPHA = '0123456789ABCDEFGHIJKLMNOPQRSTUV';\n\nfunction stripBase32Padding(str: string): string {\n let end = str.length;\n while (end > 0 && str.charCodeAt(end - 1) === 0x3d) end--;\n return str.slice(0, end);\n}\n\nfunction base32Decode(\n str: string,\n alpha: string,\n onError?: (msg: string) => void\n): Uint8Array {\n // Padding is optional; strip it before decoding.\n const s = stripBase32Padding(str).toUpperCase();\n // RFC 4648 §6: valid unpadded lengths mod 8 are 0, 2, 4, 5, 7.\n // Lengths 1, 3, 6 can never result from any valid byte sequence.\n const rem = s.length % 8;\n if (rem === 1 || rem === 3 || rem === 6)\n throw new SyntaxError(`invalid base32 length: ${s.length} characters`);\n const lookup = new Uint8Array(128).fill(0xff);\n for (let i = 0; i < alpha.length; i++) lookup[alpha.charCodeAt(i)] = i;\n const out = new Uint8Array(Math.floor((s.length * 5) / 8));\n let buf = 0,\n bufBits = 0,\n outIdx = 0;\n for (const ch of s) {\n const code = ch.charCodeAt(0);\n const val = code < 128 ? lookup[code] : 0xff;\n if (val === 0xff)\n throw new SyntaxError(\n `invalid character in byte string: ${JSON.stringify(ch)}`\n );\n buf = (buf << 5) | val;\n bufBits += 5;\n if (bufBits >= 8) {\n bufBits -= 8;\n out[outIdx++] = (buf >> bufBits) & 0xff;\n }\n }\n // RFC 4648 §3.5: trailing bits in the final quantum must be zero.\n if (bufBits > 0 && (buf & ((1 << bufBits) - 1)) !== 0) {\n const msg = 'non-zero trailing bits in base32 input';\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n return out;\n}\n\n/** RFC 4648 §6 Base32 (A–Z 2–7) app-string extension. */\nexport const b32: CborExtension = {\n appStringPrefixes: ['b32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), B32_ALPHA, onError),\n {\n ednEncoding: 'base32',\n }\n );\n },\n};\n\n/** RFC 4648 §7 Base32Hex (0–9 A–V) app-string extension. */\nexport const h32: CborExtension = {\n appStringPrefixes: ['h32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), H32_ALPHA, onError),\n {\n ednEncoding: 'base32hex',\n }\n );\n },\n};\n","/**\n * `float'...'` / `float<<...>>` app-string extension.\n *\n * Interprets a hex bit-pattern as an IEEE 754 floating-point value:\n * - 4 hex digits (2 bytes) → float16 (CBOR major-7, additional 25 / 0xf9)\n * - 8 hex digits (4 bytes) → float32 (CBOR major-7, additional 26 / 0xfa)\n * - 16 hex digits (8 bytes) → float64 (CBOR major-7, additional 27 / 0xfb)\n *\n * The string form `float'...'` supports the same comment syntax as `h'...'`:\n * slash-delimited block comments, C-style block comments, line comments (`//`\n * and `#`). The extension strips comments from the raw content itself.\n *\n * The sequence form `float<<byteStr>>` accepts a single byte-string expression\n * (e.g. `float<<h'7ef0'>>`) and interprets its bytes as float bits.\n *\n * This extension is NOT part of draft-ietf-cbor-edn-literals and is not\n * included in the default extension set. Add it explicitly:\n *\n * @example\n * import { float } from '@cbortech/cbor';\n * parseCDN(\"float'7ef0'\", { extensions: [float] }); // NaN as float16\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\nimport { CborFloat } from '../ast/CborFloat';\nimport { CborByteString } from '../ast/CborByteString';\nimport { float16BitsToFloat64 } from '../utils/float16';\nimport { stripComments } from '../utils/strip-comments';\nimport { hexToBytes } from '../utils/hex';\n\n// ── Bit-preserving CborFloat subclasses ───────────────────────────────────────\n// CborFloat stores a JS `number`, which loses NaN payloads. These subclasses\n// override _toCBOR() to emit the original bit pattern verbatim.\n\nclass CborFloat16Bits extends CborFloat {\n private readonly _bits: number;\n constructor(bits: number) {\n super(float16BitsToFloat64(bits), { precision: 'half' });\n this._bits = bits & 0xffff;\n }\n override _toCBOR(): Uint8Array {\n return new Uint8Array([0xf9, (this._bits >> 8) & 0xff, this._bits & 0xff]);\n }\n}\n\nclass CborFloat32Bits extends CborFloat {\n private readonly _raw: Uint8Array;\n constructor(bytes: Uint8Array) {\n super(new DataView(bytes.buffer, bytes.byteOffset).getFloat32(0, false), {\n precision: 'single',\n });\n this._raw = bytes.slice();\n }\n override _toCBOR(): Uint8Array {\n const out = new Uint8Array(5);\n out[0] = 0xfa;\n out.set(this._raw, 1);\n return out;\n }\n}\n\nclass CborFloat64Bits extends CborFloat {\n private readonly _raw: Uint8Array;\n constructor(bytes: Uint8Array) {\n super(new DataView(bytes.buffer, bytes.byteOffset).getFloat64(0, false), {\n precision: 'double',\n });\n this._raw = bytes.slice();\n }\n override _toCBOR(): Uint8Array {\n const out = new Uint8Array(9);\n out[0] = 0xfb;\n out.set(this._raw, 1);\n return out;\n }\n}\n\nfunction floatFromBytes(bytes: Uint8Array): CborFloat {\n if (bytes.length === 2) {\n const bits = (bytes[0]! << 8) | bytes[1]!;\n return new CborFloat16Bits(bits);\n }\n if (bytes.length === 4) return new CborFloat32Bits(bytes);\n if (bytes.length === 8) return new CborFloat64Bits(bytes);\n throw new SyntaxError(\n `float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${bytes.length} bytes`\n );\n}\n\n/**\n * Extension object for `float'...'` / `float<<...>>`.\n * Pass to `parseCDN(..., { extensions: [float] })`.\n */\nexport const float: CborExtension = {\n appStringPrefixes: ['float'],\n\n parseAppString(_prefix: string, content: string): CborItem {\n const hex = stripComments(content);\n if (!/^[0-9a-fA-F]*$/.test(hex))\n throw new SyntaxError(`float'...' contains non-hex characters`);\n if (hex.length % 2 !== 0)\n throw new SyntaxError(\n `float'...' hex content has odd length (${hex.length} digits)`\n );\n return floatFromBytes(hexToBytes(hex));\n },\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(\n `float<<...>> requires exactly one byte-string item`\n );\n if (items.length > 1) {\n const msg = `float<<...>> expects 1 item; got ${items.length} — using first`;\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n if (!(items[0] instanceof CborByteString))\n throw new SyntaxError(`float<<...>> item must be a byte string`);\n return floatFromBytes(items[0].value);\n },\n};\n\nexport default float;\n","/**\n * `same<<expr, expr, ...>>` app-sequence extension.\n *\n * Evaluates every item in the sequence to CBOR bytes and asserts that all\n * produce identical bytes. Returns the first item if all match.\n *\n * In strict mode a mismatch throws a `SyntaxError`. In lenient mode\n * (`strict: false`) a mismatch emits a `ParseWarning` and returns the first\n * item so parsing can continue.\n *\n * `same<<x>>` (single item) is a no-op assertion that always passes.\n *\n * The parsed result is wrapped in `CborAppSeqResult` so that `toCDN()` round-trips\n * the original `same<<...>>` notation. `toCBOR()` and `toJS()` delegate\n * transparently to the inner item; `appStrings: false` produces the resolved value.\n * The result is not directly `instanceof` the inner item's class.\n *\n * This extension is a testing/validation construct from the cabo/edn-abnf\n * corpus and is NOT part of draft-ietf-cbor-edn-literals. It is not included\n * in the default extension set. Add it explicitly:\n *\n * @example\n * import { same } from '@cbortech/cbor';\n * parseCDN(\"same<<b64'AA',h'00'>>\", { extensions: [same] }); // h'00'\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * Extension object for `same<<...>>`.\n * Pass to `parseCDN(..., { extensions: [same] })`.\n */\nexport const same: CborExtension = {\n appStringPrefixes: ['same'],\n preserveAppSeqSource: true,\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(`same<<...>> requires at least one item`);\n const first = items[0]!;\n const firstCbor = first.toCBOR();\n for (let i = 1; i < items.length; i++) {\n const otherCbor = items[i]!.toCBOR();\n if (!bytesEqual(firstCbor, otherCbor)) {\n const msg = `same<<...>>: item ${i} produces different CBOR bytes than item 0`;\n if (onError)\n onError(msg); // lenient: warn + return first item\n else throw new SyntaxError(msg);\n }\n }\n return first;\n },\n};\n\nexport default same;\n","import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromCDNOptions,\n FromHexDumpOptions,\n FromJSOptions,\n ToCBOROptions,\n ToCDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseCDN } from './cdn/parser';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromCDN(text: string, options?: FromCDNOptions): CborItem {\n const node = CBOR.fromCDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n /** @deprecated Use `fromCDN()` instead. */\n fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return this.fromCDN(text, options);\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n /**\n * @deprecated Use `cborToCdn()` or `fromCBOR(input, options).toCDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return this.cborToCdn(input, options);\n }\n\n cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.cborToCdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `cdnToCbor()` or `fromCDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return this.cdnToCbor(text, options);\n }\n\n cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cdnToCbor(text, this.#merge(options));\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToCDNOptions = {\n ...(this.#defaults as FromJSOptions & ToCDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return parseCDN(text, options);\n }\n\n /**\n * Parse a CDN text string into an AST node.\n *\n * @deprecated Use `fromCDN()` instead.\n */\n static fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return CBOR.fromCDN(text, options);\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n */\n static cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n *\n * @deprecated Use `CBOR.cborToCdn()` or `CBOR.fromCBOR(input, options).toCDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.cborToCdn(input, options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n */\n static cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.cdnToCbor()` or `CBOR.fromCDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cdnToCbor(text, options);\n }\n\n /**\n * Parse a CDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the CDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromCDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromCDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToCDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToCDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToCDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toCDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toCDN(opts);\n }\n\n /** Normalize a CDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.fromCDN(text, options).toCDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '—') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\n/** Map JSON.stringify `space` argument to ToCDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":";;;AAWA,SAAgB,EAAc,GAAqB;CACjD,IAAI,IAAM,IACN,IAAI;CACR,OAAO,IAAI,EAAI,SAAQ;EACrB,IAAM,IAAK,EAAI;EACf,IAAI,MAAO,OAAO,MAAO,QAAQ,MAAO,MAAM;GAC5C;GACA;EACF;EACA,IAAI,MAAO,KAAK;GACd,OA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pC,OAAO,IAAM,IAAI,EAAK,SAAS;AACjC;AAEA,SAAS,EAAe,GAAsB;CAC5C,OAAO,EAAK,QAAQ,YAAY,GAAG;AACrC;AAKA,SAAS,EACP,GAC6B;CAC7B,IAAI,OAAO,KAAU,UAAU;EAC7B,IAAM,IAAI,KAAK,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG,CAAK,CAAC,CAAC;EACrD,OAAO,MAAM,IAAI,KAAA,IAAY;CAC/B;CACA,IAAI,OAAO,KAAU,UAEnB,OADU,EAAM,MAAM,GAAG,EAClB,KAAK,KAAA;AAGhB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["#defaults","#merge"],"sources":["../src/utils/strip-comments.ts","../src/extensions/b32.ts","../src/extensions/float.ts","../src/extensions/same.ts","../src/cbor.ts"],"sourcesContent":["/**\n * Strip whitespace and EDN §2.2 comments from app-string content.\n *\n * Used by extensions whose content allows the same comment syntax as byte\n * string literals (b32, h32, float, …):\n * SP / LF / CR — whitespace, skipped\n * # … LF — line comment\n * // … LF — line comment\n * /* … *\\/ — block comment (unterminated → SyntaxError)\n * / … / — block comment (unterminated → SyntaxError)\n */\nexport function stripComments(str: string): string {\n let out = '';\n let i = 0;\n while (i < str.length) {\n const ch = str[i];\n if (ch === ' ' || ch === '\\n' || ch === '\\r') {\n i++;\n continue;\n }\n if (ch === '#') {\n while (i < str.length && str[i] !== '\\n') i++;\n continue;\n }\n if (ch === '/') {\n const next = str[i + 1] ?? '';\n if (next === '/') {\n while (i < str.length && str[i] !== '\\n') i++;\n continue;\n }\n if (next === '*') {\n i += 2;\n while (\n i < str.length &&\n !(str[i] === '*' && (str[i + 1] ?? '') === '/')\n )\n i++;\n if (i >= str.length)\n throw new SyntaxError('unterminated block comment');\n i += 2; // consume */\n continue;\n }\n // / … / block comment\n i++;\n while (i < str.length && str[i] !== '/') i++;\n if (i >= str.length) throw new SyntaxError('unterminated block comment');\n i++; // consume closing /\n continue;\n }\n out += ch;\n i++;\n }\n return out;\n}\n","import type { CborExtension } from './types';\nimport { CborByteString } from '../ast/CborByteString';\nimport { stripComments } from '../utils/strip-comments';\n\nconst B32_ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';\nconst H32_ALPHA = '0123456789ABCDEFGHIJKLMNOPQRSTUV';\n\nfunction stripBase32Padding(str: string): string {\n let end = str.length;\n while (end > 0 && str.charCodeAt(end - 1) === 0x3d) end--;\n return str.slice(0, end);\n}\n\nfunction base32Decode(\n str: string,\n alpha: string,\n onError?: (msg: string) => void\n): Uint8Array {\n // Padding is optional; strip it before decoding.\n const s = stripBase32Padding(str).toUpperCase();\n // RFC 4648 §6: valid unpadded lengths mod 8 are 0, 2, 4, 5, 7.\n // Lengths 1, 3, 6 can never result from any valid byte sequence.\n const rem = s.length % 8;\n if (rem === 1 || rem === 3 || rem === 6)\n throw new SyntaxError(`invalid base32 length: ${s.length} characters`);\n const lookup = new Uint8Array(128).fill(0xff);\n for (let i = 0; i < alpha.length; i++) lookup[alpha.charCodeAt(i)] = i;\n const out = new Uint8Array(Math.floor((s.length * 5) / 8));\n let buf = 0,\n bufBits = 0,\n outIdx = 0;\n for (const ch of s) {\n const code = ch.charCodeAt(0);\n const val = code < 128 ? lookup[code] : 0xff;\n if (val === 0xff)\n throw new SyntaxError(\n `invalid character in byte string: ${JSON.stringify(ch)}`\n );\n buf = (buf << 5) | val;\n bufBits += 5;\n if (bufBits >= 8) {\n bufBits -= 8;\n out[outIdx++] = (buf >> bufBits) & 0xff;\n }\n }\n // RFC 4648 §3.5: trailing bits in the final quantum must be zero.\n if (bufBits > 0 && (buf & ((1 << bufBits) - 1)) !== 0) {\n const msg = 'non-zero trailing bits in base32 input';\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n return out;\n}\n\n/** RFC 4648 §6 Base32 (A–Z 2–7) app-string extension. */\nexport const b32: CborExtension = {\n appStringPrefixes: ['b32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), B32_ALPHA, onError),\n {\n ednEncoding: 'base32',\n }\n );\n },\n};\n\n/** RFC 4648 §7 Base32Hex (0–9 A–V) app-string extension. */\nexport const h32: CborExtension = {\n appStringPrefixes: ['h32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), H32_ALPHA, onError),\n {\n ednEncoding: 'base32hex',\n }\n );\n },\n};\n","/**\n * `float'...'` / `float<<...>>` app-string extension.\n *\n * Interprets a hex bit-pattern as an IEEE 754 floating-point value:\n * - 4 hex digits (2 bytes) → float16 (CBOR major-7, additional 25 / 0xf9)\n * - 8 hex digits (4 bytes) → float32 (CBOR major-7, additional 26 / 0xfa)\n * - 16 hex digits (8 bytes) → float64 (CBOR major-7, additional 27 / 0xfb)\n *\n * The string form `float'...'` supports the same comment syntax as `h'...'`:\n * slash-delimited block comments, C-style block comments, line comments (`//`\n * and `#`). The extension strips comments from the raw content itself.\n *\n * The sequence form `float<<byteStr>>` accepts a single byte-string expression\n * (e.g. `float<<h'7ef0'>>`) and interprets its bytes as float bits.\n *\n * Defined in draft-ietf-cbor-edn-literals §3.7. Not included in the default\n * extension set (must be added explicitly):\n *\n * @example\n * import { float } from '@cbortech/cbor';\n * parseCDN(\"float'7ef0'\", { extensions: [float] }); // NaN as float16\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\nimport { CborFloat } from '../ast/CborFloat';\nimport { CborByteString } from '../ast/CborByteString';\nimport { float16BitsToFloat64, float64ToFloat16Bits } from '../utils/float16';\nimport { stripComments } from '../utils/strip-comments';\nimport { hexToBytes } from '../utils/hex';\nimport type { EncodingWidth } from '../cbor/encode';\n\n// ── Bit-preserving CborFloat subclasses ───────────────────────────────────────\n// CborFloat stores a JS `number`, which loses NaN payloads. These subclasses\n// override _toCBOR() to emit the original bit pattern verbatim.\n\nclass CborFloat16Bits extends CborFloat {\n private readonly _bits: number;\n constructor(bits: number) {\n super(float16BitsToFloat64(bits), { precision: 'half' });\n this._bits = bits & 0xffff;\n }\n override _toCBOR(): Uint8Array {\n return new Uint8Array([0xf9, (this._bits >> 8) & 0xff, this._bits & 0xff]);\n }\n}\n\nclass CborFloat32Bits extends CborFloat {\n private readonly _raw: Uint8Array;\n constructor(bytes: Uint8Array) {\n super(new DataView(bytes.buffer, bytes.byteOffset).getFloat32(0, false), {\n precision: 'single',\n });\n this._raw = bytes.slice();\n }\n override _toCBOR(): Uint8Array {\n const out = new Uint8Array(5);\n out[0] = 0xfa;\n out.set(this._raw, 1);\n return out;\n }\n}\n\nclass CborFloat64Bits extends CborFloat {\n private readonly _raw: Uint8Array;\n constructor(bytes: Uint8Array) {\n super(new DataView(bytes.buffer, bytes.byteOffset).getFloat64(0, false), {\n precision: 'double',\n });\n this._raw = bytes.slice();\n }\n override _toCBOR(): Uint8Array {\n const out = new Uint8Array(9);\n out[0] = 0xfb;\n out.set(this._raw, 1);\n return out;\n }\n}\n\nfunction floatFromBytes(bytes: Uint8Array): CborFloat {\n if (bytes.length === 2) {\n const bits = (bytes[0]! << 8) | bytes[1]!;\n return new CborFloat16Bits(bits);\n }\n if (bytes.length === 4) return new CborFloat32Bits(bytes);\n if (bytes.length === 8) return new CborFloat64Bits(bytes);\n throw new SyntaxError(\n `float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${bytes.length} bytes`\n );\n}\n\n/** Expand float16 bit pattern to 4-byte float32 (bit-exact, preserves NaN payloads). */\nfunction float16BitsToFloat32Bytes(bits16: number): Uint8Array {\n const sign = (bits16 >>> 15) & 1;\n const exp16 = (bits16 >>> 10) & 0x1f;\n const mant16 = bits16 & 0x3ff;\n let bits32: number;\n if (exp16 === 0x1f) {\n bits32 = (sign << 31) | 0x7f800000 | (mant16 << 13);\n } else if (exp16 === 0 && mant16 === 0) {\n bits32 = sign << 31;\n } else if (exp16 === 0) {\n // Denormal float16 → normal float32\n let m = mant16;\n let shifts = 0;\n while ((m & 0x200) === 0) {\n m <<= 1;\n shifts++;\n }\n bits32 = (sign << 31) | ((112 - shifts) << 23) | ((m & 0x1ff) << 14);\n } else {\n bits32 = (sign << 31) | ((exp16 + 112) << 23) | (mant16 << 13);\n }\n const out = new Uint8Array(4);\n new DataView(out.buffer).setUint32(0, bits32 >>> 0, false);\n return out;\n}\n\n/** Expand float16 bit pattern to 8-byte float64 (bit-exact, preserves NaN payloads). */\nfunction float16BitsToFloat64Bytes(bits16: number): Uint8Array {\n const sign = (bits16 >>> 15) & 1;\n const exp16 = (bits16 >>> 10) & 0x1f;\n const mant16 = bits16 & 0x3ff;\n const out = new Uint8Array(8);\n const dv = new DataView(out.buffer);\n if (exp16 === 0x1f) {\n dv.setUint32(0, ((sign << 31) | 0x7ff00000 | (mant16 << 10)) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else if (exp16 === 0 && mant16 === 0) {\n dv.setUint32(0, (sign << 31) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else if (exp16 === 0) {\n // Denormal float16 → normal float64\n let m = mant16;\n let shifts = 0;\n while ((m & 0x200) === 0) {\n m <<= 1;\n shifts++;\n }\n dv.setUint32(\n 0,\n ((sign << 31) | ((1008 - shifts) << 20) | ((m & 0x1ff) << 11)) >>> 0,\n false\n );\n dv.setUint32(4, 0, false);\n } else {\n dv.setUint32(\n 0,\n ((sign << 31) | ((exp16 + 1008) << 20) | (mant16 << 10)) >>> 0,\n false\n );\n dv.setUint32(4, 0, false);\n }\n return out;\n}\n\n/** Expand float32 bit pattern to 8-byte float64 (bit-exact, preserves NaN payloads). */\nfunction float32BitsToFloat64Bytes(bytes4: Uint8Array): Uint8Array {\n const bits32 = new DataView(bytes4.buffer, bytes4.byteOffset).getUint32(\n 0,\n false\n );\n const sign = (bits32 >>> 31) & 1;\n const exp32 = (bits32 >>> 23) & 0xff;\n const mant32 = bits32 & 0x7fffff;\n const out = new Uint8Array(8);\n const dv = new DataView(out.buffer);\n if (exp32 === 0xff) {\n dv.setUint32(0, ((sign << 31) | 0x7ff00000 | (mant32 >>> 3)) >>> 0, false);\n dv.setUint32(4, (mant32 & 7) << 29, false);\n } else if (exp32 === 0 && mant32 === 0) {\n dv.setUint32(0, (sign << 31) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else {\n // Normal or denormal: JS arithmetic is exact (float32 ⊂ float64), NaN handled above.\n const f64 = new DataView(bytes4.buffer, bytes4.byteOffset).getFloat32(\n 0,\n false\n );\n dv.setFloat64(0, f64, false);\n }\n return out;\n}\n\n/**\n * Re-encode float bytes at a target precision (_1=half, _2=single, _3=double).\n * Returns undefined if the conversion is lossy (caller should warn).\n */\nfunction reencodeFloat(\n bytes: Uint8Array,\n targetWidth: 1 | 2 | 3,\n onError: (msg: string) => void\n): CborFloat {\n const naturalWidth = bytes.length === 2 ? 1 : bytes.length === 4 ? 2 : 3;\n\n if (naturalWidth === 1) {\n const bits16 = (bytes[0]! << 8) | bytes[1]!;\n if (targetWidth === 2)\n return new CborFloat32Bits(float16BitsToFloat32Bytes(bits16));\n if (targetWidth === 3)\n return new CborFloat64Bits(float16BitsToFloat64Bytes(bits16));\n }\n\n if (naturalWidth === 2) {\n if (targetWidth === 3)\n return new CborFloat64Bits(float32BitsToFloat64Bytes(bytes));\n if (targetWidth === 1) {\n const f32 = new DataView(bytes.buffer, bytes.byteOffset).getFloat32(\n 0,\n false\n );\n const bits16 = float64ToFloat16Bits(f32);\n if (!Object.is(float16BitsToFloat64(bits16), f32) && !isNaN(f32)) {\n onError(\n `float'...' value cannot be exactly represented as float16 (_1)`\n );\n }\n return new CborFloat16Bits(bits16);\n }\n }\n\n if (naturalWidth === 3) {\n const f64 = new DataView(bytes.buffer, bytes.byteOffset).getFloat64(\n 0,\n false\n );\n if (targetWidth === 1) {\n const bits16 = float64ToFloat16Bits(f64);\n if (!Object.is(float16BitsToFloat64(bits16), f64) && !isNaN(f64)) {\n onError(\n `float'...' value cannot be exactly represented as float16 (_1)`\n );\n }\n return new CborFloat16Bits(bits16);\n }\n if (targetWidth === 2) {\n const f32 = Math.fround(f64);\n if (!Object.is(f32, f64) && !isNaN(f64)) {\n onError(\n `float'...' value cannot be exactly represented as float32 (_2)`\n );\n }\n const out = new Uint8Array(4);\n new DataView(out.buffer).setFloat32(0, f32, false);\n return new CborFloat32Bits(out);\n }\n }\n\n // naturalWidth === targetWidth: identity (already handled by caller)\n return floatFromBytes(bytes);\n}\n\n/**\n * Extension object for `float'...'` / `float<<...>>`.\n * Pass to `parseCDN(..., { extensions: [float] })`.\n */\nexport const float: CborExtension = {\n appStringPrefixes: ['float'],\n\n parseAppString(\n _prefix: string,\n content: string,\n onError?: (msg: string) => void,\n options?: { encodingWidth?: EncodingWidth }\n ): CborItem {\n const hex = stripComments(content);\n if (!/^[0-9a-fA-F]*$/.test(hex))\n throw new SyntaxError(`float'...' contains non-hex characters`);\n if (hex.length % 2 !== 0)\n throw new SyntaxError(\n `float'...' hex content has odd length (${hex.length} digits)`\n );\n const bytes = hexToBytes(hex);\n const ew = options?.encodingWidth;\n if (ew === undefined) return floatFromBytes(bytes);\n if (ew !== 1 && ew !== 2 && ew !== 3) {\n const msg = `float'...' encoding indicator _${ew} is not valid; use _1, _2, or _3`;\n if (onError) {\n onError(msg);\n return floatFromBytes(bytes);\n }\n throw new SyntaxError(msg);\n }\n const naturalWidth = bytes.length === 2 ? 1 : bytes.length === 4 ? 2 : 3;\n if (ew === naturalWidth) return floatFromBytes(bytes);\n const fallbackOnError =\n onError ??\n ((msg: string) => {\n throw new SyntaxError(msg);\n });\n return reencodeFloat(bytes, ew, fallbackOnError);\n },\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(\n `float<<...>> requires exactly one byte-string item`\n );\n if (items.length > 1) {\n const msg = `float<<...>> expects 1 item; got ${items.length} — using first`;\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n if (!(items[0] instanceof CborByteString))\n throw new SyntaxError(`float<<...>> item must be a byte string`);\n return floatFromBytes(items[0].value);\n },\n};\n\nexport default float;\n","/**\n * `same<<expr, expr, ...>>` app-sequence extension.\n *\n * Evaluates every item in the sequence to CBOR bytes and asserts that all\n * produce identical bytes. Returns the first item if all match.\n *\n * In strict mode a mismatch throws a `SyntaxError`. In lenient mode\n * (`strict: false`) a mismatch emits a `ParseWarning` and returns the first\n * item so parsing can continue.\n *\n * `same<<x>>` (single item) is a no-op assertion that always passes.\n *\n * The parsed result is wrapped in `CborAppSeqResult` so that `toCDN()` round-trips\n * the original `same<<...>>` notation. `toCBOR()` and `toJS()` delegate\n * transparently to the inner item; `appStrings: false` produces the resolved value.\n * The result is not directly `instanceof` the inner item's class.\n *\n * This extension is a testing/validation construct from the cabo/edn-abnf\n * corpus and is NOT part of draft-ietf-cbor-edn-literals. It is not included\n * in the default extension set. Add it explicitly:\n *\n * @example\n * import { same } from '@cbortech/cbor';\n * parseCDN(\"same<<b64'AA',h'00'>>\", { extensions: [same] }); // h'00'\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * Extension object for `same<<...>>`.\n * Pass to `parseCDN(..., { extensions: [same] })`.\n */\nexport const same: CborExtension = {\n appStringPrefixes: ['same'],\n preserveAppSeqSource: true,\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(`same<<...>> requires at least one item`);\n const first = items[0]!;\n const firstCbor = first.toCBOR();\n for (let i = 1; i < items.length; i++) {\n const otherCbor = items[i]!.toCBOR();\n if (!bytesEqual(firstCbor, otherCbor)) {\n const msg = `same<<...>>: item ${i} produces different CBOR bytes than item 0`;\n if (onError)\n onError(msg); // lenient: warn + return first item\n else throw new SyntaxError(msg);\n }\n }\n return first;\n },\n};\n\nexport default same;\n","import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromCDNOptions,\n FromHexDumpOptions,\n FromJSOptions,\n ToCBOROptions,\n ToCDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseCDN } from './cdn/parser';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromCDN(text: string, options?: FromCDNOptions): CborItem {\n const node = CBOR.fromCDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n /** @deprecated Use `fromCDN()` instead. */\n fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return this.fromCDN(text, options);\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n /**\n * @deprecated Use `cborToCdn()` or `fromCBOR(input, options).toCDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return this.cborToCdn(input, options);\n }\n\n cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.cborToCdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `cdnToCbor()` or `fromCDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return this.cdnToCbor(text, options);\n }\n\n cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cdnToCbor(text, this.#merge(options));\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToCDNOptions = {\n ...(this.#defaults as FromJSOptions & ToCDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return parseCDN(text, options);\n }\n\n /**\n * Parse a CDN text string into an AST node.\n *\n * @deprecated Use `fromCDN()` instead.\n */\n static fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return CBOR.fromCDN(text, options);\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n */\n static cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n *\n * @deprecated Use `CBOR.cborToCdn()` or `CBOR.fromCBOR(input, options).toCDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.cborToCdn(input, options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n */\n static cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.cdnToCbor()` or `CBOR.fromCDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cdnToCbor(text, options);\n }\n\n /**\n * Parse a CDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the CDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromCDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromCDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToCDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToCDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToCDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toCDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toCDN(opts);\n }\n\n /** Normalize a CDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.fromCDN(text, options).toCDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '—') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\n/** Map JSON.stringify `space` argument to ToCDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":";;;AAWA,SAAgB,EAAc,GAAqB;CACjD,IAAI,IAAM,IACN,IAAI;CACR,OAAO,IAAI,EAAI,SAAQ;EACrB,IAAM,IAAK,EAAI;EACf,IAAI,MAAO,OAAO,MAAO,QAAQ,MAAO,MAAM;GAC5C;GACA;EACF;EACA,IAAI,MAAO,KAAK;GACd,OAAO,IAAI,EAAI,UAAU,EAAI,OAAO,OAAM;GAC1C;EACF;EACA,IAAI,MAAO,KAAK;GACd,IAAM,IAAO,EAAI,IAAI,MAAM;GAC3B,IAAI,MAAS,KAAK;IAChB,OAAO,IAAI,EAAI,UAAU,EAAI,OAAO,OAAM;IAC1C;GACF;GACA,IAAI,MAAS,KAAK;IAEhB,KADA,KAAK,GAEH,IAAI,EAAI,UACR,EAAE,EAAI,OAAO,QAAQ,EAAI,IAAI,MAAM,QAAQ,OAE3C;IACF,IAAI,KAAK,EAAI,QACX,MAAU,YAAY,4BAA4B;IACpD,KAAK;IACL;GACF;GAGA,KADA,KACO,IAAI,EAAI,UAAU,EAAI,OAAO,MAAK;GACzC,IAAI,KAAK,EAAI,QAAQ,MAAU,YAAY,4BAA4B;GACvE;GACA;EACF;EAEA,AADA,KAAO,GACP;CACF;CACA,OAAO;AACT;;;ACjDA,IAAM,IAAY,oCACZ,IAAY;AAElB,SAAS,EAAmB,GAAqB;CAC/C,IAAI,IAAM,EAAI;CACd,OAAO,IAAM,KAAK,EAAI,WAAW,IAAM,CAAC,MAAM,KAAM;CACpD,OAAO,EAAI,MAAM,GAAG,CAAG;AACzB;AAEA,SAAS,EACP,GACA,GACA,GACY;CAEZ,IAAM,IAAI,EAAmB,CAAG,EAAE,YAAY,GAGxC,IAAM,EAAE,SAAS;CACvB,IAAI,MAAQ,KAAK,MAAQ,KAAK,MAAQ,G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