@cbortech/cbor 0.25.1 → 0.25.3
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 +2 -1
- package/dist/ast/CborArray.d.ts +2 -2
- package/dist/ast/CborByteString.d.ts +2 -2
- package/dist/ast/CborEmbeddedCBOR.d.ts +2 -1
- package/dist/ast/CborFloat.d.ts +2 -1
- package/dist/ast/CborIndefiniteByteString.d.ts +2 -1
- package/dist/ast/CborIndefiniteTextString.d.ts +2 -1
- package/dist/ast/CborItem.d.ts +29 -2
- package/dist/ast/CborMap.d.ts +2 -2
- package/dist/ast/CborNint.d.ts +2 -2
- package/dist/ast/CborSimple.d.ts +2 -1
- package/dist/ast/CborTag.d.ts +2 -2
- package/dist/ast/CborTextString.d.ts +2 -2
- package/dist/ast/CborUint.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cbor/encode.d.ts +38 -4
- package/dist/cdn/tokenizer.d.ts +24 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +85 -89
- package/dist/index.js.map +1 -1
- package/dist/{mapEntries-ZR8QJ0Yj.js → mapEntries-C8HTvn5t.js} +1107 -990
- package/dist/mapEntries-C8HTvn5t.js.map +1 -0
- package/dist/mapEntries-o_ePE8Io.cjs +39 -0
- package/dist/mapEntries-o_ePE8Io.cjs.map +1 -0
- package/dist/utils/hex.d.ts +19 -0
- package/package.json +4 -3
- package/dist/mapEntries-BccT62HT.cjs +0 -36
- package/dist/mapEntries-BccT62HT.cjs.map +0 -1
- package/dist/mapEntries-ZR8QJ0Yj.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as e, D as t, E as n, O as r,
|
|
1
|
+
import { C as e, D as t, E as n, O as r, S as i, T as a, a as o, g as s, i as c, k as l, n as u, r as d, s as f, t as p, v as m, w as h } from "./mapEntries-C8HTvn5t.js";
|
|
2
2
|
//#region src/utils/strip-comments.ts
|
|
3
|
-
function
|
|
3
|
+
function g(e) {
|
|
4
4
|
let t = "", n = 0;
|
|
5
5
|
for (; n < e.length;) {
|
|
6
6
|
let r = e[n];
|
|
@@ -35,14 +35,14 @@ function h(e) {
|
|
|
35
35
|
}
|
|
36
36
|
//#endregion
|
|
37
37
|
//#region src/extensions/b32.ts
|
|
38
|
-
var
|
|
39
|
-
function
|
|
38
|
+
var _ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", v = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
39
|
+
function y(e) {
|
|
40
40
|
let t = e.length;
|
|
41
41
|
for (; t > 0 && e.charCodeAt(t - 1) === 61;) t--;
|
|
42
42
|
return e.slice(0, t);
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
let r =
|
|
44
|
+
function b(e, t, n) {
|
|
45
|
+
let r = y(e).toUpperCase(), i = r.length % 8;
|
|
46
46
|
if (i === 1 || i === 3 || i === 6) throw SyntaxError(`invalid base32 length: ${r.length} characters`);
|
|
47
47
|
let a = new Uint8Array(128).fill(255);
|
|
48
48
|
for (let e = 0; e < t.length; e++) a[t.charCodeAt(e)] = e;
|
|
@@ -59,24 +59,20 @@ function y(e, t, n) {
|
|
|
59
59
|
}
|
|
60
60
|
return o;
|
|
61
61
|
}
|
|
62
|
-
var
|
|
62
|
+
var x = {
|
|
63
63
|
appStringPrefixes: ["b32"],
|
|
64
64
|
parseAppString(e, t, n) {
|
|
65
|
-
return new
|
|
65
|
+
return new s(b(g(t), _, n), { ednEncoding: "base32" });
|
|
66
66
|
}
|
|
67
|
-
},
|
|
67
|
+
}, S = {
|
|
68
68
|
appStringPrefixes: ["h32"],
|
|
69
69
|
parseAppString(e, t, n) {
|
|
70
|
-
return new
|
|
70
|
+
return new s(b(g(t), v, n), { ednEncoding: "base32hex" });
|
|
71
71
|
}
|
|
72
|
-
},
|
|
73
|
-
let t = new Uint8Array(e.length / 2);
|
|
74
|
-
for (let n = 0; n < e.length; n += 2) t[n / 2] = parseInt(e.slice(n, n + 2), 16);
|
|
75
|
-
return t;
|
|
76
|
-
}, C = class extends f {
|
|
72
|
+
}, C = class extends m {
|
|
77
73
|
_bits;
|
|
78
74
|
constructor(e) {
|
|
79
|
-
super(
|
|
75
|
+
super(i(e), { precision: "half" }), this._bits = e & 65535;
|
|
80
76
|
}
|
|
81
77
|
_toCBOR() {
|
|
82
78
|
return new Uint8Array([
|
|
@@ -85,7 +81,7 @@ var b = {
|
|
|
85
81
|
this._bits & 255
|
|
86
82
|
]);
|
|
87
83
|
}
|
|
88
|
-
}, w = class extends
|
|
84
|
+
}, w = class extends m {
|
|
89
85
|
_raw;
|
|
90
86
|
constructor(e) {
|
|
91
87
|
super(new DataView(e.buffer, e.byteOffset).getFloat32(0, !1), { precision: "single" }), this._raw = e.slice();
|
|
@@ -94,7 +90,7 @@ var b = {
|
|
|
94
90
|
let e = new Uint8Array(5);
|
|
95
91
|
return e[0] = 250, e.set(this._raw, 1), e;
|
|
96
92
|
}
|
|
97
|
-
}, T = class extends
|
|
93
|
+
}, T = class extends m {
|
|
98
94
|
_raw;
|
|
99
95
|
constructor(e) {
|
|
100
96
|
super(new DataView(e.buffer, e.byteOffset).getFloat64(0, !1), { precision: "double" }), this._raw = e.slice();
|
|
@@ -112,11 +108,11 @@ function E(e) {
|
|
|
112
108
|
}
|
|
113
109
|
var D = {
|
|
114
110
|
appStringPrefixes: ["float"],
|
|
115
|
-
parseAppString(
|
|
116
|
-
let
|
|
117
|
-
if (!/^[0-9a-fA-F]*$/.test(
|
|
118
|
-
if (
|
|
119
|
-
return E(
|
|
111
|
+
parseAppString(t, n) {
|
|
112
|
+
let r = g(n);
|
|
113
|
+
if (!/^[0-9a-fA-F]*$/.test(r)) throw SyntaxError("float'...' contains non-hex characters");
|
|
114
|
+
if (r.length % 2 != 0) throw SyntaxError(`float'...' hex content has odd length (${r.length} digits)`);
|
|
115
|
+
return E(e(r));
|
|
120
116
|
},
|
|
121
117
|
parseAppSequence(e, t, n) {
|
|
122
118
|
if (t.length === 0) throw SyntaxError("float<<...>> requires exactly one byte-string item");
|
|
@@ -125,7 +121,7 @@ var D = {
|
|
|
125
121
|
if (n) n(e);
|
|
126
122
|
else throw SyntaxError(e);
|
|
127
123
|
}
|
|
128
|
-
if (!(t[0] instanceof
|
|
124
|
+
if (!(t[0] instanceof s)) throw SyntaxError("float<<...>> item must be a byte string");
|
|
129
125
|
return E(t[0].value);
|
|
130
126
|
}
|
|
131
127
|
};
|
|
@@ -149,13 +145,13 @@ var k = {
|
|
|
149
145
|
}
|
|
150
146
|
return r;
|
|
151
147
|
}
|
|
152
|
-
}, A = class
|
|
153
|
-
static OMIT =
|
|
154
|
-
static TAG =
|
|
155
|
-
static Tag =
|
|
156
|
-
static Simple =
|
|
157
|
-
static MapEntries =
|
|
158
|
-
static dt_as_Date =
|
|
148
|
+
}, A = class e {
|
|
149
|
+
static OMIT = a;
|
|
150
|
+
static TAG = n;
|
|
151
|
+
static Tag = r;
|
|
152
|
+
static Simple = h;
|
|
153
|
+
static MapEntries = p;
|
|
154
|
+
static dt_as_Date = o;
|
|
159
155
|
#e;
|
|
160
156
|
constructor(e) {
|
|
161
157
|
this.#e = e ?? {};
|
|
@@ -166,72 +162,72 @@ var k = {
|
|
|
166
162
|
...e ?? {}
|
|
167
163
|
};
|
|
168
164
|
}
|
|
169
|
-
fromCBOR(
|
|
170
|
-
let r =
|
|
165
|
+
fromCBOR(t, n) {
|
|
166
|
+
let r = e.fromCBOR(t, this.#t(n));
|
|
171
167
|
return r._defaults = this.#e, r;
|
|
172
168
|
}
|
|
173
|
-
fromCDN(
|
|
174
|
-
let r =
|
|
169
|
+
fromCDN(t, n) {
|
|
170
|
+
let r = e.fromCDN(t, this.#t(n));
|
|
175
171
|
return r._defaults = this.#e, r;
|
|
176
172
|
}
|
|
177
173
|
fromEDN(e, t) {
|
|
178
174
|
return this.fromCDN(e, t);
|
|
179
175
|
}
|
|
180
|
-
fromJS(
|
|
181
|
-
let r =
|
|
176
|
+
fromJS(t, n) {
|
|
177
|
+
let r = e.fromJS(t, this.#t(n));
|
|
182
178
|
return r._defaults = this.#e, r;
|
|
183
179
|
}
|
|
184
|
-
fromHexDump(
|
|
185
|
-
let r =
|
|
180
|
+
fromHexDump(t, n) {
|
|
181
|
+
let r = e.fromHexDump(t, this.#t(n));
|
|
186
182
|
return r._defaults = this.#e, r;
|
|
187
183
|
}
|
|
188
|
-
decode(
|
|
189
|
-
return
|
|
184
|
+
decode(t, n) {
|
|
185
|
+
return e.decode(t, this.#t(n));
|
|
190
186
|
}
|
|
191
|
-
encode(
|
|
192
|
-
return
|
|
187
|
+
encode(t, n) {
|
|
188
|
+
return e.encode(t, this.#t(n));
|
|
193
189
|
}
|
|
194
190
|
cborToCborEdn(e, t) {
|
|
195
191
|
return this.cborToCdn(e, t);
|
|
196
192
|
}
|
|
197
|
-
cborToCdn(
|
|
198
|
-
return
|
|
193
|
+
cborToCdn(t, n) {
|
|
194
|
+
return e.cborToCdn(t, this.#t(n));
|
|
199
195
|
}
|
|
200
196
|
cborEdnToCbor(e, t) {
|
|
201
197
|
return this.cdnToCbor(e, t);
|
|
202
198
|
}
|
|
203
|
-
cdnToCbor(
|
|
204
|
-
return
|
|
199
|
+
cdnToCbor(t, n) {
|
|
200
|
+
return e.cdnToCbor(t, this.#t(n));
|
|
205
201
|
}
|
|
206
|
-
parse(
|
|
207
|
-
if (typeof
|
|
208
|
-
let r = this.#t({ reviver:
|
|
209
|
-
return
|
|
202
|
+
parse(t, n) {
|
|
203
|
+
if (typeof n == "function") {
|
|
204
|
+
let r = this.#t({ reviver: n });
|
|
205
|
+
return e.fromCDN(t, r).toJS(r);
|
|
210
206
|
}
|
|
211
|
-
let r = this.#t(
|
|
212
|
-
return
|
|
207
|
+
let r = this.#t(n);
|
|
208
|
+
return e.fromCDN(t, r).toJS(r);
|
|
213
209
|
}
|
|
214
|
-
stringify(
|
|
215
|
-
if (typeof
|
|
210
|
+
stringify(t, n, r) {
|
|
211
|
+
if (typeof n == "function" || Array.isArray(n) || n === null || n === void 0 && r !== void 0) {
|
|
216
212
|
let i = { ...this.#e };
|
|
217
|
-
return
|
|
213
|
+
return n === null ? i.replacer = void 0 : (typeof n == "function" || Array.isArray(n)) && (i.replacer = n), r !== void 0 && (i.indent = P(r)), e.stringify(t, i);
|
|
218
214
|
}
|
|
219
|
-
return
|
|
215
|
+
return e.stringify(t, this.#t(n ?? void 0));
|
|
220
216
|
}
|
|
221
|
-
format(
|
|
222
|
-
return
|
|
217
|
+
format(t, n) {
|
|
218
|
+
return e.format(t, this.#t(n));
|
|
223
219
|
}
|
|
224
220
|
static fromCBOR(e, t) {
|
|
225
|
-
return
|
|
221
|
+
return c(e, t);
|
|
226
222
|
}
|
|
227
223
|
static fromCDN(e, t) {
|
|
228
|
-
return
|
|
224
|
+
return f(e, t);
|
|
229
225
|
}
|
|
230
|
-
static fromEDN(
|
|
231
|
-
return
|
|
226
|
+
static fromEDN(t, n) {
|
|
227
|
+
return e.fromCDN(t, n);
|
|
232
228
|
}
|
|
233
229
|
static fromJS(e, t) {
|
|
234
|
-
return
|
|
230
|
+
return d(e, t);
|
|
235
231
|
}
|
|
236
232
|
static fromHexDump(e, t) {
|
|
237
233
|
let n = [], r = j(e).trim().split(/\s+/).filter(Boolean);
|
|
@@ -239,49 +235,49 @@ var k = {
|
|
|
239
235
|
if (!/^[0-9A-Fa-f]{2}$/.test(e)) throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);
|
|
240
236
|
n.push(parseInt(e, 16));
|
|
241
237
|
}
|
|
242
|
-
return
|
|
238
|
+
return c(new Uint8Array(n), t);
|
|
243
239
|
}
|
|
244
|
-
static decode(
|
|
245
|
-
return
|
|
240
|
+
static decode(t, n) {
|
|
241
|
+
return e.fromCBOR(t, n).toJS(n);
|
|
246
242
|
}
|
|
247
|
-
static encode(
|
|
248
|
-
return
|
|
243
|
+
static encode(t, n) {
|
|
244
|
+
return e.fromJS(t, n).toCBOR(n);
|
|
249
245
|
}
|
|
250
|
-
static cborToCdn(
|
|
251
|
-
return
|
|
246
|
+
static cborToCdn(t, n) {
|
|
247
|
+
return e.fromCBOR(t, n).toCDN(n);
|
|
252
248
|
}
|
|
253
|
-
static cborToCborEdn(
|
|
254
|
-
return
|
|
249
|
+
static cborToCborEdn(t, n) {
|
|
250
|
+
return e.cborToCdn(t, n);
|
|
255
251
|
}
|
|
256
|
-
static cdnToCbor(
|
|
257
|
-
return
|
|
252
|
+
static cdnToCbor(t, n) {
|
|
253
|
+
return e.fromCDN(t, n).toCBOR(n);
|
|
258
254
|
}
|
|
259
|
-
static cborEdnToCbor(
|
|
260
|
-
return
|
|
255
|
+
static cborEdnToCbor(t, n) {
|
|
256
|
+
return e.cdnToCbor(t, n);
|
|
261
257
|
}
|
|
262
|
-
static parse(
|
|
263
|
-
return typeof
|
|
258
|
+
static parse(t, n) {
|
|
259
|
+
return typeof n == "function" ? e.fromCDN(t).toJS({ reviver: n }) : e.fromCDN(t, n).toJS(n);
|
|
264
260
|
}
|
|
265
261
|
static stringify(e, t, n) {
|
|
266
262
|
if (typeof t == "function" || Array.isArray(t) || t === null || t === void 0 && n !== void 0) {
|
|
267
263
|
let r = typeof t == "function" || Array.isArray(t) ? t : void 0, i = P(n);
|
|
268
264
|
if (r) {
|
|
269
|
-
let t =
|
|
270
|
-
return t === void 0 || t ===
|
|
265
|
+
let t = u(e, r);
|
|
266
|
+
return t === void 0 || t === a ? void 0 : d(t).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
271
267
|
}
|
|
272
|
-
return
|
|
268
|
+
return d(e).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
273
269
|
}
|
|
274
270
|
let r = t;
|
|
275
271
|
if (r?.replacer) {
|
|
276
|
-
let t =
|
|
277
|
-
if (t === void 0 || t ===
|
|
272
|
+
let t = u(e, r.replacer, r.extensions, r.undefinedOmits);
|
|
273
|
+
if (t === void 0 || t === a) return;
|
|
278
274
|
let { replacer: n, ...i } = r;
|
|
279
|
-
return
|
|
275
|
+
return d(t, Object.keys(i).length > 0 ? i : void 0).toCDN(r);
|
|
280
276
|
}
|
|
281
|
-
return
|
|
277
|
+
return d(e, r).toCDN(r);
|
|
282
278
|
}
|
|
283
|
-
static format(
|
|
284
|
-
return
|
|
279
|
+
static format(t, n) {
|
|
280
|
+
return e.fromCDN(t, n).toCDN(n);
|
|
285
281
|
}
|
|
286
282
|
};
|
|
287
283
|
function j(e) {
|
|
@@ -331,6 +327,6 @@ function P(e) {
|
|
|
331
327
|
if (typeof e == "string") return e.slice(0, 10) || void 0;
|
|
332
328
|
}
|
|
333
329
|
//#endregion
|
|
334
|
-
export { A as CBOR, A as default,
|
|
330
|
+
export { A as CBOR, A as default, a as CBOR_OMIT, n as CBOR_TAG, p as MapEntries, t as Null, h as Simple, r as Tag, l as Undefined, x as b32, o as dt_as_Date, D as float, S as h32, k as same };
|
|
335
331
|
|
|
336
332
|
//# 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';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst _fromHex =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (Uint8Array as any).fromHex === 'function'\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (h: string) => (Uint8Array as any).fromHex(h) as Uint8Array\n : (h: string): Uint8Array => {\n const out = new Uint8Array(h.length / 2);\n for (let i = 0; i < h.length; i += 2)\n out[i / 2] = parseInt(h.slice(i, i + 2), 16);\n return out;\n };\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(_fromHex(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 throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\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 === '/' && 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,IAA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,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 * 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 throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\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 === '/' && 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,M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