@cbortech/cbor 0.24.0 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +127 -49
- package/README.md +128 -49
- package/dist/ast/CborAppSeqResult.d.ts +20 -0
- package/dist/ast/CborArray.d.ts +3 -3
- package/dist/ast/CborBignum.d.ts +5 -5
- package/dist/ast/CborByteString.d.ts +2 -2
- package/dist/ast/CborEllipsis.d.ts +2 -2
- package/dist/ast/CborEmbeddedCBOR.d.ts +3 -3
- package/dist/ast/CborFloat.d.ts +8 -2
- package/dist/ast/CborIndefiniteByteString.d.ts +3 -3
- package/dist/ast/CborIndefiniteTextString.d.ts +3 -3
- package/dist/ast/CborItem.d.ts +22 -10
- package/dist/ast/CborMap.d.ts +3 -3
- package/dist/ast/CborNint.d.ts +2 -2
- package/dist/ast/CborSimple.d.ts +2 -2
- package/dist/ast/CborTag.d.ts +3 -3
- package/dist/ast/CborTextString.d.ts +2 -2
- package/dist/ast/CborUint.d.ts +2 -2
- package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cbor.d.ts +44 -26
- package/dist/cdn/parser.d.ts +7 -0
- package/dist/{edn → cdn}/serialize-utils.d.ts +20 -7
- package/dist/cdn/serializer.d.ts +7 -0
- package/dist/cdn/test-vectors/runner.d.ts +22 -0
- package/dist/{edn → cdn}/tokenizer.d.ts +28 -25
- package/dist/extensions/b32.d.ts +5 -0
- package/dist/extensions/cri.d.ts +7 -7
- package/dist/extensions/dt.d.ts +10 -19
- package/dist/extensions/float.d.ts +7 -0
- package/dist/extensions/ip.d.ts +8 -8
- package/dist/extensions/same.d.ts +7 -0
- package/dist/extensions/types.d.ts +30 -8
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +244 -77
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-BccT62HT.cjs +36 -0
- package/dist/mapEntries-BccT62HT.cjs.map +1 -0
- package/dist/{mapEntries-D5MWtXqq.js → mapEntries-ZR8QJ0Yj.js} +1157 -853
- package/dist/mapEntries-ZR8QJ0Yj.js.map +1 -0
- package/dist/simple.d.ts +2 -2
- package/dist/tag.d.ts +1 -1
- package/dist/types.d.ts +141 -30
- package/dist/utils/hexfloat.d.ts +2 -2
- package/dist/utils/strip-comments.d.ts +12 -0
- package/package.json +13 -11
- package/dist/edn/parser.d.ts +0 -7
- package/dist/edn/serializer.d.ts +0 -7
- package/dist/mapEntries-D5MWtXqq.js.map +0 -1
- package/dist/mapEntries-bihZ3yks.cjs +0 -31
- package/dist/mapEntries-bihZ3yks.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,160 @@
|
|
|
1
|
-
import { C as e, D as t, E as n,
|
|
2
|
-
//#region src/
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { C as e, D as t, E as n, O as r, T as i, a, g as o, i as s, n as c, r as l, s as u, t as d, v as f, w as p, x as m } from "./mapEntries-ZR8QJ0Yj.js";
|
|
2
|
+
//#region src/utils/strip-comments.ts
|
|
3
|
+
function h(e) {
|
|
4
|
+
let t = "", n = 0;
|
|
5
|
+
for (; n < e.length;) {
|
|
6
|
+
let r = e[n];
|
|
7
|
+
if (r === " " || r === "\n" || r === "\r") {
|
|
8
|
+
n++;
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (r === "#") {
|
|
12
|
+
for (; n < e.length && e[n] !== "\n";) n++;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (r === "/") {
|
|
16
|
+
let t = e[n + 1] ?? "";
|
|
17
|
+
if (t === "/") {
|
|
18
|
+
for (; n < e.length && e[n] !== "\n";) n++;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (t === "*") {
|
|
22
|
+
for (n += 2; n < e.length && !(e[n] === "*" && (e[n + 1] ?? "") === "/");) n++;
|
|
23
|
+
if (n >= e.length) throw SyntaxError("unterminated block comment");
|
|
24
|
+
n += 2;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
for (n++; n < e.length && e[n] !== "/";) n++;
|
|
28
|
+
if (n >= e.length) throw SyntaxError("unterminated block comment");
|
|
29
|
+
n++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
t += r, n++;
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/extensions/b32.ts
|
|
38
|
+
var g = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", _ = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
39
|
+
function v(e) {
|
|
40
|
+
let t = e.length;
|
|
41
|
+
for (; t > 0 && e.charCodeAt(t - 1) === 61;) t--;
|
|
42
|
+
return e.slice(0, t);
|
|
43
|
+
}
|
|
44
|
+
function y(e, t, n) {
|
|
45
|
+
let r = v(e).toUpperCase(), i = r.length % 8;
|
|
46
|
+
if (i === 1 || i === 3 || i === 6) throw SyntaxError(`invalid base32 length: ${r.length} characters`);
|
|
47
|
+
let a = new Uint8Array(128).fill(255);
|
|
48
|
+
for (let e = 0; e < t.length; e++) a[t.charCodeAt(e)] = e;
|
|
49
|
+
let o = new Uint8Array(Math.floor(r.length * 5 / 8)), s = 0, c = 0, l = 0;
|
|
50
|
+
for (let e of r) {
|
|
51
|
+
let t = e.charCodeAt(0), n = t < 128 ? a[t] : 255;
|
|
52
|
+
if (n === 255) throw SyntaxError(`invalid character in byte string: ${JSON.stringify(e)}`);
|
|
53
|
+
s = s << 5 | n, c += 5, c >= 8 && (c -= 8, o[l++] = s >> c & 255);
|
|
54
|
+
}
|
|
55
|
+
if (c > 0 && s & (1 << c) - 1) {
|
|
56
|
+
let e = "non-zero trailing bits in base32 input";
|
|
57
|
+
if (n) n(e);
|
|
58
|
+
else throw SyntaxError(e);
|
|
59
|
+
}
|
|
60
|
+
return o;
|
|
61
|
+
}
|
|
62
|
+
var b = {
|
|
63
|
+
appStringPrefixes: ["b32"],
|
|
64
|
+
parseAppString(e, t, n) {
|
|
65
|
+
return new o(y(h(t), g, n), { ednEncoding: "base32" });
|
|
66
|
+
}
|
|
67
|
+
}, x = {
|
|
68
|
+
appStringPrefixes: ["h32"],
|
|
69
|
+
parseAppString(e, t, n) {
|
|
70
|
+
return new o(y(h(t), _, n), { ednEncoding: "base32hex" });
|
|
71
|
+
}
|
|
72
|
+
}, S = typeof Uint8Array.fromHex == "function" ? (e) => Uint8Array.fromHex(e) : (e) => {
|
|
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 {
|
|
77
|
+
_bits;
|
|
78
|
+
constructor(e) {
|
|
79
|
+
super(m(e), { precision: "half" }), this._bits = e & 65535;
|
|
80
|
+
}
|
|
81
|
+
_toCBOR() {
|
|
82
|
+
return new Uint8Array([
|
|
83
|
+
249,
|
|
84
|
+
this._bits >> 8 & 255,
|
|
85
|
+
this._bits & 255
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
}, w = class extends f {
|
|
89
|
+
_raw;
|
|
90
|
+
constructor(e) {
|
|
91
|
+
super(new DataView(e.buffer, e.byteOffset).getFloat32(0, !1), { precision: "single" }), this._raw = e.slice();
|
|
92
|
+
}
|
|
93
|
+
_toCBOR() {
|
|
94
|
+
let e = new Uint8Array(5);
|
|
95
|
+
return e[0] = 250, e.set(this._raw, 1), e;
|
|
96
|
+
}
|
|
97
|
+
}, T = class extends f {
|
|
98
|
+
_raw;
|
|
99
|
+
constructor(e) {
|
|
100
|
+
super(new DataView(e.buffer, e.byteOffset).getFloat64(0, !1), { precision: "double" }), this._raw = e.slice();
|
|
101
|
+
}
|
|
102
|
+
_toCBOR() {
|
|
103
|
+
let e = new Uint8Array(9);
|
|
104
|
+
return e[0] = 251, e.set(this._raw, 1), e;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
function E(e) {
|
|
108
|
+
if (e.length === 2) return new C(e[0] << 8 | e[1]);
|
|
109
|
+
if (e.length === 4) return new w(e);
|
|
110
|
+
if (e.length === 8) return new T(e);
|
|
111
|
+
throw SyntaxError(`float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${e.length} bytes`);
|
|
112
|
+
}
|
|
113
|
+
var D = {
|
|
114
|
+
appStringPrefixes: ["float"],
|
|
115
|
+
parseAppString(e, t) {
|
|
116
|
+
let n = h(t);
|
|
117
|
+
if (!/^[0-9a-fA-F]*$/.test(n)) throw SyntaxError("float'...' contains non-hex characters");
|
|
118
|
+
if (n.length % 2 != 0) throw SyntaxError(`float'...' hex content has odd length (${n.length} digits)`);
|
|
119
|
+
return E(S(n));
|
|
120
|
+
},
|
|
121
|
+
parseAppSequence(e, t, n) {
|
|
122
|
+
if (t.length === 0) throw SyntaxError("float<<...>> requires exactly one byte-string item");
|
|
123
|
+
if (t.length > 1) {
|
|
124
|
+
let e = `float<<...>> expects 1 item; got ${t.length} — using first`;
|
|
125
|
+
if (n) n(e);
|
|
126
|
+
else throw SyntaxError(e);
|
|
127
|
+
}
|
|
128
|
+
if (!(t[0] instanceof o)) throw SyntaxError("float<<...>> item must be a byte string");
|
|
129
|
+
return E(t[0].value);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/extensions/same.ts
|
|
134
|
+
function O(e, t) {
|
|
135
|
+
if (e.length !== t.length) return !1;
|
|
136
|
+
for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
|
|
137
|
+
return !0;
|
|
138
|
+
}
|
|
139
|
+
var k = {
|
|
140
|
+
appStringPrefixes: ["same"],
|
|
141
|
+
preserveAppSeqSource: !0,
|
|
142
|
+
parseAppSequence(e, t, n) {
|
|
143
|
+
if (t.length === 0) throw SyntaxError("same<<...>> requires at least one item");
|
|
144
|
+
let r = t[0], i = r.toCBOR();
|
|
145
|
+
for (let e = 1; e < t.length; e++) if (!O(i, t[e].toCBOR())) {
|
|
146
|
+
let t = `same<<...>>: item ${e} produces different CBOR bytes than item 0`;
|
|
147
|
+
if (n) n(t);
|
|
148
|
+
else throw SyntaxError(t);
|
|
149
|
+
}
|
|
150
|
+
return r;
|
|
151
|
+
}
|
|
152
|
+
}, A = class n {
|
|
153
|
+
static OMIT = p;
|
|
154
|
+
static TAG = i;
|
|
155
|
+
static Tag = t;
|
|
156
|
+
static Simple = e;
|
|
157
|
+
static MapEntries = d;
|
|
9
158
|
static dt_as_Date = a;
|
|
10
159
|
#e;
|
|
11
160
|
constructor(e) {
|
|
@@ -17,146 +166,164 @@ var f = class t {
|
|
|
17
166
|
...e ?? {}
|
|
18
167
|
};
|
|
19
168
|
}
|
|
20
|
-
fromCBOR(e,
|
|
21
|
-
let r =
|
|
169
|
+
fromCBOR(e, t) {
|
|
170
|
+
let r = n.fromCBOR(e, this.#t(t));
|
|
22
171
|
return r._defaults = this.#e, r;
|
|
23
172
|
}
|
|
24
|
-
|
|
25
|
-
let r =
|
|
173
|
+
fromCDN(e, t) {
|
|
174
|
+
let r = n.fromCDN(e, this.#t(t));
|
|
26
175
|
return r._defaults = this.#e, r;
|
|
27
176
|
}
|
|
28
|
-
|
|
29
|
-
|
|
177
|
+
fromEDN(e, t) {
|
|
178
|
+
return this.fromCDN(e, t);
|
|
179
|
+
}
|
|
180
|
+
fromJS(e, t) {
|
|
181
|
+
let r = n.fromJS(e, this.#t(t));
|
|
30
182
|
return r._defaults = this.#e, r;
|
|
31
183
|
}
|
|
32
|
-
fromHexDump(e,
|
|
33
|
-
let r =
|
|
184
|
+
fromHexDump(e, t) {
|
|
185
|
+
let r = n.fromHexDump(e, this.#t(t));
|
|
34
186
|
return r._defaults = this.#e, r;
|
|
35
187
|
}
|
|
36
|
-
decode(e,
|
|
37
|
-
return
|
|
188
|
+
decode(e, t) {
|
|
189
|
+
return n.decode(e, this.#t(t));
|
|
190
|
+
}
|
|
191
|
+
encode(e, t) {
|
|
192
|
+
return n.encode(e, this.#t(t));
|
|
193
|
+
}
|
|
194
|
+
cborToCborEdn(e, t) {
|
|
195
|
+
return this.cborToCdn(e, t);
|
|
38
196
|
}
|
|
39
|
-
|
|
40
|
-
return
|
|
197
|
+
cborToCdn(e, t) {
|
|
198
|
+
return n.cborToCdn(e, this.#t(t));
|
|
41
199
|
}
|
|
42
|
-
|
|
43
|
-
return
|
|
200
|
+
cborEdnToCbor(e, t) {
|
|
201
|
+
return this.cdnToCbor(e, t);
|
|
44
202
|
}
|
|
45
|
-
|
|
46
|
-
return
|
|
203
|
+
cdnToCbor(e, t) {
|
|
204
|
+
return n.cdnToCbor(e, this.#t(t));
|
|
47
205
|
}
|
|
48
|
-
parse(e,
|
|
49
|
-
if (typeof
|
|
50
|
-
let r = this.#t({ reviver:
|
|
51
|
-
return
|
|
206
|
+
parse(e, t) {
|
|
207
|
+
if (typeof t == "function") {
|
|
208
|
+
let r = this.#t({ reviver: t });
|
|
209
|
+
return n.fromCDN(e, r).toJS(r);
|
|
52
210
|
}
|
|
53
|
-
let r = this.#t(
|
|
54
|
-
return
|
|
211
|
+
let r = this.#t(t);
|
|
212
|
+
return n.fromCDN(e, r).toJS(r);
|
|
55
213
|
}
|
|
56
|
-
stringify(e,
|
|
57
|
-
if (typeof
|
|
214
|
+
stringify(e, t, r) {
|
|
215
|
+
if (typeof t == "function" || Array.isArray(t) || t === null || t === void 0 && r !== void 0) {
|
|
58
216
|
let i = { ...this.#e };
|
|
59
|
-
return
|
|
217
|
+
return t === null ? i.replacer = void 0 : (typeof t == "function" || Array.isArray(t)) && (i.replacer = t), r !== void 0 && (i.indent = P(r)), n.stringify(e, i);
|
|
60
218
|
}
|
|
61
|
-
return
|
|
219
|
+
return n.stringify(e, this.#t(t ?? void 0));
|
|
62
220
|
}
|
|
63
|
-
format(e,
|
|
64
|
-
return
|
|
221
|
+
format(e, t) {
|
|
222
|
+
return n.format(e, this.#t(t));
|
|
65
223
|
}
|
|
66
224
|
static fromCBOR(e, t) {
|
|
67
|
-
return
|
|
225
|
+
return s(e, t);
|
|
226
|
+
}
|
|
227
|
+
static fromCDN(e, t) {
|
|
228
|
+
return u(e, t);
|
|
68
229
|
}
|
|
69
230
|
static fromEDN(e, t) {
|
|
70
|
-
return
|
|
231
|
+
return n.fromCDN(e, t);
|
|
71
232
|
}
|
|
72
233
|
static fromJS(e, t) {
|
|
73
|
-
return
|
|
234
|
+
return l(e, t);
|
|
74
235
|
}
|
|
75
236
|
static fromHexDump(e, t) {
|
|
76
|
-
let n = [], r =
|
|
237
|
+
let n = [], r = j(e).trim().split(/\s+/).filter(Boolean);
|
|
77
238
|
for (let e of r) {
|
|
78
239
|
if (!/^[0-9A-Fa-f]{2}$/.test(e)) throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);
|
|
79
240
|
n.push(parseInt(e, 16));
|
|
80
241
|
}
|
|
81
|
-
return
|
|
242
|
+
return s(new Uint8Array(n), t);
|
|
82
243
|
}
|
|
83
|
-
static decode(e,
|
|
84
|
-
return
|
|
244
|
+
static decode(e, t) {
|
|
245
|
+
return n.fromCBOR(e, t).toJS(t);
|
|
85
246
|
}
|
|
86
|
-
static encode(e,
|
|
87
|
-
return
|
|
247
|
+
static encode(e, t) {
|
|
248
|
+
return n.fromJS(e, t).toCBOR(t);
|
|
88
249
|
}
|
|
89
|
-
static
|
|
90
|
-
return
|
|
250
|
+
static cborToCdn(e, t) {
|
|
251
|
+
return n.fromCBOR(e, t).toCDN(t);
|
|
91
252
|
}
|
|
92
|
-
static
|
|
93
|
-
return
|
|
253
|
+
static cborToCborEdn(e, t) {
|
|
254
|
+
return n.cborToCdn(e, t);
|
|
94
255
|
}
|
|
95
|
-
static
|
|
96
|
-
return
|
|
256
|
+
static cdnToCbor(e, t) {
|
|
257
|
+
return n.fromCDN(e, t).toCBOR(t);
|
|
97
258
|
}
|
|
98
|
-
static
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
259
|
+
static cborEdnToCbor(e, t) {
|
|
260
|
+
return n.cdnToCbor(e, t);
|
|
261
|
+
}
|
|
262
|
+
static parse(e, t) {
|
|
263
|
+
return typeof t == "function" ? n.fromCDN(e).toJS({ reviver: t }) : n.fromCDN(e, t).toJS(t);
|
|
264
|
+
}
|
|
265
|
+
static stringify(e, t, n) {
|
|
266
|
+
if (typeof t == "function" || Array.isArray(t) || t === null || t === void 0 && n !== void 0) {
|
|
267
|
+
let r = typeof t == "function" || Array.isArray(t) ? t : void 0, i = P(n);
|
|
268
|
+
if (r) {
|
|
269
|
+
let t = c(e, r);
|
|
270
|
+
return t === void 0 || t === p ? void 0 : l(t).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
104
271
|
}
|
|
105
|
-
return
|
|
272
|
+
return l(e).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
106
273
|
}
|
|
107
|
-
let
|
|
108
|
-
if (
|
|
109
|
-
let
|
|
110
|
-
if (
|
|
111
|
-
let { replacer:
|
|
112
|
-
return
|
|
274
|
+
let r = t;
|
|
275
|
+
if (r?.replacer) {
|
|
276
|
+
let t = c(e, r.replacer, r.extensions, r.undefinedOmits);
|
|
277
|
+
if (t === void 0 || t === p) return;
|
|
278
|
+
let { replacer: n, ...i } = r;
|
|
279
|
+
return l(t, Object.keys(i).length > 0 ? i : void 0).toCDN(r);
|
|
113
280
|
}
|
|
114
|
-
return
|
|
281
|
+
return l(e, r).toCDN(r);
|
|
115
282
|
}
|
|
116
|
-
static format(e,
|
|
117
|
-
return
|
|
283
|
+
static format(e, t) {
|
|
284
|
+
return n.fromCDN(e, t).toCDN(t);
|
|
118
285
|
}
|
|
119
286
|
};
|
|
120
|
-
function
|
|
287
|
+
function j(e) {
|
|
121
288
|
let t = "", n = 0;
|
|
122
289
|
for (; n < e.length;) {
|
|
123
290
|
let r = e[n], i = e[n + 1] ?? "";
|
|
124
291
|
if (r === "-" && i === "-") {
|
|
125
|
-
n =
|
|
292
|
+
n = M(e, n + 2), t += " ";
|
|
126
293
|
continue;
|
|
127
294
|
}
|
|
128
295
|
if (r === "#") {
|
|
129
|
-
n =
|
|
296
|
+
n = M(e, n + 1), t += " ";
|
|
130
297
|
continue;
|
|
131
298
|
}
|
|
132
299
|
if (r === "/" && i === "/") {
|
|
133
|
-
n =
|
|
300
|
+
n = M(e, n + 2), t += " ";
|
|
134
301
|
continue;
|
|
135
302
|
}
|
|
136
303
|
if (r === "/" && i === "*") {
|
|
137
304
|
let r = e.indexOf("*/", n + 2);
|
|
138
305
|
if (r < 0) throw SyntaxError("Unterminated comment in hex dump");
|
|
139
|
-
t +=
|
|
306
|
+
t += N(e.slice(n, r + 2)), n = r + 2;
|
|
140
307
|
continue;
|
|
141
308
|
}
|
|
142
309
|
if (r === "/") {
|
|
143
310
|
let r = e.indexOf("/", n + 1);
|
|
144
311
|
if (r < 0) throw SyntaxError("Unterminated comment in hex dump");
|
|
145
|
-
t +=
|
|
312
|
+
t += N(e.slice(n, r + 1)), n = r + 1;
|
|
146
313
|
continue;
|
|
147
314
|
}
|
|
148
315
|
t += r, n++;
|
|
149
316
|
}
|
|
150
317
|
return t;
|
|
151
318
|
}
|
|
152
|
-
function
|
|
319
|
+
function M(e, t) {
|
|
153
320
|
let n = e.indexOf("\n", t);
|
|
154
321
|
return n < 0 ? e.length : n;
|
|
155
322
|
}
|
|
156
|
-
function
|
|
323
|
+
function N(e) {
|
|
157
324
|
return e.replace(/[^\r\n]/g, " ");
|
|
158
325
|
}
|
|
159
|
-
function
|
|
326
|
+
function P(e) {
|
|
160
327
|
if (typeof e == "number") {
|
|
161
328
|
let t = Math.floor(Math.min(10, Math.max(0, e)));
|
|
162
329
|
return t === 0 ? void 0 : t;
|
|
@@ -164,6 +331,6 @@ function g(e) {
|
|
|
164
331
|
if (typeof e == "string") return e.slice(0, 10) || void 0;
|
|
165
332
|
}
|
|
166
333
|
//#endregion
|
|
167
|
-
export {
|
|
334
|
+
export { A as CBOR, A as default, p as CBOR_OMIT, i as CBOR_TAG, d as MapEntries, n as Null, e as Simple, t as Tag, r as Undefined, b as b32, a as dt_as_Date, D as float, x as h32, k as same };
|
|
168
335
|
|
|
169
336
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromHexDumpOptions,\n FromEDNOptions,\n FromJSOptions,\n ToCBOROptions,\n ToEDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseEDN } from './edn/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 CBOR-EDN 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 fromEDN(text: string, options?: FromEDNOptions): CborItem {\n const node = CBOR.fromEDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\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 `fromCBOR(input, options).toEDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.cborToCborEdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromEDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cborEdnToCbor(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: FromEDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromEDN(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 & ToEDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\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 & ToEDNOptions = {\n ...(this.#defaults as FromJSOptions & ToEDNOptions),\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?: FromEDNOptions & ToEDNOptions): 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 CBOR-EDN text string into an AST node. */\n static fromEDN(text: string, options?: FromEDNOptions): CborItem {\n return parseEDN(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 CBOR-EDN text string.\n *\n * @deprecated Use `CBOR.fromCBOR(input, options).toEDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toEDN(options);\n }\n\n /**\n * Convert a CBOR-EDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.fromEDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromEDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CBOR-EDN 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 EDN 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: FromEDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromEDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromEDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CBOR-EDN 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 `ToEDNOptions.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 & ToEDNOptions\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 & ToEDNOptions),\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).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToEDNOptions) | 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 ).toEDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toEDN(opts);\n }\n\n /** Normalize a CBOR-EDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.fromEDN(text, options).toEDN(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 ToEDNOptions.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":";;AAwCA,IAAa,IAAb,MAAa,EAAK;CAMhB,OAAgB,OAAyB;CAGzC,OAAgB,MAAuB;CAGvC,OAAgB,MAAmB;CAGnC,OAAgB,SAAyB;CAGzC,OAAgB,aAAiC;CAGjD,OAAgB,aAAiC;CAIjD;CAWA,YAAY,GAAwB;EAClC,KAAKA,KAAY,KAAY,EAAE;;CAGjC,GAAyB,GAA8B;EACrD,OAAO;GAAE,GAAG,KAAKA;GAAW,GAAI,KAAW,EAAE;GAAG;;CAGlD,SACE,GACA,G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32.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;CACj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