@cbortech/cbor 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,695 @@
1
+ /* Excluded from this release type: AnnotatedLine */
2
+
3
+ /**
4
+ * Main facade class.
5
+ *
6
+ * Provides factory methods for constructing AST nodes from the three
7
+ * supported input formats, and shortcut methods that mirror the
8
+ * `JSON.parse` / `JSON.stringify` API.
9
+ *
10
+ * @example
11
+ * // CBOR binary → AST → CBOR binary
12
+ * const ast = CBOR.fromCBOR(bytes);
13
+ * const reencoded = ast.toCBOR();
14
+ *
15
+ * @example
16
+ * // JS value → CBOR binary (shortcut)
17
+ * const bytes = CBOR.encode({ hello: 'world' });
18
+ *
19
+ * @example
20
+ * // CBOR binary → JS value (shortcut)
21
+ * const value = CBOR.decode(bytes);
22
+ */
23
+ declare class CBOR {
24
+ #private;
25
+ /**
26
+ * Sentinel returned from a replacer or reviver to omit the key/element from
27
+ * the output. Use this instead of `undefined` when `undefinedOmits` is
28
+ * `false` (the default) and you need to drop a specific entry.
29
+ */
30
+ static readonly OMIT: typeof CBOR_OMIT;
31
+ /** Unique symbol used to attach a CBOR tag number to a JS value. */
32
+ static readonly TAG: typeof CBOR_TAG;
33
+ /** Namespace for CBOR tag annotation utilities. */
34
+ static readonly Tag: typeof Tag;
35
+ /** Wrapper for CBOR simple values other than false/true/null/undefined. */
36
+ static readonly Simple: typeof Simple;
37
+ /** Array subclass used to preserve CBOR map entries, including duplicates. */
38
+ static readonly MapEntries: typeof MapEntries;
39
+ /** Extension that maps CBOR-EDN dt/DT values to JavaScript Date objects. */
40
+ static readonly dt_as_Date: typeof dt_as_Date;
41
+ /**
42
+ * Create a reusable instance with default options applied to every method call.
43
+ * Per-call options always override these defaults.
44
+ *
45
+ * @example
46
+ * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });
47
+ * const obj = cbor.parse('{ "dt": DT\'2024-01-01T00:00:00Z\' }');
48
+ * const text = cbor.stringify(obj);
49
+ */
50
+ constructor(defaults?: CBOROptions);
51
+ fromCBOR(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions): CborItem;
52
+ fromEDN(text: string, options?: FromEDNOptions): CborItem;
53
+ fromJS(value: unknown, options?: FromJSOptions): CborItem;
54
+ fromHexDump(text: string, options?: FromHexDumpOptions): CborItem;
55
+ decode(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToJSOptions): unknown;
56
+ encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array;
57
+ cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToEDNOptions): string;
58
+ cborEdnToCbor(text: string, options?: FromEDNOptions & ToCBOROptions): Uint8Array;
59
+ parse(text: string): unknown;
60
+ parse(text: string, reviver: (this: unknown, key: unknown, value: unknown) => unknown): unknown;
61
+ parse(text: string, options: FromEDNOptions & ToJSOptions): unknown;
62
+ stringify(value: unknown): string;
63
+ stringify(value: unknown, replacer: ((this: unknown, key: unknown, value: unknown) => unknown) | (string | number)[] | null, space?: string | number): string;
64
+ stringify(value: unknown, options: FromJSOptions & ToEDNOptions): string;
65
+ format(text: string, options?: FromEDNOptions & ToEDNOptions): string;
66
+ /** Decode CBOR binary data into an AST node. */
67
+ static fromCBOR(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions): CborItem;
68
+ /** Parse a CBOR-EDN text string into an AST node. */
69
+ static fromEDN(text: string, options?: FromEDNOptions): CborItem;
70
+ /** Convert a JavaScript value into an AST node. */
71
+ static fromJS(value: unknown, options?: FromJSOptions): CborItem;
72
+ /**
73
+ * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})
74
+ * into an AST node.
75
+ *
76
+ * Each line is expected to have the form:
77
+ * `[whitespace] HH [HH …] -- comment`
78
+ * `[whitespace] HH [HH …] # comment`
79
+ * `[whitespace] HH [HH …] // comment`
80
+ * Block comments may also be written as `/ comment /` or `/* comment *\/`.
81
+ * Lines with no hex content before the comment marker are ignored.
82
+ */
83
+ static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem;
84
+ /** Decode CBOR binary data directly to a JavaScript value. */
85
+ static decode(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToJSOptions): unknown;
86
+ /** Encode a JavaScript value directly to CBOR binary data. */
87
+ static encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array;
88
+ /** Convert CBOR binary data directly to a CBOR-EDN text string. */
89
+ static cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToEDNOptions): string;
90
+ /** Convert a CBOR-EDN text string directly to CBOR binary data. */
91
+ static cborEdnToCbor(text: string, options?: FromEDNOptions & ToCBOROptions): Uint8Array;
92
+ /**
93
+ * Parse a CBOR-EDN text string directly to a JavaScript value.
94
+ *
95
+ * Accepts either a JSON-compatible `reviver` function as the second argument,
96
+ * or a plain options object (existing API).
97
+ *
98
+ * When a `reviver` is supplied it is applied bottom-up after the EDN text has
99
+ * been parsed and converted to a JS value, matching the semantics of
100
+ * `JSON.parse(text, reviver)`.
101
+ *
102
+ * Note: CBOR-specific value types such as `bigint` are passed to the reviver
103
+ * as-is; the reviver is responsible for handling them.
104
+ */
105
+ static parse(text: string): unknown;
106
+ static parse(text: string, reviver: (this: unknown, key: unknown, value: unknown) => unknown): unknown;
107
+ static parse(text: string, options: FromEDNOptions & ToJSOptions): unknown;
108
+ /**
109
+ * Serialize a JavaScript value directly to a CBOR-EDN text string.
110
+ *
111
+ * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain
112
+ * options object (existing API).
113
+ *
114
+ * - `replacer` may be a function (transforms each key/value before encoding)
115
+ * or an array of strings/numbers (allowlist of object keys to include).
116
+ * Pass `null` to skip filtering.
117
+ * - `space` controls indentation, mapping to `ToEDNOptions.indent`.
118
+ * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.
119
+ */
120
+ static stringify(value: unknown): string;
121
+ static stringify(value: unknown, replacer: ((this: unknown, key: unknown, value: unknown) => unknown) | (string | number)[] | null, space?: string | number): string;
122
+ static stringify(value: unknown, options: FromJSOptions & ToEDNOptions): string;
123
+ /** Normalize a CBOR-EDN text string by parsing and re-serializing it. */
124
+ static format(text: string, options?: FromEDNOptions & ToEDNOptions): string;
125
+ }
126
+ export { CBOR }
127
+ export default CBOR;
128
+
129
+ /**
130
+ * Sentinel returned from a replacer or reviver to omit the key/element from
131
+ * the output. Use this instead of returning `undefined` when `undefinedOmits`
132
+ * is `false` (the default) and you need to drop a specific entry.
133
+ *
134
+ * Accessible as `CBOR.OMIT` on the main class.
135
+ */
136
+ export declare const CBOR_OMIT: unique symbol;
137
+
138
+ export declare const CBOR_TAG: unique symbol;
139
+
140
+ declare interface CborComment {
141
+ kind: 'line' | 'block';
142
+ marker: '#' | '//' | '/*' | '/';
143
+ text: string;
144
+ start: number;
145
+ end: number;
146
+ line: number;
147
+ col: number;
148
+ }
149
+
150
+ declare interface CborComments {
151
+ leading?: CborComment[];
152
+ trailing?: CborComment[];
153
+ dangling?: CborComment[];
154
+ }
155
+
156
+ /**
157
+ * Plugin that extends EDN parsing, CBOR decoding, and `fromJS()` for specific
158
+ * application-string prefixes or CBOR tag numbers.
159
+ *
160
+ * Pass instances via `FromEDNOptions.extensions`, `FromCBOROptions.extensions`,
161
+ * or `FromJSOptions.extensions`.
162
+ *
163
+ * @example
164
+ * // Custom "ip" extension: ip'192.0.2.1' → CborByteString of 4 bytes
165
+ * const ipExtension: CborExtension = {
166
+ * appStringPrefixes: ['ip'],
167
+ * parseAppString(_prefix, content) {
168
+ * return new CborByteString(parseIPv4(content));
169
+ * },
170
+ * };
171
+ * parseEDN("ip'192.0.2.1'", { extensions: [ipExtension] });
172
+ */
173
+ export declare interface CborExtension {
174
+ /**
175
+ * App-string prefixes this extension handles (e.g. `['dt', 'DT']`).
176
+ * The tokenizer recognises these as `APP_STRING` / `APP_SEQUENCE` tokens.
177
+ */
178
+ readonly appStringPrefixes?: readonly string[];
179
+ /**
180
+ * CBOR tag numbers this extension handles (e.g. `[0n, 1n]`).
181
+ * Extensions with `parseTag()` are invoked for these tag numbers during
182
+ * `fromCBOR()` and integer-tagged EDN items (`1(…)`) in `fromEDN()`.
183
+ */
184
+ readonly tagNumbers?: readonly bigint[];
185
+ /**
186
+ * Parse an app-string literal: `prefix'content'` or `prefix"content"`.
187
+ * Receives the matched `prefix` and the decoded string `content`.
188
+ * Throw `SyntaxError` to report invalid content.
189
+ */
190
+ parseAppString?(prefix: string, content: string): CborItem;
191
+ /**
192
+ * Parse an app-sequence literal: `prefix<<item, ...>>`.
193
+ * Receives the matched `prefix` and the array of parsed CBOR values.
194
+ * If omitted, the `<<...>>` form is rejected with a `SyntaxError`.
195
+ */
196
+ parseAppSequence?(prefix: string, items: CborItem[]): CborItem;
197
+ /**
198
+ * Called when a `CborTag` is encountered during CBOR decode (`fromCBOR`)
199
+ * or EDN integer-tag parsing (`fromEDN`).
200
+ * Return `undefined` to fall back to the default `CborTag` representation.
201
+ */
202
+ parseTag?(tag: bigint, value: CborItem): CborItem | undefined;
203
+ /**
204
+ * Called during `fromJS()` for every value before the default conversion
205
+ * logic. Return `undefined` to fall through to the default behaviour.
206
+ * Typical uses: intercept `Date` instances, or CBOR-tagged plain objects
207
+ * that carry a `Symbol.for('cbor.tag')` key for a registered tag number.
208
+ */
209
+ fromJS?(value: unknown, options: FromJSOptions): CborItem | undefined;
210
+ /**
211
+ * Returns `true` if the given JS value is of a type that this extension's
212
+ * `fromJS()` converts. When `true`, the replacer pipeline passes the value
213
+ * through as-is instead of decomposing it with `Object.keys()` traversal.
214
+ *
215
+ * Implement this alongside `fromJS` for any class instance type (e.g.
216
+ * `Date`) that must survive the replacer pipeline intact so that `fromJS`
217
+ * can convert it correctly.
218
+ *
219
+ * Implementations may narrow the return type to a type predicate
220
+ * (e.g. `value is Date`) for better static type inference at the call site.
221
+ */
222
+ isJSType?(value: unknown): boolean;
223
+ }
224
+
225
+ /**
226
+ * Abstract base class for all CBOR AST nodes.
227
+ *
228
+ * Every node can serialize itself to CBOR binary, CBOR-EDN text, and a
229
+ * plain JavaScript value. Concrete implementations are provided in each
230
+ * subclass (added in later phases).
231
+ */
232
+ export declare abstract class CborItem {
233
+ /**
234
+ * Character offset of the first character of this item in the parsed source.
235
+ * Set by parsers; undefined when the node was constructed directly.
236
+ * For CBOR input this is a byte offset.
237
+ */
238
+ start?: number;
239
+ /**
240
+ * Character offset just past the last character of this item in the parsed source.
241
+ * Set by parsers; undefined when the node was constructed directly.
242
+ * For CBOR input this is a byte offset.
243
+ */
244
+ end?: number;
245
+ /**
246
+ * Comments captured from CBOR-EDN source when `preserveComments` is enabled.
247
+ * They do not affect CBOR bytes or JS conversion.
248
+ */
249
+ comments?: CborComments;
250
+ /* Excluded from this release type: _defaults */
251
+ /** Serialize this node to CBOR binary. */
252
+ toCBOR(options?: ToCBOROptions): Uint8Array;
253
+ /** Serialize this node to a CBOR-EDN text string. */
254
+ toEDN(options?: ToEDNOptions): string;
255
+ /**
256
+ * Convert this CBOR AST node to a plain JavaScript value.
257
+ *
258
+ * If `options.reviver` is supplied it is called with key `''` on the root
259
+ * result after the full tree has been converted (matching the semantics of
260
+ * `JSON.parse`). Container nodes call the reviver on each of their direct
261
+ * children during conversion, so the walk is bottom-up.
262
+ */
263
+ toJS(options?: ToJSOptions): unknown;
264
+ /**
265
+ * Generate an RFC 8949 §3 style annotated hex dump of this value.
266
+ *
267
+ * @example
268
+ * const cbor = CBOR.fromEDN('[_ 1, [2, 3]]');
269
+ * console.log(cbor.toHexDump());
270
+ * // 9F -- Start indefinite-length array
271
+ * // 01 -- 1
272
+ * // 82 -- Array of length 2
273
+ * // 02 -- 2
274
+ * // 03 -- 3
275
+ * // FF -- "break"
276
+ * // FF -- "break"
277
+ */
278
+ toHexDump(options?: ToHexDumpOptions): string;
279
+ /* Excluded from this release type: _toCBOR */
280
+ /* Excluded from this release type: _toEDN */
281
+ /* Excluded from this release type: _toJS */
282
+ /* Excluded from this release type: _toHexDump */
283
+ }
284
+
285
+ /**
286
+ * Combined options for the `CBOR` constructor.
287
+ *
288
+ * These defaults are applied to every subsequent method call on the instance.
289
+ * Per-call options always take precedence over these defaults.
290
+ *
291
+ * Note: `encodeIntegerAs` (from {@link FromJSOptions}) and `integerAs` (from
292
+ * {@link ToJSOptions}) are distinct fields and do not conflict.
293
+ */
294
+ export declare type CBOROptions = FromEDNOptions & FromJSOptions & ToCBOROptions & ToEDNOptions & ToJSOptions & ToHexDumpOptions;
295
+
296
+ /**
297
+ * Full-featured dt/DT CborExtension with Date support.
298
+ * Tagged DT values produce CborTaggedEpochDtAsDateExt; toJS() returns a Date.
299
+ * fromJS(Date) converts Date instances to tagged epoch values.
300
+ */
301
+ export declare const dt_as_Date: CborExtension;
302
+
303
+ export declare interface FromCBOROptions {
304
+ /**
305
+ * Byte offset within the supplied input at which CBOR decoding starts.
306
+ * Useful for reading one item from a CBOR Sequence.
307
+ *
308
+ * @default 0
309
+ */
310
+ offset?: number;
311
+ /**
312
+ * Allow bytes after the decoded item.
313
+ *
314
+ * When `false`, decoding still requires the item to consume the remaining
315
+ * input, preserving the historical single-item behaviour. Set this to `true`
316
+ * when using `CborItem.end` to continue decoding a CBOR Sequence.
317
+ *
318
+ * @example
319
+ * // Read two items from a CBOR Sequence, validating that the second is last.
320
+ * const first = CBOR.fromCBOR(bytes, { allowTrailing: true });
321
+ * const second = CBOR.fromCBOR(bytes, { offset: first.end });
322
+ *
323
+ * @default false
324
+ */
325
+ allowTrailing?: boolean;
326
+ /**
327
+ * Extension plugins applied during CBOR decoding.
328
+ * Extensions with `parseTag()` are invoked when a tagged item is
329
+ * encountered; returning a non-`undefined` value replaces the default
330
+ * `CborTag` node.
331
+ */
332
+ extensions?: CborExtension[];
333
+ }
334
+
335
+ export declare interface FromEDNOptions {
336
+ /**
337
+ * Character offset within the supplied text at which CBOR-EDN parsing starts.
338
+ * Leading whitespace/comments at or after this offset are skipped as usual.
339
+ *
340
+ * @default 0
341
+ */
342
+ offset?: number;
343
+ /**
344
+ * Allow tokens after the parsed item.
345
+ *
346
+ * When `false`, parsing still requires the item to consume the remaining
347
+ * input, preserving the historical single-item behaviour. Set this to `true`
348
+ * when using `CborItem.end` to continue parsing a CBOR-EDN sequence.
349
+ * Top-level comma separators are not skipped by `fromEDN()` itself; handle
350
+ * them in sequence-level code before passing the next `offset`. For example,
351
+ * after parsing `1, 2`, the first item's `end` points just before the comma;
352
+ * advance past that comma before parsing the next item.
353
+ *
354
+ * @example
355
+ * // Read two whitespace-separated items, validating that the second is last.
356
+ * const first = CBOR.fromEDN(text, { allowTrailing: true });
357
+ * const second = CBOR.fromEDN(text, { offset: first.end });
358
+ *
359
+ * @default false
360
+ */
361
+ allowTrailing?: boolean;
362
+ /**
363
+ * Extension plugins for EDN parsing.
364
+ * Each extension declares which app-string prefixes (and, in future, tag
365
+ * numbers) it handles via `appStringPrefixes` / `tagNumbers`, and provides
366
+ * callback methods that return `CborItem`-subclassed objects controlling
367
+ * subsequent serialisation.
368
+ *
369
+ * User-supplied extensions take priority over the built-in `dt`/`DT`
370
+ * extension for the same prefix.
371
+ */
372
+ extensions?: CborExtension[];
373
+ /**
374
+ * How to handle unrecognised application-extension identifiers
375
+ * (§4.1 draft-ietf-cbor-edn-literals-20).
376
+ *
377
+ * - `'cpa999'`: wrap the literal in a `CPA999` tag
378
+ * (`CborUnresolvedAppExt`) instead of failing. The resulting node
379
+ * round-trips through `toEDN()` back to the original notation.
380
+ * - `'error'`: throw `SyntaxError` for unknown prefixes.
381
+ * @default 'cpa999'
382
+ */
383
+ unresolvedExtension?: 'cpa999' | 'error';
384
+ /**
385
+ * When `true`, byte-string chunks in text string concatenation
386
+ * (`"a" + h'...'`) that are not valid UTF-8 are decoded with the Unicode
387
+ * replacement character (U+FFFD) instead of throwing a `SyntaxError`.
388
+ *
389
+ * The CBOR text string type (RFC 8949 §3.1) requires valid UTF-8;
390
+ * enabling this option produces non-conformant output and should only be
391
+ * used when interoperating with lenient producers.
392
+ *
393
+ * @default false
394
+ */
395
+ allowInvalidUtf8?: boolean;
396
+ /**
397
+ * Preserve comments found between CBOR-EDN values and attach them to the AST.
398
+ *
399
+ * Comments are metadata only: they are ignored by CBOR binary encoding and
400
+ * JavaScript conversion. Use together with `ToEDNOptions.preserveComments`
401
+ * to include them when formatting back to EDN.
402
+ *
403
+ * @default false
404
+ */
405
+ preserveComments?: boolean;
406
+ }
407
+
408
+ /**
409
+ * Options for parsing an annotated hex dump.
410
+ */
411
+ export declare interface FromHexDumpOptions {
412
+ /**
413
+ * Extension plugins applied during CBOR decoding.
414
+ * Extensions with `parseTag()` are invoked when a tagged item is encountered;
415
+ * returning a non-`undefined` value replaces the default `CborTag` node.
416
+ */
417
+ extensions?: CborExtension[];
418
+ }
419
+
420
+ export declare interface FromJSOptions {
421
+ /**
422
+ * Extension plugins applied during `fromJS()`.
423
+ * Extensions with `fromJS()` are given first chance to convert each value.
424
+ */
425
+ extensions?: CborExtension[];
426
+ /**
427
+ * How to encode integer-valued JS `number`s.
428
+ * - `'int'`: encode as CborUint / CborNint
429
+ * - `'float'`: always encode as CborFloat
430
+ * @default 'int'
431
+ */
432
+ encodeIntegerAs?: 'int' | 'float';
433
+ /**
434
+ * How to encode `Uint8Array` values.
435
+ * - `'bytes'`: encode as CborByteString
436
+ * - `'array'`: encode as CborArray of CborUint
437
+ * @default 'bytes'
438
+ */
439
+ uint8ArrayAs?: 'bytes' | 'array';
440
+ /**
441
+ * Pre-encoding replacer function or key allowlist, applied before the
442
+ * JavaScript value is converted to a CBOR AST node.
443
+ *
444
+ * - Function: called for every key/value pair (including `MapEntries`
445
+ * entries with non-string keys). Return `CBOR.OMIT` to remove the entry.
446
+ * When `undefinedOmits` is `true`, returning `undefined` also removes it.
447
+ * - Array of strings/numbers: allowlist of object keys to include.
448
+ * `MapEntries` entries retain all entries; their values are recursively
449
+ * filtered.
450
+ *
451
+ * Note: this option is honoured by `fromJS()` and the `CBOR.*` shortcut
452
+ * methods.
453
+ */
454
+ replacer?: ((this: unknown, key: unknown, value: unknown) => unknown) | (string | number)[];
455
+ /**
456
+ * When `true`, a replacer returning `undefined` removes the entry from the
457
+ * output, matching `JSON.stringify` behavior.
458
+ * When `false` (default), only `CBOR.OMIT` removes an entry; returning
459
+ * `undefined` keeps the entry as CBOR `undefined` (simple 23).
460
+ * @default false
461
+ */
462
+ undefinedOmits?: boolean;
463
+ }
464
+
465
+ export declare class MapEntries extends Array<[unknown, unknown]> {
466
+ toJSON(): Record<string, unknown>;
467
+ }
468
+
469
+ export declare class Null {
470
+ valueOf(): null;
471
+ toJSON(): null;
472
+ }
473
+
474
+ /**
475
+ * Wrapper for unrecognised CBOR simple values (0–255, excluding false/true/
476
+ * null/undefined). Returned by CborSimple.toJS() so that fromJS() can
477
+ * reconstruct the original CborSimple node and preserve the round-trip.
478
+ *
479
+ * Also serves as a namespace for simple-value utilities.
480
+ *
481
+ * @example
482
+ * const v = CBOR.fromEDN('simple(19)').toJS();
483
+ * Simple.is(v); // true
484
+ * Simple.get(v); // 19
485
+ *
486
+ * const node = CBOR.fromJS(new Simple(19));
487
+ * node.toEDN(); // "simple(19)"
488
+ */
489
+ export declare class Simple {
490
+ readonly value: number;
491
+ constructor(value: number);
492
+ valueOf(): number;
493
+ toJSON(): never;
494
+ /** Return true if value is a Simple instance. */
495
+ static is(value: unknown): value is Simple;
496
+ /** Return the simple number if value is a Simple instance, otherwise undefined. */
497
+ static get(value: unknown): number | undefined;
498
+ }
499
+
500
+ /**
501
+ * Namespace for CBOR tag annotation utilities.
502
+ *
503
+ * @example
504
+ * const v = CBOR.fromEDN('42("hello")').toJS();
505
+ * Tag.get(v); // 42n
506
+ * Tag.getValue(v); // "hello"
507
+ *
508
+ * const tagged = Tag.set([1, 2, 3], 100n);
509
+ * Tag.remove(tagged); // [1, 2, 3]
510
+ */
511
+ export declare class Tag {
512
+ private constructor();
513
+ /** Unique symbol used to attach a CBOR tag number to a JS value. */
514
+ static readonly symbol: typeof CBOR_TAG;
515
+ /** Wrapper class for tagged `null` values. */
516
+ static readonly Null: typeof Null;
517
+ /** Wrapper class for tagged `undefined` values. */
518
+ static readonly Undefined: typeof Undefined;
519
+ /** Return the CBOR tag number attached to `value`, or `undefined` if none. */
520
+ static get(value: unknown): bigint | undefined;
521
+ /** Attach a CBOR tag number to `value` and return the annotated value. */
522
+ static set(value: unknown, tag: bigint): object;
523
+ /** Remove the `[Tag.symbol]` annotation from `value` and return the plain value. */
524
+ static remove(value: unknown): unknown;
525
+ /** Return the underlying plain JS value held inside a tagged wrapper. */
526
+ static getValue(value: unknown): unknown;
527
+ }
528
+
529
+ export declare interface ToCBOROptions {
530
+ }
531
+
532
+ export declare interface ToEDNOptions {
533
+ /**
534
+ * Indentation for pretty-printing.
535
+ * - `number`: number of spaces
536
+ * - `string`: literal indent string (e.g. `'\t'`)
537
+ * - omit for single-line output
538
+ */
539
+ indent?: number | string;
540
+ /**
541
+ * Emit comments previously captured by `FromEDNOptions.preserveComments`.
542
+ *
543
+ * When enabled for containers, comment-bearing arrays/maps are emitted in
544
+ * multi-line form even if `indent` is omitted.
545
+ *
546
+ * @default false
547
+ */
548
+ preserveComments?: boolean;
549
+ /**
550
+ * Re-emit byte string literals parsed from EDN using their original source
551
+ * text when available.
552
+ *
553
+ * This preserves the spelling and interior layout of non-concatenated
554
+ * `h'...'`, `b64'...'`, `b32'...'`, `h32'...'`, raw-backtick byte strings,
555
+ * and single-quoted byte strings, including comments inside those literals.
556
+ * Byte strings produced by `+` concatenation are normalised as usual.
557
+ *
558
+ * When enabled, this takes precedence over `bstrEncoding` and `sqstr` for
559
+ * byte strings that carry original EDN source text.
560
+ *
561
+ * @default false
562
+ */
563
+ preserveByteString?: boolean;
564
+ /**
565
+ * Whether to emit commas between array/map elements.
566
+ * - `'comma'`: emit commas (`[1, 2, 3]`)
567
+ * - `'none'`: omit commas, use spaces only (`[1 2 3]`)
568
+ * - `'trailing'`: emit commas including a trailing comma after the last element
569
+ * @default 'comma'
570
+ */
571
+ commas?: 'comma' | 'none' | 'trailing';
572
+ /**
573
+ /**
574
+ * Fallback binary encoding for byte string literals when sqstr is not applicable.
575
+ * - `'hex'`: `h'...'`
576
+ * - `'base64'`: `b64'...'`
577
+ * - `'base64url'`: `b64'...'` (base64url alphabet)
578
+ * - `'base32'`: `b32'...'`
579
+ * - `'base32hex'`: `h32'...'`
580
+ * @default 'hex'
581
+ */
582
+ bstrEncoding?: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex';
583
+ /**
584
+ * Whether to prefer single-quoted string form (`sqstr`) for byte strings.
585
+ * - `'printable-string'`: emit `'...'` when the bytes are valid UTF-8 and
586
+ * contain no control characters; fall back to `bstrEncoding` otherwise.
587
+ * - `'string'`: emit `'...'` when the bytes are valid UTF-8;
588
+ * fall back to `bstrEncoding` otherwise.
589
+ * - `'none'`: never emit sqstr; always use `bstrEncoding`.
590
+ * @default 'printable-string'
591
+ */
592
+ sqstr?: 'printable-string' | 'string' | 'none';
593
+ /**
594
+ * Whether to use application-string / app-sequence notation for built-in
595
+ * extensions (e.g. `dt'...'`, `DT'...'`, `ip'...'`, `IP'...'`).
596
+ * - `true`: emit extension notation (`DT'2023-01-01T12:00:00Z'`)
597
+ * - `false`: emit raw CBOR notation (`1(-14159024)`, `52(h'c000022a')`)
598
+ * @default true
599
+ */
600
+ appStrings?: boolean;
601
+ /**
602
+ * Numeric format for integer values in EDN output.
603
+ * - `'decimal'`: standard decimal notation (e.g. `42`, `-14159024`)
604
+ * - `'hex'`: hexadecimal notation (e.g. `0x2a`, `-0xd83130`)
605
+ * - `'octal'`: octal notation (e.g. `0o52`, `-0o67061560`)
606
+ * - `'binary'`: binary notation (e.g. `0b101010`, `-0b110110000011000100110000`)
607
+ * @default 'decimal'
608
+ */
609
+ intFormat?: 'decimal' | 'hex' | 'octal' | 'binary';
610
+ /**
611
+ * Numeric format for floating-point values in EDN output.
612
+ * - `'decimal'`: standard decimal notation (e.g. `1.5`, `145544.0_3`)
613
+ * - `'hex'`: C99-style hex float notation (e.g. `0x1.8p+0`, `0x1.1c54p+17_3`)
614
+ * @default 'decimal'
615
+ */
616
+ floatFormat?: 'decimal' | 'hex';
617
+ /**
618
+ * Split long text strings using EDN string concatenation syntax (`"a" + "b"`).
619
+ * Only effective when `indent` is specified.
620
+ *
621
+ * - `'newline'`: split at newline characters
622
+ * - `'cboredn'`: split according to CBOR-EDN structure when the string content
623
+ * is parseable as CBOR-EDN (JSON superset)
624
+ *
625
+ * When both are specified, `'cboredn'` is tried first; `'newline'` is used
626
+ * only when the string content is not parseable as CBOR-EDN.
627
+ */
628
+ textStringFormat?: ('newline' | 'cboredn')[];
629
+ }
630
+
631
+ export declare interface ToHexDumpOptions {
632
+ /**
633
+ * Indentation per nesting level.
634
+ * - `number`: number of spaces (e.g. `3` → `" "`)
635
+ * - `string`: literal indent string (e.g. `'\t'`)
636
+ * @default 3
637
+ */
638
+ indent?: number | string;
639
+ /** Comment marker used in the hex dump. Default: `'--'` */
640
+ commentStyle?: '--' | '#';
641
+ }
642
+
643
+ export declare interface ToJSOptions {
644
+ /**
645
+ * How to represent CBOR integer values (major type 0 / 1) in JavaScript.
646
+ * - `'auto'`: `number` when the value is within the safe integer range
647
+ * (±`Number.MAX_SAFE_INTEGER`), `bigint` otherwise.
648
+ * - `'number'`: always `number` (precision may be lost for large values).
649
+ * - `'bigint'`: always `bigint`.
650
+ * @default 'auto'
651
+ */
652
+ integerAs?: 'auto' | 'number' | 'bigint';
653
+ /**
654
+ * How to represent CBOR map values when converting to JavaScript.
655
+ * - `'auto'`: text-string-only keys → `Record<string, unknown>`,
656
+ * other key types → `Map<unknown, unknown>`.
657
+ * Duplicate keys are silently overwritten (last value wins).
658
+ * - `'object'`: always `Record<string, unknown>` — non-string keys are
659
+ * converted via `String()`. Duplicate keys are overwritten (last wins).
660
+ * - `'entries'`: always `MapEntries` (a typed `Array` subclass) — preserves all
661
+ * entries including duplicate keys (§2.6.2 of draft-ietf-cbor-edn-literals-20).
662
+ * `fromJS()` recognises `MapEntries` instances and converts them back to `CborMap`.
663
+ * @default 'auto'
664
+ */
665
+ mapAs?: 'auto' | 'object' | 'entries';
666
+ /**
667
+ * Post-conversion reviver function, applied bottom-up after the CBOR value
668
+ * has been converted to JavaScript.
669
+ *
670
+ * Called for every key/value pair — including map entries with non-string
671
+ * keys — and finally for the root value with key `''`.
672
+ * Return `CBOR.OMIT` to remove the entry from its parent container.
673
+ * When `undefinedOmits` is `true`, returning `undefined` also removes the
674
+ * entry (matching `JSON.parse` behavior).
675
+ *
676
+ * Note: this option is honoured by `CborItem.toJS()` and the `CBOR.*`
677
+ * shortcut methods. Calling `_toJS()` directly bypasses it.
678
+ */
679
+ reviver?: (this: unknown, key: unknown, value: unknown) => unknown;
680
+ /**
681
+ * When `true`, a reviver returning `undefined` removes the entry from its
682
+ * parent container, matching `JSON.parse` behavior.
683
+ * When `false` (default), only `CBOR.OMIT` removes an entry; returning
684
+ * `undefined` keeps the entry as CBOR `undefined` (simple 23).
685
+ * @default false
686
+ */
687
+ undefinedOmits?: boolean;
688
+ }
689
+
690
+ export declare class Undefined {
691
+ valueOf(): undefined;
692
+ toJSON(): undefined;
693
+ }
694
+
695
+ export { }