@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.
Files changed (54) hide show
  1. package/README.ja.md +127 -49
  2. package/README.md +128 -49
  3. package/dist/ast/CborAppSeqResult.d.ts +20 -0
  4. package/dist/ast/CborArray.d.ts +3 -3
  5. package/dist/ast/CborBignum.d.ts +5 -5
  6. package/dist/ast/CborByteString.d.ts +2 -2
  7. package/dist/ast/CborEllipsis.d.ts +2 -2
  8. package/dist/ast/CborEmbeddedCBOR.d.ts +3 -3
  9. package/dist/ast/CborFloat.d.ts +8 -2
  10. package/dist/ast/CborIndefiniteByteString.d.ts +3 -3
  11. package/dist/ast/CborIndefiniteTextString.d.ts +3 -3
  12. package/dist/ast/CborItem.d.ts +22 -10
  13. package/dist/ast/CborMap.d.ts +3 -3
  14. package/dist/ast/CborNint.d.ts +2 -2
  15. package/dist/ast/CborSimple.d.ts +2 -2
  16. package/dist/ast/CborTag.d.ts +3 -3
  17. package/dist/ast/CborTextString.d.ts +2 -2
  18. package/dist/ast/CborUint.d.ts +2 -2
  19. package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
  20. package/dist/ast/index.cjs +1 -1
  21. package/dist/ast/index.js +2 -2
  22. package/dist/cbor.d.ts +44 -26
  23. package/dist/cdn/parser.d.ts +7 -0
  24. package/dist/{edn → cdn}/serialize-utils.d.ts +20 -7
  25. package/dist/cdn/serializer.d.ts +7 -0
  26. package/dist/cdn/test-vectors/runner.d.ts +22 -0
  27. package/dist/{edn → cdn}/tokenizer.d.ts +28 -25
  28. package/dist/extensions/b32.d.ts +5 -0
  29. package/dist/extensions/cri.d.ts +7 -7
  30. package/dist/extensions/dt.d.ts +10 -19
  31. package/dist/extensions/float.d.ts +7 -0
  32. package/dist/extensions/ip.d.ts +8 -8
  33. package/dist/extensions/same.d.ts +7 -0
  34. package/dist/extensions/types.d.ts +30 -8
  35. package/dist/index.cjs +5 -2
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.ts +4 -1
  38. package/dist/index.js +244 -77
  39. package/dist/index.js.map +1 -1
  40. package/dist/mapEntries-BccT62HT.cjs +36 -0
  41. package/dist/mapEntries-BccT62HT.cjs.map +1 -0
  42. package/dist/{mapEntries-D5MWtXqq.js → mapEntries-ZR8QJ0Yj.js} +1157 -853
  43. package/dist/mapEntries-ZR8QJ0Yj.js.map +1 -0
  44. package/dist/simple.d.ts +2 -2
  45. package/dist/tag.d.ts +1 -1
  46. package/dist/types.d.ts +141 -30
  47. package/dist/utils/hexfloat.d.ts +2 -2
  48. package/dist/utils/strip-comments.d.ts +12 -0
  49. package/package.json +13 -11
  50. package/dist/edn/parser.d.ts +0 -7
  51. package/dist/edn/serializer.d.ts +0 -7
  52. package/dist/mapEntries-D5MWtXqq.js.map +0 -1
  53. package/dist/mapEntries-bihZ3yks.cjs +0 -31
  54. package/dist/mapEntries-bihZ3yks.cjs.map +0 -1
@@ -1,10 +1,10 @@
1
1
  /**
2
- * EDN lexer (internal).
2
+ * CDN lexer (internal).
3
3
  *
4
4
  * Used by parser.ts for parsing and by CborTextString serialization to collect
5
- * source offsets after parseEDN() has already validated embedded CBOR-EDN.
5
+ * source offsets after parseCDN() has already validated embedded CDN.
6
6
  */
7
- export type TokenType = 'INTEGER' | 'FLOAT' | 'TSTR' | 'SQSTR' | 'RAWSTRING' | 'BYTES_HEX' | 'BYTES_HEX_ELIDED' | 'BYTES_B64' | 'BYTES_B32' | 'BYTES_H32' | 'APP_STRING' | 'APP_SEQUENCE' | 'EMPTY_INDEF_BYTES' | 'EMPTY_INDEF_TEXT' | 'TRUE' | 'FALSE' | 'NULL' | 'UNDEFINED' | 'SIMPLE' | 'LBRACKET' | 'RBRACKET' | 'LBRACE' | 'RBRACE' | 'LPAREN' | 'RPAREN' | 'COLON' | 'COMMA' | 'PLUS' | 'UNDERSCORE' | 'ENCODING_INDICATOR' | 'LT_LT' | 'GT_GT' | 'ELLIPSIS' | 'EOF';
7
+ export type TokenType = 'INTEGER' | 'FLOAT' | 'TSTR' | 'SQSTR' | 'RAWSTRING' | 'BYTES_HEX' | 'BYTES_HEX_ELIDED' | 'BYTES_B64' | 'APP_STRING' | 'APP_SEQUENCE' | 'EMPTY_INDEF_BYTES' | 'EMPTY_INDEF_TEXT' | 'TRUE' | 'FALSE' | 'NULL' | 'UNDEFINED' | 'SIMPLE' | 'LBRACKET' | 'RBRACKET' | 'LBRACE' | 'RBRACE' | 'LPAREN' | 'RPAREN' | 'COLON' | 'COMMA' | 'PLUS' | 'UNDERSCORE' | 'ENCODING_INDICATOR' | 'LT_LT' | 'GT_GT' | 'ELLIPSIS' | 'EOF';
8
8
  export interface Token {
9
9
  type: TokenType;
10
10
  /** Processed value: decoded string content, raw number text, raw byte content, etc. */
@@ -42,18 +42,26 @@ export declare class Tokenizer {
42
42
  private _lastConsumedEndOffset;
43
43
  /** Comments encountered while scanning, appended in source order. */
44
44
  readonly comments: EdnComment[];
45
+ /**
46
+ * When set, non-standard-but-JS-valid escape sequences are accepted instead
47
+ * of throwing. The callback receives a message and the position of the `\`
48
+ * (offset, line, column) so the parser can forward it as a ParseWarning.
49
+ */
50
+ onEscapeWarning?: (msg: string, offset: number, line: number, col: number) => void;
45
51
  constructor(input: string, options?: TokenizerOptions);
46
52
  peek(): Token;
47
53
  consume(): Token;
48
54
  /** Character offset just past the last character of the most recently consumed token. */
49
55
  get lastEndOffset(): number;
56
+ /** The full source text supplied to this tokenizer. */
57
+ get source(): string;
50
58
  private _ch;
51
59
  private _eof;
52
60
  private _advance;
53
61
  private _fail;
54
62
  private _skipWS;
55
63
  /**
56
- * Skip a comment in a quoted byte string literal (h'', b32'', h32'').
64
+ * Skip a comment in a quoted byte string literal (h'', b64'').
57
65
  * Returns true if a comment was consumed, false if the current char is not a
58
66
  * comment start. `quote` is the closing delimiter character.
59
67
  *
@@ -61,7 +69,16 @@ export declare class Tokenizer {
61
69
  */
62
70
  private _skipByteStringComment;
63
71
  /**
64
- * Skip a comment in a raw byte string (h``, b32``, h32``).
72
+ * Validate a `\uXXXX` or `\u{N}` escape inside a hex-string comment.
73
+ *
74
+ * Called immediately after the `u` character has been consumed. Rejects
75
+ * lone surrogates and invalid surrogate pairs; tolerates truncated/
76
+ * non-hex sequences (comments are informational, but surrogates are
77
+ * always illegal).
78
+ */
79
+ private _validateHexCommentUnicodeEscape;
80
+ /**
81
+ * Skip a comment in a raw byte string (h``, b64``).
65
82
  * Called with `i` pointing at the comment-start character.
66
83
  * Returns the index after the comment, or -1 if no comment was found.
67
84
  *
@@ -69,7 +86,7 @@ export declare class Tokenizer {
69
86
  * `context` is used in unterminated-comment error messages.
70
87
  */
71
88
  private _skipRawComment;
72
- /** Skip content until a closing `/` (CBOR-EDN block comment). */
89
+ /** Skip content until a closing `/` (CDN block comment). */
73
90
  private _skipBlockCommentSlash;
74
91
  /** Skip content until a closing `*\/` (JSONC block comment). */
75
92
  private _skipBlockCommentStar;
@@ -80,13 +97,13 @@ export declare class Tokenizer {
80
97
  * - Literal LF (U+000A) is allowed; all other C0 controls and U+007F are rejected.
81
98
  * - Literal CR (U+000D) is silently stripped (source-level CRLF normalisation).
82
99
  * - Only spec-defined escape sequences are accepted; `\q` etc. throw SyntaxError.
83
- * - `\/` is valid in both single- and double-quoted strings.
84
- * - `\\` (backslash) is always a valid escape.
100
+ * - `\/` is valid only in double-quoted strings (not in escapable-s, §5.1).
101
+ * - `\\` (backslash) is valid in both single- and double-quoted strings.
85
102
  * - `\uXXXX` for a high surrogate must be immediately followed by `\uXXXX` for
86
103
  * the corresponding low surrogate; lone surrogates are rejected.
87
104
  * - `\u{N}` … `\u{10FFFF}` extended syntax is supported; surrogates are rejected.
88
105
  * - In single-quoted strings, `\u` escapes to printable ASCII (U+0020–U+007E)
89
- * are forbidden (hexchar-s restriction, draft §2.5.2 / §5.1).
106
+ * are forbidden (hexchar-s restriction, draft-25 §5.1).
90
107
  */
91
108
  private _readStringContent;
92
109
  /**
@@ -101,9 +118,8 @@ export declare class Tokenizer {
101
118
  * which is then decoded into the corresponding non-BMP code point.
102
119
  *
103
120
  * In single-quoted strings (`quote === "'"`), `\u` escapes that resolve to
104
- * printable ASCII (U+0020–U+007E) are rejected per draft §2.5.2 / §5.1
105
- * hexchar-s, except for backslash (U+005C) and single-quote (U+0027), which
106
- * require escaping and cannot be written literally.
121
+ * printable ASCII (U+0020–U+007E) are rejected per draft-25 §5.1 hexchar-s.
122
+ * Use `\\` for backslash (U+005C) and `\'` for the single-quote delimiter.
107
123
  */
108
124
  private _readUnicodeEscape;
109
125
  /**
@@ -142,13 +158,6 @@ export declare class Tokenizer {
142
158
  * Returns the stripped base64 string.
143
159
  */
144
160
  private _processRawB64Content;
145
- /**
146
- * Post-process raw base32/base32hex content from `b32``…``\` / `h32``…``\` raw strings.
147
- *
148
- * Supports all comment forms (§2.2): `/ ... /`, `/*...*\/`, `//`, `#`.
149
- * HT is still forbidden (rawchars excludes %x09).
150
- */
151
- private _processRawB32Content;
152
161
  /**
153
162
  * Read raw byte-string content between `quote` chars (b64 / b64url).
154
163
  *
@@ -156,12 +165,6 @@ export declare class Tokenizer {
156
165
  * `/` is NOT treated as a comment delimiter because it is a valid base64 character.
157
166
  */
158
167
  private _readByteContent;
159
- /**
160
- * Read base32 / base32hex byte-string content (`b32'...'` / `h32'...'`).
161
- *
162
- * Supports all comment forms (§2.2): `/ ... /`, `/*...*\/`, `//`, `#`.
163
- */
164
- private _readB32Content;
165
168
  /**
166
169
  * Read hex byte-string content, recognising `...` ellipsis sequences (§4.2).
167
170
  *
@@ -0,0 +1,5 @@
1
+ import { CborExtension } from './types';
2
+ /** RFC 4648 §6 Base32 (A–Z 2–7) app-string extension. */
3
+ export declare const b32: CborExtension;
4
+ /** RFC 4648 §7 Base32Hex (0–9 A–V) app-string extension. */
5
+ export declare const h32: CborExtension;
@@ -1,28 +1,28 @@
1
- import { ToEDNOptions } from '../types';
1
+ import { ToCDNOptions } from '../types';
2
2
  import { CborExtension } from './types';
3
3
  import { CborArray } from '../ast/CborArray';
4
4
  import { CborTag } from '../ast/CborTag';
5
5
  /**
6
- * CBOR tag number for the tagged CRI variant (draft-ietf-cbor-edn-literals-21 §3.4 / §5.2.5).
6
+ * CBOR tag number for the tagged CRI variant (§3.4 and §5.2.5 of draft-ietf-cbor-edn-literals-25).
7
7
  */
8
8
  export declare const TAG_CRI = 99n;
9
9
  /**
10
- * Bare CRI array whose toEDN() emits cri'…' notation.
10
+ * Bare CRI array whose toCDN() emits cri'…' notation.
11
11
  * Falls back to generic array notation if the content cannot be expressed as a URI.
12
12
  */
13
13
  export declare class CborCriExt extends CborArray {
14
- _toEDN(options: ToEDNOptions | undefined, depth: number): string;
14
+ _toCDN(options: ToCDNOptions | undefined, depth: number): string;
15
15
  }
16
16
  /**
17
- * tag(99, CRI array) whose toEDN() emits CRI'…' notation.
17
+ * tag(99, CRI array) whose toCDN() emits CRI'…' notation.
18
18
  * Falls back to generic tag notation if the content cannot be expressed as a URI.
19
19
  */
20
20
  export declare class CborTaggedCriExt extends CborTag {
21
21
  constructor(content: CborArray);
22
- _toEDN(options: ToEDNOptions | undefined, depth: number): string;
22
+ _toCDN(options: ToCDNOptions | undefined, depth: number): string;
23
23
  }
24
24
  /**
25
- * Create the cri/CRI CborExtension (§5.2.5 draft-ietf-cbor-edn-literals-20).
25
+ * Create the cri/CRI CborExtension (§3.4 and §5.2.5 of draft-ietf-cbor-edn-literals-25).
26
26
  *
27
27
  * - `cri'uri'` → CborCriExt (bare CRI array, no CBOR tag)
28
28
  * - `CRI'uri'` → CborTaggedCriExt tag(99, CRI array)
@@ -1,4 +1,4 @@
1
- import { ToEDNOptions, ToJSOptions } from '../types';
1
+ import { ToCDNOptions, ToJSOptions } from '../types';
2
2
  import { CborExtension } from './types';
3
3
  import { CborUint } from '../ast/CborUint';
4
4
  import { CborNint } from '../ast/CborNint';
@@ -19,58 +19,49 @@ import { EncodingWidth } from '../cbor/encode';
19
19
  * used so that the float64 value is faithfully represented.
20
20
  */
21
21
  export declare function epochToRfc3339(epochSeconds: number): string;
22
- /**
23
- * Parse an RFC 3339 string and produce the appropriate epoch CborItem subclass.
24
- * Integer seconds → CborEpochDtExtUint or CborEpochDtExtNint.
25
- * Fractional seconds → CborEpochDtExtFloat.
26
- *
27
- * Fractional seconds are extracted from the string directly (via parseFloat)
28
- * before passing the remainder to Date.parse, so sub-millisecond precision
29
- * is preserved rather than being rounded to the nearest millisecond.
30
- */
31
- export declare function parseDtAppString(str: string): CborEpochDtExtUint | CborEpochDtExtNint | CborEpochDtExtFloat;
22
+ export declare function parseDtAppString(str: string, onError?: (msg: string) => void): CborEpochDtExtUint | CborEpochDtExtNint | CborEpochDtExtFloat;
32
23
  export declare const PREFIX_DT = "dt";
33
24
  export declare const PREFIX_DT_TAGGED = "DT";
34
25
  export declare const TAG_EPOCH = 1n;
35
26
  /**
36
- * Unsigned epoch timestamp whose toEDN() emits dt'…' notation.
27
+ * Unsigned epoch timestamp whose toCDN() emits dt'…' notation.
37
28
  * The RFC 3339 string is re-derived from the numeric value on each call.
38
29
  */
39
30
  export declare class CborEpochDtExtUint extends CborUint {
40
31
  constructor(value: number | bigint, options?: {
41
32
  encodingWidth?: EncodingWidth;
42
33
  });
43
- _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
34
+ _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
44
35
  }
45
36
  /**
46
- * Negative epoch timestamp whose toEDN() emits dt'…' notation.
37
+ * Negative epoch timestamp whose toCDN() emits dt'…' notation.
47
38
  * The RFC 3339 string is re-derived from the numeric value on each call.
48
39
  */
49
40
  export declare class CborEpochDtExtNint extends CborNint {
50
41
  constructor(value: number | bigint, options?: {
51
42
  encodingWidth?: EncodingWidth;
52
43
  });
53
- _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
44
+ _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
54
45
  }
55
46
  /**
56
- * Float epoch timestamp whose toEDN() emits dt'…' notation.
47
+ * Float epoch timestamp whose toCDN() emits dt'…' notation.
57
48
  * The RFC 3339 string is re-derived from the numeric value on each call.
58
49
  */
59
50
  export declare class CborEpochDtExtFloat extends CborFloat {
60
51
  constructor(value: number, options?: {
61
52
  precision?: 'half' | 'single' | 'double';
62
53
  });
63
- _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
54
+ _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
64
55
  }
65
56
  /**
66
- * CBOR tag(1, epoch) whose toEDN() emits DT'…' notation.
57
+ * CBOR tag(1, epoch) whose toCDN() emits DT'…' notation.
67
58
  * The RFC 3339 string is re-derived from the numeric content on each call.
68
59
  */
69
60
  export declare class CborTaggedEpochDtExt extends CborTag {
70
61
  constructor(datetime: string, options?: {
71
62
  encodingWidth?: EncodingWidth;
72
63
  });
73
- _toEDN(options: ToEDNOptions | undefined, depth: number): string;
64
+ _toCDN(options: ToCDNOptions | undefined, depth: number): string;
74
65
  }
75
66
  /**
76
67
  * CBOR tag(1, epoch) whose toJS() returns a plain Date object.
@@ -0,0 +1,7 @@
1
+ import { CborExtension } from './types';
2
+ /**
3
+ * Extension object for `float'...'` / `float<<...>>`.
4
+ * Pass to `parseCDN(..., { extensions: [float] })`.
5
+ */
6
+ export declare const float: CborExtension;
7
+ export default float;
@@ -1,35 +1,35 @@
1
- import { ToEDNOptions } from '../types';
1
+ import { ToCDNOptions } from '../types';
2
2
  import { CborExtension } from './types';
3
3
  import { CborItem } from '../ast/CborItem';
4
4
  import { CborByteString } from '../ast/CborByteString';
5
5
  import { CborTag } from '../ast/CborTag';
6
6
  import { CborArray } from '../ast/CborArray';
7
7
  /**
8
- * Bare IP address byte string whose toEDN() emits ip'…' notation.
8
+ * Bare IP address byte string whose toCDN() emits ip'…' notation.
9
9
  */
10
10
  export declare class CborIpExt extends CborByteString {
11
- _toEDN(options: ToEDNOptions | undefined, _depth: number): string;
11
+ _toCDN(options: ToCDNOptions | undefined, _depth: number): string;
12
12
  }
13
13
  /**
14
- * Bare IP address prefix (CIDR) whose toEDN() emits ip'…/prefix' notation.
14
+ * Bare IP address prefix (CIDR) whose toCDN() emits ip'…/prefix' notation.
15
15
  * Encoded as [prefixLen, truncatedBytes] per RFC 9164 §2.3, without a tag.
16
16
  */
17
17
  export declare class CborIpPrefixExt extends CborArray {
18
18
  private readonly _isV4;
19
19
  constructor(prefixLen: number, truncated: Uint8Array, isV4: boolean);
20
- _toEDN(options: ToEDNOptions | undefined, depth: number): string;
20
+ _toCDN(options: ToCDNOptions | undefined, depth: number): string;
21
21
  }
22
22
  /**
23
- * CBOR tag(52/54, …) IP address whose toEDN() emits IP'…' notation.
23
+ * CBOR tag(52/54, …) IP address whose toCDN() emits IP'…' notation.
24
24
  * Content may be a byte string (plain address) or an array [prefix, bytes]
25
25
  * (CIDR prefix per RFC 9164).
26
26
  */
27
27
  export declare class CborTaggedIpExt extends CborTag {
28
28
  constructor(tag: bigint, content: CborItem);
29
- _toEDN(options: ToEDNOptions | undefined, depth: number): string;
29
+ _toCDN(options: ToCDNOptions | undefined, depth: number): string;
30
30
  }
31
31
  /**
32
- * Create an ip/IP CborExtension (RFC 9164 / §3.3 draft-ietf-cbor-edn-literals-20).
32
+ * Create an ip/IP CborExtension (RFC 9164 / §3.2 of draft-ietf-cbor-edn-literals-25).
33
33
  *
34
34
  * - `ip'addr'` → CborIpExt (bare byte string, 4 or 16 bytes)
35
35
  * - `IP'addr'` → CborTaggedIpExt tag(52 or 54, bytes)
@@ -0,0 +1,7 @@
1
+ import { CborExtension } from './types';
2
+ /**
3
+ * Extension object for `same<<...>>`.
4
+ * Pass to `parseCDN(..., { extensions: [same] })`.
5
+ */
6
+ export declare const same: CborExtension;
7
+ export default same;
@@ -1,10 +1,10 @@
1
1
  import { CborItem } from '../ast/CborItem';
2
- import { FromJSOptions } from '../types';
2
+ import { FromCBOROptions, FromJSOptions } from '../types';
3
3
  /**
4
4
  * Plugin that extends EDN parsing, CBOR decoding, and `fromJS()` for specific
5
5
  * application-string prefixes or CBOR tag numbers.
6
6
  *
7
- * Pass instances via `FromEDNOptions.extensions`, `FromCBOROptions.extensions`,
7
+ * Pass instances via `FromCDNOptions.extensions`, `FromCBOROptions.extensions`,
8
8
  * or `FromJSOptions.extensions`.
9
9
  *
10
10
  * @example
@@ -15,7 +15,7 @@ import { FromJSOptions } from '../types';
15
15
  * return new CborByteString(parseIPv4(content));
16
16
  * },
17
17
  * };
18
- * parseEDN("ip'192.0.2.1'", { extensions: [ipExtension] });
18
+ * parseCDN("ip'192.0.2.1'", { extensions: [ipExtension] });
19
19
  */
20
20
  export interface CborExtension {
21
21
  /**
@@ -26,27 +26,49 @@ export interface CborExtension {
26
26
  /**
27
27
  * CBOR tag numbers this extension handles (e.g. `[0n, 1n]`).
28
28
  * Extensions with `parseTag()` are invoked for these tag numbers during
29
- * `fromCBOR()` and integer-tagged EDN items (`1(…)`) in `fromEDN()`.
29
+ * `fromCBOR()` and integer-tagged EDN items (`1(…)`) in `fromCDN()`.
30
30
  */
31
31
  readonly tagNumbers?: readonly bigint[];
32
32
  /**
33
33
  * Parse an app-string literal: `prefix'content'` or `prefix"content"`.
34
34
  * Receives the matched `prefix` and the decoded string `content`.
35
35
  * Throw `SyntaxError` to report invalid content.
36
+ *
37
+ * The CDN parser always passes an `onError` callback. Extensions may call
38
+ * `onError(msg)` instead of throwing to emit a recoverable violation; the
39
+ * callback emits a warning and, in strict mode, also throws. Extensions
40
+ * that ignore `onError` and throw directly always hard-fail regardless of
41
+ * the `strict` setting.
36
42
  */
37
- parseAppString?(prefix: string, content: string): CborItem;
43
+ parseAppString?(prefix: string, content: string, onError?: (msg: string) => void): CborItem;
38
44
  /**
39
45
  * Parse an app-sequence literal: `prefix<<item, ...>>`.
40
46
  * Receives the matched `prefix` and the array of parsed CBOR values.
41
47
  * If omitted, the `<<...>>` form is rejected with a `SyntaxError`.
48
+ * The `onError` callback follows the same contract as in `parseAppString`.
42
49
  */
43
- parseAppSequence?(prefix: string, items: CborItem[]): CborItem;
50
+ parseAppSequence?(prefix: string, items: CborItem[], onError?: (msg: string) => void): CborItem;
51
+ /**
52
+ * When `true`, the CDN parser wraps the result of `parseAppSequence` in a
53
+ * `CborAppSeqResult` so that `toCDN()` round-trips the original
54
+ * `prefix<<...>>` notation when `appStrings !== false`.
55
+ *
56
+ * Extensions whose result is already a subclass that handles source
57
+ * preservation itself (e.g. `CborFloat` via its `ednSource` property) should
58
+ * leave this unset.
59
+ */
60
+ readonly preserveAppSeqSource?: boolean;
44
61
  /**
45
62
  * Called when a `CborTag` is encountered during CBOR decode (`fromCBOR`)
46
- * or EDN integer-tag parsing (`fromEDN`).
63
+ * or EDN integer-tag parsing (`fromCDN`).
47
64
  * Return `undefined` to fall back to the default `CborTag` representation.
65
+ *
66
+ * `options` is supplied only from the binary CBOR decoder; it is `undefined`
67
+ * when called from the CDN parser. Extensions that perform nested CBOR
68
+ * decoding (e.g. tag 24) should forward these options to propagate
69
+ * `strict`, `onWarning`, and `silent` into the inner decode.
48
70
  */
49
- parseTag?(tag: bigint, value: CborItem): CborItem | undefined;
71
+ parseTag?(tag: bigint, value: CborItem, options?: FromCBOROptions): CborItem | undefined;
50
72
  /**
51
73
  * Called during `fromJS()` for every value before the default conversion
52
74
  * logic. Return `undefined` to fall through to the default behaviour.
package/dist/index.cjs CHANGED
@@ -1,3 +1,6 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./mapEntries-bihZ3yks.cjs`);var t=class t{static OMIT=e.C;static TAG=e.w;static Tag=e.E;static Simple=e.S;static MapEntries=e.t;static dt_as_Date=e.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,n){let r=t.fromCBOR(e,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,n){let r=t.fromEDN(e,this.#t(n));return r._defaults=this.#e,r}fromJS(e,n){let r=t.fromJS(e,this.#t(n));return r._defaults=this.#e,r}fromHexDump(e,n){let r=t.fromHexDump(e,this.#t(n));return r._defaults=this.#e,r}decode(e,n){return t.decode(e,this.#t(n))}encode(e,n){return t.encode(e,this.#t(n))}cborToCborEdn(e,n){return t.cborToCborEdn(e,this.#t(n))}cborEdnToCbor(e,n){return t.cborEdnToCbor(e,this.#t(n))}parse(e,n){if(typeof n==`function`){let r=this.#t({reviver:n});return t.fromEDN(e,r).toJS(r)}let r=this.#t(n);return t.fromEDN(e,r).toJS(r)}stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i={...this.#e};return n===null?i.replacer=void 0:(typeof n==`function`||Array.isArray(n))&&(i.replacer=n),r!==void 0&&(i.indent=a(r)),t.stringify(e,i)}return t.stringify(e,this.#t(n??void 0))}format(e,n){return t.format(e,this.#t(n))}static fromCBOR(t,n){return e.i(t,n)}static fromEDN(t,n){return e.s(t,n)}static fromJS(t,n){return e.r(t,n)}static fromHexDump(t,r){let i=[],a=n(t).trim().split(/\s+/).filter(Boolean);for(let e of a){if(!/^[0-9A-Fa-f]{2}$/.test(e))throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);i.push(parseInt(e,16))}return e.i(new Uint8Array(i),r)}static decode(e,n){return t.fromCBOR(e,n).toJS(n)}static encode(e,n){return t.fromJS(e,n).toCBOR(n)}static cborToCborEdn(e,n){return t.fromCBOR(e,n).toEDN(n)}static cborEdnToCbor(e,n){return t.fromEDN(e,n).toCBOR(n)}static parse(e,n){return typeof n==`function`?t.fromEDN(e).toJS({reviver:n}):t.fromEDN(e,n).toJS(n)}static stringify(t,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i=typeof n==`function`||Array.isArray(n)?n:void 0,o=a(r);if(i){let n=e.n(t,i);return n===void 0||n===e.C?void 0:e.r(n).toEDN(o===void 0?void 0:{indent:o})}return e.r(t).toEDN(o===void 0?void 0:{indent:o})}let i=n;if(i?.replacer){let n=e.n(t,i.replacer,i.extensions,i.undefinedOmits);if(n===void 0||n===e.C)return;let{replacer:r,...a}=i;return e.r(n,Object.keys(a).length>0?a:void 0).toEDN(i)}return e.r(t,i).toEDN(i)}static format(e,n){return t.fromEDN(e,n).toEDN(n)}};function n(e){let t=``,n=0;for(;n<e.length;){let a=e[n],o=e[n+1]??``;if(a===`-`&&o===`-`){n=r(e,n+2),t+=` `;continue}if(a===`#`){n=r(e,n+1),t+=` `;continue}if(a===`/`&&o===`/`){n=r(e,n+2),t+=` `;continue}if(a===`/`&&o===`*`){let r=e.indexOf(`*/`,n+2);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=i(e.slice(n,r+2)),n=r+2;continue}if(a===`/`){let r=e.indexOf(`/`,n+1);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=i(e.slice(n,r+1)),n=r+1;continue}t+=a,n++}return t}function r(e,t){let n=e.indexOf(`
2
- `,t);return n<0?e.length:n}function i(e){return e.replace(/[^\r\n]/g,` `)}function a(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.CBOR=t,exports.default=t,exports.CBOR_OMIT=e.C,exports.CBOR_TAG=e.w,exports.MapEntries=e.t,exports.Null=e.T,exports.Simple=e.S,exports.Tag=e.E,exports.Undefined=e.D,exports.dt_as_Date=e.a;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./mapEntries-BccT62HT.cjs");function t(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===`
2
+ `||r===`\r`){n++;continue}if(r===`#`){for(;n<e.length&&e[n]!==`
3
+ `;)n++;continue}if(r===`/`){let t=e[n+1]??``;if(t===`/`){for(;n<e.length&&e[n]!==`
4
+ `;)n++;continue}if(t===`*`){for(n+=2;n<e.length&&!(e[n]===`*`&&(e[n+1]??``)===`/`);)n++;if(n>=e.length)throw SyntaxError(`unterminated block comment`);n+=2;continue}for(n++;n<e.length&&e[n]!==`/`;)n++;if(n>=e.length)throw SyntaxError(`unterminated block comment`);n++;continue}t+=r,n++}return t}var n=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,r=`0123456789ABCDEFGHIJKLMNOPQRSTUV`;function i(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===61;)t--;return e.slice(0,t)}function a(e,t,n){let r=i(e).toUpperCase(),a=r.length%8;if(a===1||a===3||a===6)throw SyntaxError(`invalid base32 length: ${r.length} characters`);let o=new Uint8Array(128).fill(255);for(let e=0;e<t.length;e++)o[t.charCodeAt(e)]=e;let s=new Uint8Array(Math.floor(r.length*5/8)),c=0,l=0,u=0;for(let e of r){let t=e.charCodeAt(0),n=t<128?o[t]:255;if(n===255)throw SyntaxError(`invalid character in byte string: ${JSON.stringify(e)}`);c=c<<5|n,l+=5,l>=8&&(l-=8,s[u++]=c>>l&255)}if(l>0&&c&(1<<l)-1){let e=`non-zero trailing bits in base32 input`;if(n)n(e);else throw SyntaxError(e)}return s}var o={appStringPrefixes:[`b32`],parseAppString(r,i,o){return new e.g(a(t(i),n,o),{ednEncoding:`base32`})}},s={appStringPrefixes:[`h32`],parseAppString(n,i,o){return new e.g(a(t(i),r,o),{ednEncoding:`base32hex`})}},c=typeof Uint8Array.fromHex==`function`?e=>Uint8Array.fromHex(e):e=>{let t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.slice(n,n+2),16);return t},l=class extends e.v{_bits;constructor(t){super(e.x(t),{precision:`half`}),this._bits=t&65535}_toCBOR(){return new Uint8Array([249,this._bits>>8&255,this._bits&255])}},u=class extends e.v{_raw;constructor(e){super(new DataView(e.buffer,e.byteOffset).getFloat32(0,!1),{precision:`single`}),this._raw=e.slice()}_toCBOR(){let e=new Uint8Array(5);return e[0]=250,e.set(this._raw,1),e}},d=class extends e.v{_raw;constructor(e){super(new DataView(e.buffer,e.byteOffset).getFloat64(0,!1),{precision:`double`}),this._raw=e.slice()}_toCBOR(){let e=new Uint8Array(9);return e[0]=251,e.set(this._raw,1),e}};function f(e){if(e.length===2)return new l(e[0]<<8|e[1]);if(e.length===4)return new u(e);if(e.length===8)return new d(e);throw SyntaxError(`float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${e.length} bytes`)}var p={appStringPrefixes:[`float`],parseAppString(e,n){let r=t(n);if(!/^[0-9a-fA-F]*$/.test(r))throw SyntaxError(`float'...' contains non-hex characters`);if(r.length%2!=0)throw SyntaxError(`float'...' hex content has odd length (${r.length} digits)`);return f(c(r))},parseAppSequence(t,n,r){if(n.length===0)throw SyntaxError(`float<<...>> requires exactly one byte-string item`);if(n.length>1){let e=`float<<...>> expects 1 item; got ${n.length} — using first`;if(r)r(e);else throw SyntaxError(e)}if(!(n[0]instanceof e.g))throw SyntaxError(`float<<...>> item must be a byte string`);return f(n[0].value)}};function m(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var h={appStringPrefixes:[`same`],preserveAppSeqSource:!0,parseAppSequence(e,t,n){if(t.length===0)throw SyntaxError(`same<<...>> requires at least one item`);let r=t[0],i=r.toCBOR();for(let e=1;e<t.length;e++)if(!m(i,t[e].toCBOR())){let t=`same<<...>>: item ${e} produces different CBOR bytes than item 0`;if(n)n(t);else throw SyntaxError(t)}return r}},g=class t{static OMIT=e.w;static TAG=e.T;static Tag=e.D;static Simple=e.C;static MapEntries=e.t;static dt_as_Date=e.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,n){let r=t.fromCBOR(e,this.#t(n));return r._defaults=this.#e,r}fromCDN(e,n){let r=t.fromCDN(e,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,n){let r=t.fromJS(e,this.#t(n));return r._defaults=this.#e,r}fromHexDump(e,n){let r=t.fromHexDump(e,this.#t(n));return r._defaults=this.#e,r}decode(e,n){return t.decode(e,this.#t(n))}encode(e,n){return t.encode(e,this.#t(n))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,n){return t.cborToCdn(e,this.#t(n))}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,n){return t.cdnToCbor(e,this.#t(n))}parse(e,n){if(typeof n==`function`){let r=this.#t({reviver:n});return t.fromCDN(e,r).toJS(r)}let r=this.#t(n);return t.fromCDN(e,r).toJS(r)}stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i={...this.#e};return n===null?i.replacer=void 0:(typeof n==`function`||Array.isArray(n))&&(i.replacer=n),r!==void 0&&(i.indent=b(r)),t.stringify(e,i)}return t.stringify(e,this.#t(n??void 0))}format(e,n){return t.format(e,this.#t(n))}static fromCBOR(t,n){return e.i(t,n)}static fromCDN(t,n){return e.s(t,n)}static fromEDN(e,n){return t.fromCDN(e,n)}static fromJS(t,n){return e.r(t,n)}static fromHexDump(t,n){let r=[],i=_(t).trim().split(/\s+/).filter(Boolean);for(let e of i){if(!/^[0-9A-Fa-f]{2}$/.test(e))throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);r.push(parseInt(e,16))}return e.i(new Uint8Array(r),n)}static decode(e,n){return t.fromCBOR(e,n).toJS(n)}static encode(e,n){return t.fromJS(e,n).toCBOR(n)}static cborToCdn(e,n){return t.fromCBOR(e,n).toCDN(n)}static cborToCborEdn(e,n){return t.cborToCdn(e,n)}static cdnToCbor(e,n){return t.fromCDN(e,n).toCBOR(n)}static cborEdnToCbor(e,n){return t.cdnToCbor(e,n)}static parse(e,n){return typeof n==`function`?t.fromCDN(e).toJS({reviver:n}):t.fromCDN(e,n).toJS(n)}static stringify(t,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i=typeof n==`function`||Array.isArray(n)?n:void 0,a=b(r);if(i){let n=e.n(t,i);return n===void 0||n===e.w?void 0:e.r(n).toCDN(a===void 0?void 0:{indent:a})}return e.r(t).toCDN(a===void 0?void 0:{indent:a})}let i=n;if(i?.replacer){let n=e.n(t,i.replacer,i.extensions,i.undefinedOmits);if(n===void 0||n===e.w)return;let{replacer:r,...a}=i;return e.r(n,Object.keys(a).length>0?a:void 0).toCDN(i)}return e.r(t,i).toCDN(i)}static format(e,n){return t.fromCDN(e,n).toCDN(n)}};function _(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=v(e,n+2),t+=` `;continue}if(r===`#`){n=v(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=v(e,n+2),t+=` `;continue}if(r===`/`&&i===`*`){let r=e.indexOf(`*/`,n+2);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=y(e.slice(n,r+2)),n=r+2;continue}if(r===`/`){let r=e.indexOf(`/`,n+1);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=y(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function v(e,t){let n=e.indexOf(`
5
+ `,t);return n<0?e.length:n}function y(e){return e.replace(/[^\r\n]/g,` `)}function b(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.CBOR=g,exports.default=g,exports.CBOR_OMIT=e.w,exports.CBOR_TAG=e.T,exports.MapEntries=e.t,exports.Null=e.E,exports.Simple=e.C,exports.Tag=e.D,exports.Undefined=e.O,exports.b32=o,exports.dt_as_Date=e.a,exports.float=p,exports.h32=s,exports.same=h;
3
6
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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":"4IAwCA,IAAa,EAAb,MAAa,CAAK,CAMhB,OAAgB,KAAyB,EAAA,EAGzC,OAAgB,IAAuB,EAAA,EAGvC,OAAgB,IAAmB,EAAA,EAGnC,OAAgB,OAAyB,EAAA,EAGzC,OAAgB,WAAiC,EAAA,EAGjD,OAAgB,WAAiC,EAAA,EAIjD,GAWA,YAAY,EAAwB,CAClC,KAAKA,GAAY,GAAY,EAAE,CAGjC,GAAyB,EAA8B,CACrD,MAAO,CAAE,GAAG,KAAKA,GAAW,GAAI,GAAW,EAAE,CAAG,CAGlD,SACE,EACA,EACU,CACV,IAAM,EAAO,EAAK,SAAS,EAAO,KAAKC,GAAO,EAAQ,CAAC,CAEvD,MADA,GAAK,UAAY,KAAKD,GACf,EAGT,QAAQ,EAAc,EAAoC,CACxD,IAAM,EAAO,EAAK,QAAQ,EAAM,KAAKC,GAAO,EAAQ,CAAC,CAErD,MADA,GAAK,UAAY,KAAKD,GACf,EAGT,OAAO,EAAgB,EAAmC,CACxD,IAAM,EAAO,EAAK,OAAO,EAAO,KAAKC,GAAO,EAAQ,CAAC,CAErD,MADA,GAAK,UAAY,KAAKD,GACf,EAGT,YAAY,EAAc,EAAwC,CAChE,IAAM,EAAO,EAAK,YAAY,EAAM,KAAKC,GAAO,EAAQ,CAAC,CAEzD,MADA,GAAK,UAAY,KAAKD,GACf,EAGT,OACE,EACA,EACS,CACT,OAAO,EAAK,OAAO,EAAO,KAAKC,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,EAAK,QAAQ,IAAK,EAAI,EAAE,CACpC,GAAI,EAAM,EAAG,MAAU,YAAY,mCAAmC,CACtE,GAAO,EAAe,EAAK,MAAM,EAAG,EAAM,EAAE,CAAC,CAC7C,EAAI,EAAM,EACV,SAGF,GAAO,EACP,IAGF,OAAO,EAGT,SAAS,EAAgB,EAAc,EAAuB,CAC5D,IAAM,EAAM,EAAK,QAAQ;EAAM,EAAM,CACrC,OAAO,EAAM,EAAI,EAAK,OAAS,EAGjC,SAAS,EAAe,EAAsB,CAC5C,OAAO,EAAK,QAAQ,WAAY,IAAI,CAMtC,SAAS,EACP,EAC6B,CAC7B,GAAI,OAAO,GAAU,SAAU,CAC7B,IAAM,EAAI,KAAK,MAAM,KAAK,IAAI,GAAI,KAAK,IAAI,EAAG,EAAM,CAAC,CAAC,CACtD,OAAO,IAAM,EAAI,IAAA,GAAY,EAE/B,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,GAClB,EAAK,IAAA"}
1
+ {"version":3,"file":"index.cjs","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":"4IAWA,SAAgB,EAAc,EAAqB,CACjD,IAAI,EAAM,GACN,EAAI,EACR,KAAO,EAAI,EAAI,QAAQ,CACrB,IAAM,EAAK,EAAI,GACf,GAAI,IAAO,KAAO,IAAO;GAAQ,IAAO,KAAM,CAC5C,IACA,QACF,CACA,GAAI,IAAO,IAAK,CACd,KAAO,EAAI,EAAI,QAAU,EAAI,KAAO;GAAM,IAC1C,QACF,CACA,GAAI,IAAO,IAAK,CACd,IAAM,EAAO,EAAI,EAAI,IAAM,GAC3B,GAAI,IAAS,IAAK,CAChB,KAAO,EAAI,EAAI,QAAU,EAAI,KAAO;GAAM,IAC1C,QACF,CACA,GAAI,IAAS,IAAK,CAEhB,IADA,GAAK,EAEH,EAAI,EAAI,QACR,EAAE,EAAI,KAAO,MAAQ,EAAI,EAAI,IAAM,MAAQ,MAE3C,IACF,GAAI,GAAK,EAAI,OACX,MAAU,YAAY,4BAA4B,EACp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AAM,EAAI,IAAA,GAAY,CAC/B,CACA,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,EAClB,GAAK,IAAA,EAGhB"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- export type { CBOROptions, CborExtension, FromCBOROptions, ToCBOROptions, FromEDNOptions, ToEDNOptions, FromJSOptions, ToJSOptions, FromHexDumpOptions, ToHexDumpOptions, } from './types';
1
+ export type { CBOROptions, CborExtension, DecodeWarning, ParseWarning, FromCBOROptions, ToCBOROptions, FromCDNOptions, ToCDNOptions, FromEDNOptions, ToEDNOptions, FromJSOptions, ToJSOptions, FromHexDumpOptions, ToHexDumpOptions, } from './types';
2
2
  export { CBOR_TAG, Null, Tag, Undefined } from './tag';
3
3
  export { CBOR_OMIT } from './types';
4
4
  export { Simple } from './simple';
5
5
  export { MapEntries } from './mapEntries';
6
+ export { b32, h32 } from './extensions/b32';
7
+ export { float } from './extensions/float';
8
+ export { same } from './extensions/same';
6
9
  export { dt_as_Date } from './extensions/dt';
7
10
  export { CBOR } from './cbor';
8
11
  export { CBOR as default } from './cbor';