@cbortech/cbor 0.25.10 → 0.26.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.
package/README.ja.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [CBOR](#準拠している仕様)、[CDN (CBOR-EDN)](#準拠している仕様)、JavaScript 値を相互変換するための TypeScript ライブラリです。
4
4
 
5
+ ![CBOR、CDN、JavaScript 値の関係図](./assets/cbor-cdn-js.png)
6
+
5
7
  プレイグラウンドを **https://cbor.tech/cbor/** で公開しています。
6
8
 
7
9
  このパッケージは `CBOR` ファサードに加えて、extension の実装に必要な CBOR AST ノードクラス用の entrypoint を公開します。
@@ -212,15 +214,15 @@ console.log(text);
212
214
 
213
215
  ### テキスト文字列を分割して整形する
214
216
 
215
- `textStringSplit` を使うと、長いテキスト文字列を CDN の文字列連結として分割できます。
216
- このオプションは `indent` を指定したときに適用されます。
217
+ `splitNewline` を使うと、長いテキスト文字列を改行文字の位置で CDN の文字列連結として
218
+ 分割できます。このオプションは `indent` を指定したときに適用されます。
217
219
 
218
220
  ```ts
219
221
  import { CBOR } from '@cbortech/cbor';
220
222
 
221
223
  const text = CBOR.format('{"text": "line1\\nline2\\nline3"}', {
222
224
  indent: 2,
223
- textStringSplit: 'newline',
225
+ splitNewline: true,
224
226
  });
225
227
 
226
228
  console.log(text);
@@ -231,15 +233,16 @@ console.log(text);
231
233
  // }
232
234
  ```
233
235
 
234
- 文字列の中身が CDN や JSON 風の内容なら、`'cdn'` を使えます
235
- (`'cdn+newline'` で両方の分割を組み合わせられます)。
236
+ 文字列の中身が CDN や JSON 風の内容なら、`splitCdn` で周囲の CDN と同じように
237
+ 構造に応じた改行とインデントを入れて整形できます。両方のオプションは併用でき、
238
+ 配列で指定する従来の `textStringFormat` オプションを置き換えます(非推奨)。
236
239
 
237
240
  ```ts
238
241
  import { CBOR } from '@cbortech/cbor';
239
242
 
240
243
  const text = CBOR.format('{"cdn": "[1,2,3]"}', {
241
244
  indent: 2,
242
- textStringSplit: 'cdn',
245
+ splitCdn: true,
243
246
  });
244
247
 
245
248
  console.log(text);
@@ -259,6 +262,10 @@ console.log(text);
259
262
  元の連結の区切りを保持します。`preserveByteString` を併用すると、バイト文字列の
260
263
  各パートの元の表記も保持されます。
261
264
 
265
+ 分割オプションとの関係: 文字列の中身が CDN としてパースできる場合は `splitCdn` が
266
+ `preserveConcatenation` より優先されます。`splitNewline` は共存し、保持した各パートに
267
+ 改行文字が含まれていればさらにそこで分割します。
268
+
262
269
  ```ts
263
270
  import { CBOR } from '@cbortech/cbor';
264
271
 
@@ -427,6 +434,63 @@ console.log(text);
427
434
  // DT'2026-05-06T00:00:00Z'
428
435
  ```
429
436
 
437
+ ## 文字列連結と不定長文字列
438
+
439
+ draft-ietf-cbor-edn-literals-26(§3.4 / §3.5)の application extension
440
+ `t1` / `b1` / `ilbs` / `ilts` は、デフォルトで有効です。
441
+
442
+ `t1<<...>>` と `b1<<...>>` は、(テキストまたはバイト)文字列の引数を左から
443
+ 右へ結合し、1 つのテキスト文字列(`t1`)またはバイト文字列(`b1`)を
444
+ 作ります。引数には省略記号(`...`)も使えます。
445
+
446
+ ```ts
447
+ import { CBOR } from '@cbortech/cbor';
448
+
449
+ const text = CBOR.fromCDN('t1<<"Hello ", "world">>');
450
+ console.log(text.toCDN({ appStrings: false }));
451
+ // "Hello world"
452
+
453
+ const bytes = CBOR.fromCDN("b1<<'Hello ', h'776f726c64'>>");
454
+ console.log(bytes.toCDN({ appStrings: false }));
455
+ // 'Hello world'
456
+ ```
457
+
458
+ `ilbs<<...>>` / `ilts<<...>>` は、引数 1 つにつき 1 チャンクの不定長
459
+ バイト列/テキスト文字列を作ります。各引数のエンコーディング指示子は
460
+ チャンクに引き継がれます。draft-26 で非推奨となった `(_ chunk, ...)`
461
+ streamstring 構文の置き換えですが、本ライブラリは従来構文の入力も
462
+ 引き続き受理します。
463
+
464
+ ```ts
465
+ import { CBOR } from '@cbortech/cbor';
466
+
467
+ const v = CBOR.fromCDN("ilbs<<'Hello ', 'world'>>");
468
+ console.log(v.toCDN({ appStrings: false }));
469
+ // (_ 'Hello ', 'world')
470
+ ```
471
+
472
+ > [!NOTE]
473
+ > `t1` / `b1` という識別子は draft-26 で暫定(provisional)と明記されて
474
+ > おり、CBOR ワーキンググループにより改名される可能性があります。
475
+
476
+ ## float
477
+
478
+ 16 進数のビットパターンを IEEE 754 浮動小数点値として解釈します
479
+ (draft-ietf-cbor-edn-literals-26 §3.7)。デフォルトで有効です。
480
+
481
+ ```ts
482
+ import { CBOR } from '@cbortech/cbor';
483
+
484
+ const v = CBOR.fromCDN("float'7e00'");
485
+ console.log(v.toCDN({ appStrings: false }));
486
+ // NaN
487
+
488
+ // バイト列から解釈する場合
489
+ const v2 = CBOR.fromCDN("float<<h'3f800000'>>");
490
+ console.log(v2.toCDN({ appStrings: false }));
491
+ // 1.0_2
492
+ ```
493
+
430
494
  ## オプション extension
431
495
 
432
496
  このパッケージには、デフォルト有効ではないものの本体に同梱されている
@@ -453,25 +517,6 @@ console.log(v2.toCDN({ appStrings: false }));
453
517
  // h'003200'
454
518
  ```
455
519
 
456
- ### float
457
-
458
- 16 進数のビットパターンを IEEE 754 浮動小数点値として解釈します。
459
- [draft-bormann-cbor-edn-app-ext](https://datatracker.ietf.org/doc/draft-bormann-cbor-edn-app-ext/)
460
- に記載があり、[cbor-test-vectors](https://github.com/cbor-wg/cbor-test-vectors) でも使われています。
461
-
462
- ```ts
463
- import { CBOR, float } from '@cbortech/cbor';
464
-
465
- const v = CBOR.fromCDN("float'7e00'", { extensions: [float] });
466
- console.log(v.toCDN({ appStrings: false }));
467
- // NaN
468
-
469
- // バイト列から解釈する場合
470
- const v2 = CBOR.fromCDN("float<<h'3f800000'>>", { extensions: [float] });
471
- console.log(v2.toCDN({ appStrings: false }));
472
- // 1.0_2
473
- ```
474
-
475
520
  ### same
476
521
 
477
522
  `same<<expr, expr, ...>>` は、シーケンス内のすべての要素が同一の CBOR
@@ -724,6 +769,22 @@ AST ノードクラスは `@cbortech/cbor/ast` にあります。
724
769
  - [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
725
770
  - [Concise Diagnostic Notation (CDN), draft-ietf-cbor-edn-literals-25](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/)
726
771
 
772
+ draft -25 をベースに、
773
+ [draft -26](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/26/)
774
+ の一部仕様も先行して取り込んでいます。
775
+
776
+ - 文字列連結 extension `t1` / `b1`(§3.4)
777
+ - 不定長文字列 extension `ilbs` / `ilts`(§3.5)
778
+ - `float` extension のデフォルト有効化(§3.7)
779
+ - draft-26 の raw string 規則(§2.5.4): 終端デリミタは開始デリミタと
780
+ 同数のバッククォートに限られ、スペース除去規則がすべてのデリミタ長に
781
+ 適用されます
782
+
783
+ draft -26 で削除された `+` による文字列連結構文と、非推奨となった
784
+ `(_ ...)` streamstring 構文は、引き続き受理します。CDN は Internet-Draft
785
+ として策定中の仕様であり、今後も変更される可能性がある点に注意して
786
+ ください(たとえば extension 名 `t1` / `b1` は暫定とされています)。
787
+
727
788
  CDN は、CBOR データを人間が読み書きしやすいテキストとして表現するための記法です。
728
789
  サンプル、テストベクター、デバッグ、fixture、設定ファイルに近い用途など、CBOR のバイト列をそのまま扱うと読みにくい場面で役立ちます。
729
790
 
@@ -734,8 +795,6 @@ CDN は、CBOR データを人間が読み書きしやすいテキストとし
734
795
  CDN は JSON / JSONC の上位互換なので、通常の JSON データやコメント付きの JSON 風データも、
735
796
  特別な変換なしに CDN としてパース・整形できます。
736
797
 
737
- CDN はまだ広く普及した RFC ではなく、Internet-Draft として策定中の仕様です。
738
-
739
798
  ## ライセンス
740
799
 
741
800
  Apache-2.0
package/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  TypeScript library for converting between [CBOR](#specifications),
4
4
  [CDN (CBOR-EDN)](#specifications), and JavaScript values.
5
5
 
6
+ ![Relationship between CBOR, CDN, and JavaScript values](./assets/cbor-cdn-js.png)
7
+
6
8
  A live playground is available at **https://cbor.tech/cbor/**.
7
9
 
8
10
  This package exposes the `CBOR` facade plus a separate AST entrypoint for the
@@ -214,15 +216,15 @@ console.log(text);
214
216
 
215
217
  ### Split text strings while formatting
216
218
 
217
- `textStringSplit` can split long text strings with CDN string concatenation.
218
- It is applied when `indent` is specified.
219
+ `splitNewline` splits long text strings at newline characters using CDN
220
+ string concatenation. It is applied when `indent` is specified.
219
221
 
220
222
  ```ts
221
223
  import { CBOR } from '@cbortech/cbor';
222
224
 
223
225
  const text = CBOR.format('{"text": "line1\\nline2\\nline3"}', {
224
226
  indent: 2,
225
- textStringSplit: 'newline',
227
+ splitNewline: true,
226
228
  });
227
229
 
228
230
  console.log(text);
@@ -233,15 +235,17 @@ console.log(text);
233
235
  // }
234
236
  ```
235
237
 
236
- For strings that contain CDN or JSON-like content, use `'cdn'`
237
- (or `'cdn+newline'` to combine both split strategies).
238
+ For strings that contain CDN or JSON-like content, `splitCdn` formats the
239
+ string content with structure-aware line breaks and indentation, the same
240
+ way the surrounding CDN is formatted. Both options can be combined, and they
241
+ replace the deprecated array-valued `textStringFormat` option.
238
242
 
239
243
  ```ts
240
244
  import { CBOR } from '@cbortech/cbor';
241
245
 
242
246
  const text = CBOR.format('{"cdn": "[1,2,3]"}', {
243
247
  indent: 2,
244
- textStringSplit: 'cdn',
248
+ splitCdn: true,
245
249
  });
246
250
 
247
251
  console.log(text);
@@ -261,6 +265,11 @@ literal. `preserveConcatenation` keeps the original part boundaries for both
261
265
  text strings and byte strings; add `preserveByteString` to also keep the
262
266
  original spelling of byte string parts.
263
267
 
268
+ `preserveConcatenation` interacts with the split options: `splitCdn` takes
269
+ precedence when the string content parses as CDN, while `splitNewline`
270
+ combines with it by further splitting the preserved parts at newline
271
+ characters.
272
+
264
273
  ```ts
265
274
  import { CBOR } from '@cbortech/cbor';
266
275
 
@@ -431,6 +440,62 @@ console.log(text);
431
440
  // DT'2026-05-06T00:00:00Z'
432
441
  ```
433
442
 
443
+ ## String Concatenation and Indefinite-Length Strings
444
+
445
+ The `t1` / `b1` / `ilbs` / `ilts` application extensions from
446
+ draft-ietf-cbor-edn-literals-26 (§3.4 / §3.5) are enabled by default.
447
+
448
+ `t1<<...>>` and `b1<<...>>` join (text or byte) string arguments from left to
449
+ right into a single text string (`t1`) or byte string (`b1`). Arguments may
450
+ also be ellipses (`...`) to elide parts of a string.
451
+
452
+ ```ts
453
+ import { CBOR } from '@cbortech/cbor';
454
+
455
+ const text = CBOR.fromCDN('t1<<"Hello ", "world">>');
456
+ console.log(text.toCDN({ appStrings: false }));
457
+ // "Hello world"
458
+
459
+ const bytes = CBOR.fromCDN("b1<<'Hello ', h'776f726c64'>>");
460
+ console.log(bytes.toCDN({ appStrings: false }));
461
+ // 'Hello world'
462
+ ```
463
+
464
+ `ilbs<<...>>` / `ilts<<...>>` build an indefinite-length byte / text string
465
+ with one chunk per argument, honoring encoding indicators on each argument.
466
+ They replace the deprecated `(_ chunk, ...)` streamstring syntax for new CDN
467
+ documents; this library keeps accepting the legacy syntax on input.
468
+
469
+ ```ts
470
+ import { CBOR } from '@cbortech/cbor';
471
+
472
+ const v = CBOR.fromCDN("ilbs<<'Hello ', 'world'>>");
473
+ console.log(v.toCDN({ appStrings: false }));
474
+ // (_ 'Hello ', 'world')
475
+ ```
476
+
477
+ > [!NOTE]
478
+ > The identifiers `t1` and `b1` are explicitly provisional in draft-26 and
479
+ > may be renamed by the CBOR working group.
480
+
481
+ ## float
482
+
483
+ Interprets a hex bit-pattern as an IEEE 754 floating-point value
484
+ (draft-ietf-cbor-edn-literals-26 §3.7). Enabled by default.
485
+
486
+ ```ts
487
+ import { CBOR } from '@cbortech/cbor';
488
+
489
+ const v = CBOR.fromCDN("float'7e00'");
490
+ console.log(v.toCDN({ appStrings: false }));
491
+ // NaN
492
+
493
+ // Interpret bytes as float bits
494
+ const v2 = CBOR.fromCDN("float<<h'3f800000'>>");
495
+ console.log(v2.toCDN({ appStrings: false }));
496
+ // 1.0_2
497
+ ```
498
+
434
499
  ## Optional Extensions
435
500
 
436
501
  This package includes several bundled extensions that are not enabled by
@@ -458,26 +523,6 @@ console.log(v2.toCDN({ appStrings: false }));
458
523
  // h'003200'
459
524
  ```
460
525
 
461
- ### float
462
-
463
- Interprets a hex bit-pattern as an IEEE 754 floating-point value. This
464
- extension is described in
465
- [draft-bormann-cbor-edn-app-ext](https://datatracker.ietf.org/doc/draft-bormann-cbor-edn-app-ext/)
466
- and also used in [cbor-test-vectors](https://github.com/cbor-wg/cbor-test-vectors).
467
-
468
- ```ts
469
- import { CBOR, float } from '@cbortech/cbor';
470
-
471
- const v = CBOR.fromCDN("float'7e00'", { extensions: [float] });
472
- console.log(v.toCDN({ appStrings: false }));
473
- // NaN
474
-
475
- // Interpret bytes as float bits
476
- const v2 = CBOR.fromCDN("float<<h'3f800000'>>", { extensions: [float] });
477
- console.log(v2.toCDN({ appStrings: false }));
478
- // 1.0_2
479
- ```
480
-
481
526
  ### same
482
527
 
483
528
  `same<<expr, expr, ...>>` verifies that every item in the sequence encodes to
@@ -729,6 +774,22 @@ This library targets:
729
774
  - [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
730
775
  - [Concise Diagnostic Notation (CDN), draft-ietf-cbor-edn-literals-25](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/)
731
776
 
777
+ On top of draft -25, this library already incorporates parts of
778
+ [draft -26](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/26/):
779
+
780
+ - the `t1` / `b1` string-concatenation extensions (§3.4)
781
+ - the `ilbs` / `ilts` indefinite-length string extensions (§3.5)
782
+ - the `float` extension as a default extension (§3.7)
783
+ - the draft-26 raw-string delimiter and trimming rules (§2.5.4): the closing
784
+ delimiter must have exactly as many backquotes as the opening one, and the
785
+ space-trimming rule applies to all delimiter lengths
786
+
787
+ The legacy `+` string-concatenation syntax (removed in draft -26) and the
788
+ `(_ ...)` streamstring syntax (deprecated in draft -26) are still accepted.
789
+ Note that the CDN specification is still an Internet-Draft and may continue
790
+ to change (for example, the extension names `t1` and `b1` are explicitly
791
+ provisional).
792
+
732
793
  CDN is a human-readable text notation for CBOR data. It is useful for
733
794
  examples, test vectors, debugging, fixtures, and configuration-like files where
734
795
  raw CBOR bytes would be hard to read.
@@ -742,8 +803,6 @@ CDN is a superset of JSON and JSONC, so ordinary JSON data and
742
803
  commented JSON-style data can be parsed and formatted as CDN without
743
804
  special handling.
744
805
 
745
- CDN is still an Internet-Draft rather than a widely deployed RFC.
746
-
747
806
  ## License
748
807
 
749
808
  Apache-2.0
Binary file
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-B-INYL6l.cjs");exports.CborArray=e.p,exports.CborBigNint=e.c,exports.CborBigUint=e.l,exports.CborByteString=e.g,exports.CborEmbeddedCBOR=e.u,exports.CborFloat=e.v,exports.CborIndefiniteByteString=e.h,exports.CborIndefiniteTextString=e.m,exports.CborItem=e.x,exports.CborMap=e.f,exports.CborNint=e.y,exports.CborSimple=e.d,exports.CborTag=e._,exports.CborTextString=e.o,exports.CborUint=e.b;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-DJtvWpWq.cjs");exports.CborArray=e.y,exports.CborBigNint=e.m,exports.CborBigUint=e.h,exports.CborByteString=e.S,exports.CborEmbeddedCBOR=e.g,exports.CborFloat=e.w,exports.CborIndefiniteByteString=e.x,exports.CborIndefiniteTextString=e.b,exports.CborItem=e.D,exports.CborMap=e.v,exports.CborNint=e.T,exports.CborSimple=e._,exports.CborTag=e.C,exports.CborTextString=e.f,exports.CborUint=e.E;
package/dist/ast/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as e, b as t, c as n, d as r, f as i, g as a, h as o, l as s, m as c, o as l, p as u, u as d, v as f, x as p, y as m } from "../mapEntries-B8riGPMD.js";
2
- export { u as CborArray, n as CborBigNint, s as CborBigUint, a as CborByteString, d as CborEmbeddedCBOR, f as CborFloat, o as CborIndefiniteByteString, c as CborIndefiniteTextString, p as CborItem, i as CborMap, m as CborNint, r as CborSimple, e as CborTag, l as CborTextString, t as CborUint };
1
+ import { C as e, D as t, E as n, S as r, T as i, _ as a, b as o, f as s, g as c, h as l, m as u, v as d, w as f, x as p, y as m } from "../mapEntries-BdzS6bFp.js";
2
+ export { m as CborArray, u as CborBigNint, l as CborBigUint, r as CborByteString, c as CborEmbeddedCBOR, f as CborFloat, p as CborIndefiniteByteString, o as CborIndefiniteTextString, t as CborItem, d as CborMap, i as CborNint, a as CborSimple, e as CborTag, s as CborTextString, n as CborUint };
@@ -1,3 +1,3 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../tokenizer-CVcIyZZa.cjs");function t(t){let n=new e.t(t),r=[];for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}function n(t){let n=new e.t(t),r=[];try{for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}catch(i){let a=i instanceof e.o?i:new e.o(i instanceof Error?i.message:String(i)),o=n.lastEndOffset;if(o<t.length){let e=1,n=1;for(let r=0;r<o;r++)t[r]===`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../tokenizer-EciPlN0n.cjs");function t(t){let n=new e.t(t),r=[];for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}function n(t){let n=new e.t(t),r=[];try{for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}catch(i){let a=i instanceof e.o?i:new e.o(i instanceof Error?i.message:String(i)),o=n.lastEndOffset;if(o<t.length){let e=1,n=1;for(let r=0;r<o;r++)t[r]===`
2
2
  `?(e++,n=1):n++;r.push({type:`ERROR`,value:t.slice(o),raw:t.slice(o),line:e,col:n,offset:o,endOffset:t.length})}return{tokens:r,comments:n.comments,error:a}}}exports.CdnSyntaxError=e.o,exports.tokenize=t,exports.tokenizeLenient=n;
3
3
  //# sourceMappingURL=index.cjs.map
package/dist/cdn/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as e, t } from "../tokenizer-DkLlZ1gc.js";
1
+ import { o as e, t } from "../tokenizer-CeuixxXi.js";
2
2
  //#region src/cdn/index.ts
3
3
  function n(e) {
4
4
  let n = new t(e), r = [];
@@ -139,14 +139,17 @@ export declare class Tokenizer {
139
139
  */
140
140
  private _readUnicodeEscape;
141
141
  /**
142
- * Read raw text-string content between N-backtick delimiters (§2.5.3).
142
+ * Read raw text-string content between N-backtick delimiters
143
+ * (§2.5.4 of draft-ietf-cbor-edn-literals-26).
143
144
  *
144
145
  * - The opening delimiter is the maximal run of consecutive backticks (N ≥ 1).
145
- * - A single leading newline (LF or CRLF) immediately after the opening is stripped.
146
146
  * - No escape sequences are processed — content is taken verbatim.
147
- * - Literal CR is stripped for source-level CRLF normalisation.
148
- * - The closing delimiter is the first run of M N backticks; any excess
149
- * M-N backticks are appended to the content before closing.
147
+ * - Literal CR is stripped for source-level CRLF normalisation (§1.3.5).
148
+ * - The closing delimiter is a run of exactly N backticks (alikerawdelim);
149
+ * shorter runs are content, longer runs are an error.
150
+ * - A single leading newline (LF or CRLF) is stripped; if that rule did not
151
+ * apply and the inner string both starts and ends with a space, exactly
152
+ * one leading and one trailing space are stripped.
150
153
  */
151
154
  private _readRawStringContent;
152
155
  /**
@@ -0,0 +1,5 @@
1
+ import { CborExtension } from './types';
2
+ /** Extension object for `t1'...'` / `t1<<...>>` (text-string concatenation). */
3
+ export declare const t1: CborExtension;
4
+ /** Extension object for `b1'...'` / `b1<<...>>` (byte-string concatenation). */
5
+ export declare const b1: CborExtension;
@@ -0,0 +1,5 @@
1
+ import { CborExtension } from './types';
2
+ /** Extension object for `ilbs<<...>>` (indefinite-length byte string). */
3
+ export declare const ilbs: CborExtension;
4
+ /** Extension object for `ilts<<...>>` (indefinite-length text string). */
5
+ export declare const ilts: CborExtension;
package/dist/index.cjs CHANGED
@@ -1,13 +1,10 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./tokenizer-CVcIyZZa.cjs"),t=require("./mapEntries-B-INYL6l.cjs");function n(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 r=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,i=`0123456789ABCDEFGHIJKLMNOPQRSTUV`;function a(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===61;)t--;return e.slice(0,t)}function o(e,t,n){let r=a(e).toUpperCase(),i=r.length%8;if(i===1||i===3||i===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 s={appStringPrefixes:[`b32`],parseAppString(e,i,a){return new t.g(o(n(i),r,a),{ednEncoding:`base32`})}},c={appStringPrefixes:[`h32`],parseAppString(e,r,a){return new t.g(o(n(r),i,a),{ednEncoding:`base32hex`})}},l=class extends t.v{_bits;constructor(e){super(t.S(e),{precision:`half`}),this._bits=e&65535}_toCBOR(){return new Uint8Array([249,this._bits>>8&255,this._bits&255])}},u=class extends t.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 t.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`)}function p(e){let t=e>>>15&1,n=e>>>10&31,r=e&1023,i;if(n===31)i=t<<31|2139095040|r<<13;else if(n===0&&r===0)i=t<<31;else if(n===0){let e=r,n=0;for(;!(e&512);)e<<=1,n++;i=t<<31|112-n<<23|(e&511)<<14}else i=t<<31|n+112<<23|r<<13;let a=new Uint8Array(4);return new DataView(a.buffer).setUint32(0,i>>>0,!1),a}function m(e){let t=e>>>15&1,n=e>>>10&31,r=e&1023,i=new Uint8Array(8),a=new DataView(i.buffer);if(n===31)a.setUint32(0,(t<<31|2146435072|r<<10)>>>0,!1),a.setUint32(4,0,!1);else if(n===0&&r===0)a.setUint32(0,t<<31>>>0,!1),a.setUint32(4,0,!1);else if(n===0){let e=r,n=0;for(;!(e&512);)e<<=1,n++;a.setUint32(0,(t<<31|1008-n<<20|(e&511)<<11)>>>0,!1),a.setUint32(4,0,!1)}else a.setUint32(0,(t<<31|n+1008<<20|r<<10)>>>0,!1),a.setUint32(4,0,!1);return i}function h(e){let t=new DataView(e.buffer,e.byteOffset).getUint32(0,!1),n=t>>>31&1,r=t>>>23&255,i=t&8388607,a=new Uint8Array(8),o=new DataView(a.buffer);if(r===255)o.setUint32(0,(n<<31|2146435072|i>>>3)>>>0,!1),o.setUint32(4,(i&7)<<29,!1);else if(r===0&&i===0)o.setUint32(0,n<<31>>>0,!1),o.setUint32(4,0,!1);else{let t=new DataView(e.buffer,e.byteOffset).getFloat32(0,!1);o.setFloat64(0,t,!1)}return a}function g(e,n,r){let i=e.length===2?1:e.length===4?2:3;if(i===1){let t=e[0]<<8|e[1];if(n===2)return new u(p(t));if(n===3)return new d(m(t))}if(i===2){if(n===3)return new d(h(e));if(n===1){let n=new DataView(e.buffer,e.byteOffset).getFloat32(0,!1),i=t.C(n);return!Object.is(t.S(i),n)&&!isNaN(n)&&r(`float'...' value cannot be exactly represented as float16 (_1)`),new l(i)}}if(i===3){let i=new DataView(e.buffer,e.byteOffset).getFloat64(0,!1);if(n===1){let e=t.C(i);return!Object.is(t.S(e),i)&&!isNaN(i)&&r(`float'...' value cannot be exactly represented as float16 (_1)`),new l(e)}if(n===2){let e=Math.fround(i);!Object.is(e,i)&&!isNaN(i)&&r(`float'...' value cannot be exactly represented as float32 (_2)`);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!1),new u(t)}}return f(e)}var _={appStringPrefixes:[`float`],parseAppString(t,r,i,a){let o=n(r);if(!/^[0-9a-fA-F]*$/.test(o))throw SyntaxError(`float'...' contains non-hex characters`);if(o.length%2!=0)throw SyntaxError(`float'...' hex content has odd length (${o.length} digits)`);let s=e.a(o),c=a?.encodingWidth;if(c===void 0)return f(s);if(c!==1&&c!==2&&c!==3){let e=`float'...' encoding indicator _${c} is not valid; use _1, _2, or _3`;if(i)return i(e),f(s);throw SyntaxError(e)}return c===(s.length===2?1:s.length===4?2:3)?f(s):g(s,c,i??(e=>{throw SyntaxError(e)}))},parseAppSequence(e,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 t.g))throw SyntaxError(`float<<...>> item must be a byte string`);return f(n[0].value)}};function v(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 y={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(!v(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}},b=class n{static OMIT=t.T;static TAG=t.E;static Tag=t.O;static Simple=t.w;static MapEntries=t.t;static dt_as_Date=t.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,t){let r=n.fromCBOR(e,this.#t(t));return r._defaults=this.#e,r}fromCDN(e,t){let r=n.fromCDN(e,this.#t(t));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,t){let r=n.fromJS(e,this.#t(t));return r._defaults=this.#e,r}fromHexDump(e,t){let r=n.fromHexDump(e,this.#t(t));return r._defaults=this.#e,r}*fromCBORSeq(e,t){for(let r of n.fromCBORSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromCDNSeq(e,t){for(let r of n.fromCDNSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromHexDumpSeq(e,t){for(let r of n.fromHexDumpSeq(e,this.#t(t)))r._defaults=this.#e,yield r}decode(e,t){return n.decode(e,this.#t(t))}*decodeSeq(e,t){yield*n.decodeSeq(e,this.#t(t))}*parseSeq(e,t){yield*n.parseSeq(e,this.#t(t))}encode(e,t){return n.encode(e,this.#t(t))}compile(e,t){return n.compile(e,this.#t(t))}decompile(e,t){return n.decompile(e,this.#t(t))}toHex(e,t){return n.toHex(e,this.#t(t))}fromHex(e,t){return n.fromHex(e,this.#t(t))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,t){let r=this.#t(t),i=n.fromCBOR(e,r);return i._defaults=this.#e,i.toCDN(r)}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,t){let r=this.#t(t);return n.fromCDN(e,r).toCBOR(r)}parse(e,t){if(typeof t==`function`){let r=this.#t({reviver:t});return n.fromCDN(e,r).toJS(r)}let r=this.#t(t);return n.fromCDN(e,r).toJS(r)}stringify(e,t,r){if(typeof t==`function`||Array.isArray(t)||t===null||t===void 0&&r!==void 0){let i={...this.#e};return t===null?i.replacer=void 0:(typeof t==`function`||Array.isArray(t))&&(i.replacer=t),r!==void 0&&(i.indent=D(r)),n.stringify(e,i)}return n.stringify(e,this.#t(t??void 0))}format(e,t){return n.format(e,this.#t(t))}static fromCBOR(e,n){return t.i(e,n)}static fromCDN(e,n){return t.s(e,n)}static fromEDN(e,t){return n.fromCDN(e,t)}static*fromHexDumpSeq(e,t){let r=[],i=x(e).trim().split(/\s+/).filter(Boolean);for(let e of i)if(/^[0-9A-Fa-f]{2}$/.test(e))r.push(parseInt(e,16));else if(/^[0-9A-Fa-f]+$/.test(e)&&e.length%2==0)for(let t=0;t<e.length;t+=2)r.push(parseInt(e.slice(t,t+2),16));else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);yield*n.fromCBORSeq(new Uint8Array(r),t)}static*fromCBORSeq(e,n){let r=e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength),i=0;for(;i<r.byteLength;){let e=t.i(r,{...n,offset:i,allowTrailing:!0});yield e,i=e.end}}static*fromCDNSeq(n,r){let i=!!r?.preserveComments,a=0,o=!0;for(;;){let{offset:s,hadSeparator:c,commaOffset:l}=E(n,a,r,i?o?`all`:`after-newline`:`none`);if(o&&l>=0){let e=`leading comma in CDN sequence`;if(r?.strict!==!1)throw SyntaxError(e);w(e,l,r)}if(s>=n.length||i&&T(n,s)&&E(n,s,r).offset>=n.length)break;if(!o&&!c){let e=`CDN sequence items must be separated by whitespace, comma, or comment`;if(r?.strict!==!1)throw SyntaxError(e);w(e,s,r)}a=s;let u;try{u=t.s(n,{...r,offset:a,allowTrailing:!0,_skipRS:!0})}catch(t){if(r?.strict!==!1)throw t;w(t instanceof Error?t.message:String(t),a,r,!0,t instanceof e.o?t:void 0);break}yield u,a=u.end,o=!1}}static fromJS(e,n){return t.r(e,n)}static fromHexDump(e,n){let r=[],i=x(e).trim().split(/\s+/).filter(Boolean);for(let e of i)if(/^[0-9A-Fa-f]{2}$/.test(e))r.push(parseInt(e,16));else if(/^[0-9A-Fa-f]+$/.test(e)&&e.length%2==0)for(let t=0;t<e.length;t+=2)r.push(parseInt(e.slice(t,t+2),16));else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);return t.i(new Uint8Array(r),n)}static decode(e,t){return n.fromCBOR(e,t).toJS(t)}static*decodeSeq(e,t){for(let r of n.fromCBORSeq(e,t))yield r.toJS(t)}static*parseSeq(e,t){for(let r of n.fromCDNSeq(e,t))yield r.toJS(t)}static encode(e,t){return n.fromJS(e,t).toCBOR(t)}static compile(e,t){let r=[...n.fromCDNSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static decompile(e,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toCDN(t)).join(`
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./tokenizer-EciPlN0n.cjs"),t=require("./mapEntries-DJtvWpWq.cjs");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(e,r,i){return new t.S(a(t.a(r),n,i),{ednEncoding:`base32`})}},s={appStringPrefixes:[`h32`],parseAppString(e,n,i){return new t.S(a(t.a(n),r,i),{ednEncoding:`base32hex`})}};function c(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 l={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(!c(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}},u=class n{static OMIT=t.k;static TAG=t.A;static Tag=t.M;static Simple=t.O;static MapEntries=t.t;static dt_as_Date=t.d;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,t){let r=n.fromCBOR(e,this.#t(t));return r._defaults=this.#e,r}fromCDN(e,t){let r=n.fromCDN(e,this.#t(t));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,t){let r=n.fromJS(e,this.#t(t));return r._defaults=this.#e,r}fromHexDump(e,t){let r=n.fromHexDump(e,this.#t(t));return r._defaults=this.#e,r}*fromCBORSeq(e,t){for(let r of n.fromCBORSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromCDNSeq(e,t){for(let r of n.fromCDNSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromHexDumpSeq(e,t){for(let r of n.fromHexDumpSeq(e,this.#t(t)))r._defaults=this.#e,yield r}decode(e,t){return n.decode(e,this.#t(t))}*decodeSeq(e,t){yield*n.decodeSeq(e,this.#t(t))}*parseSeq(e,t){yield*n.parseSeq(e,this.#t(t))}encode(e,t){return n.encode(e,this.#t(t))}compile(e,t){return n.compile(e,this.#t(t))}decompile(e,t){return n.decompile(e,this.#t(t))}toHex(e,t){return n.toHex(e,this.#t(t))}fromHex(e,t){return n.fromHex(e,this.#t(t))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,t){let r=this.#t(t),i=n.fromCBOR(e,r);return i._defaults=this.#e,i.toCDN(r)}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,t){let r=this.#t(t);return n.fromCDN(e,r).toCBOR(r)}parse(e,t){if(typeof t==`function`){let r=this.#t({reviver:t});return n.fromCDN(e,r).toJS(r)}let r=this.#t(t);return n.fromCDN(e,r).toJS(r)}stringify(e,t,r){if(typeof t==`function`||Array.isArray(t)||t===null||t===void 0&&r!==void 0){let i={...this.#e};return t===null?i.replacer=void 0:(typeof t==`function`||Array.isArray(t))&&(i.replacer=t),r!==void 0&&(i.indent=_(r)),n.stringify(e,i)}return n.stringify(e,this.#t(t??void 0))}format(e,t){return n.format(e,this.#t(t))}static fromCBOR(e,n){return t.u(e,n)}static fromCDN(e,n){return t.p(e,n)}static fromEDN(e,t){return n.fromCDN(e,t)}static*fromHexDumpSeq(e,t){let r=[],i=d(e).trim().split(/\s+/).filter(Boolean);for(let e of i)if(/^[0-9A-Fa-f]{2}$/.test(e))r.push(parseInt(e,16));else if(/^[0-9A-Fa-f]+$/.test(e)&&e.length%2==0)for(let t=0;t<e.length;t+=2)r.push(parseInt(e.slice(t,t+2),16));else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);yield*n.fromCBORSeq(new Uint8Array(r),t)}static*fromCBORSeq(e,n){let r=e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength),i=0;for(;i<r.byteLength;){let e=t.u(r,{...n,offset:i,allowTrailing:!0});yield e,i=e.end}}static*fromCDNSeq(n,r){let i=!!r?.preserveComments,a=0,o=!0;for(;;){let{offset:s,hadSeparator:c,commaOffset:l}=g(n,a,r,i?o?`all`:`after-newline`:`none`);if(o&&l>=0){let e=`leading comma in CDN sequence`;if(r?.strict!==!1)throw SyntaxError(e);m(e,l,r)}if(s>=n.length||i&&h(n,s)&&g(n,s,r).offset>=n.length)break;if(!o&&!c){let e=`CDN sequence items must be separated by whitespace, comma, or comment`;if(r?.strict!==!1)throw SyntaxError(e);m(e,s,r)}a=s;let u;try{u=t.p(n,{...r,offset:a,allowTrailing:!0,_skipRS:!0})}catch(t){if(r?.strict!==!1)throw t;m(t instanceof Error?t.message:String(t),a,r,!0,t instanceof e.o?t:void 0);break}yield u,a=u.end,o=!1}}static fromJS(e,n){return t.r(e,n)}static fromHexDump(e,n){let r=[],i=d(e).trim().split(/\s+/).filter(Boolean);for(let e of i)if(/^[0-9A-Fa-f]{2}$/.test(e))r.push(parseInt(e,16));else if(/^[0-9A-Fa-f]+$/.test(e)&&e.length%2==0)for(let t=0;t<e.length;t+=2)r.push(parseInt(e.slice(t,t+2),16));else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);return t.u(new Uint8Array(r),n)}static decode(e,t){return n.fromCBOR(e,t).toJS(t)}static*decodeSeq(e,t){for(let r of n.fromCBORSeq(e,t))yield r.toJS(t)}static*parseSeq(e,t){for(let r of n.fromCDNSeq(e,t))yield r.toJS(t)}static encode(e,t){return n.fromJS(e,t).toCBOR(t)}static compile(e,t){let r=[...n.fromCDNSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static decompile(e,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toCDN(t)).join(`
5
2
  `)}static toHex(e,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toHexDump(t)).join(`
6
- `)}static fromHex(e,t){let r=[...n.fromHexDumpSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static cborToCdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cborToCborEdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static cborEdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static parse(e,t){return typeof t==`function`?n.fromCDN(e).toJS({reviver:t}):n.fromCDN(e,t).toJS(t)}static stringify(e,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=D(r);if(i){let n=t.n(e,i);return n===void 0||n===t.T?void 0:t.r(n).toCDN(a===void 0?void 0:{indent:a})}return t.r(e).toCDN(a===void 0?void 0:{indent:a})}let i=n;if(i?.replacer){let n=t.n(e,i.replacer,i.extensions,i.undefinedOmits);if(n===void 0||n===t.T)return;let{replacer:r,...a}=i;return t.r(n,Object.keys(a).length>0?a:void 0).toCDN(i)}return t.r(e,i).toCDN(i)}static format(e,t){return n.fromCDN(e,t).toCDN(t)}};function x(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=S(e,n+2),t+=` `;continue}if(r===`—`){n=S(e,n+1),t+=` `;continue}if(r===`#`){n=S(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=S(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+=C(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+=C(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function S(e,t){let n=e.indexOf(`
7
- `,t);return n<0?e.length:n}function C(e){return e.replace(/[^\r\n]/g,` `)}function w(e,t,n,r,i){let a=i?.offset??t,o={message:e,offset:a};r&&(o.fatal=!0),i?.offset!==void 0&&(o.line=i.line,o.column=i.column,o.endOffset=i.endOffset),n?.onWarning?n.onWarning(o):n?.silent||console.warn(`CDN sequence warning at offset ${a}: ${e}`)}function T(e,t){let n=e[t];return n===`#`||n===`/`}function E(e,t,n,r=`none`){let i=t,a=!1,o=!1,s=!1,c=-1,l=()=>r===`all`||r===`after-newline`&&s;for(;i<e.length;){let t=e[i];if(t===` `||t===` `||t===`\r`||t===``){a=!0,i++;continue}if(t===`
3
+ `)}static fromHex(e,t){let r=[...n.fromHexDumpSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static cborToCdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cborToCborEdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static cborEdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static parse(e,t){return typeof t==`function`?n.fromCDN(e).toJS({reviver:t}):n.fromCDN(e,t).toJS(t)}static stringify(e,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=_(r);if(i){let n=t.n(e,i);return n===void 0||n===t.k?void 0:t.r(n).toCDN(a===void 0?void 0:{indent:a})}return t.r(e).toCDN(a===void 0?void 0:{indent:a})}let i=n;if(i?.replacer){let n=t.n(e,i.replacer,i.extensions,i.undefinedOmits);if(n===void 0||n===t.k)return;let{replacer:r,...a}=i;return t.r(n,Object.keys(a).length>0?a:void 0).toCDN(i)}return t.r(e,i).toCDN(i)}static format(e,t){return n.fromCDN(e,t).toCDN(t)}};function d(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=f(e,n+2),t+=` `;continue}if(r===`—`){n=f(e,n+1),t+=` `;continue}if(r===`#`){n=f(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=f(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+=p(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+=p(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function f(e,t){let n=e.indexOf(`
4
+ `,t);return n<0?e.length:n}function p(e){return e.replace(/[^\r\n]/g,` `)}function m(e,t,n,r,i){let a=i?.offset??t,o={message:e,offset:a};r&&(o.fatal=!0),i?.offset!==void 0&&(o.line=i.line,o.column=i.column,o.endOffset=i.endOffset),n?.onWarning?n.onWarning(o):n?.silent||console.warn(`CDN sequence warning at offset ${a}: ${e}`)}function h(e,t){let n=e[t];return n===`#`||n===`/`}function g(e,t,n,r=`none`){let i=t,a=!1,o=!1,s=!1,c=-1,l=()=>r===`all`||r===`after-newline`&&s;for(;i<e.length;){let t=e[i];if(t===` `||t===` `||t===`\r`||t===``){a=!0,i++;continue}if(t===`
8
5
  `){a=!0,s=!0,i++;continue}if(t===`#`){if(a=!0,l())break;let t=e.indexOf(`
9
6
  `,i+1);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`/`){if(a=!0,l())break;let t=e.indexOf(`
10
- `,i+2);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`*`){if(a=!0,l())break;let t=e.indexOf(`*/`,i+2);if(t<0){let t=`unterminated /* comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);w(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
11
- `)&&(s=!0),i=t+2;continue}if(t===`/`&&e[i+1]!==`/`){if(a=!0,l())break;let t=e.indexOf(`/`,i+1);if(t<0){let t=`unterminated / comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);w(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
12
- `)&&(s=!0),i=t+1;continue}if(t===`,`&&!o){a=!0,o=!0,c=i,i++;continue}break}return{offset:i,hadSeparator:a,commaOffset:c}}function D(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=b,exports.default=b,exports.CBOR_OMIT=t.T,exports.CBOR_TAG=t.E,exports.CdnSyntaxError=e.o,exports.MapEntries=t.t,exports.Null=t.D,exports.Simple=t.w,exports.Tag=t.O,exports.Undefined=t.k,exports.b32=s,exports.dt_as_Date=t.a,exports.float=_,exports.h32=c,exports.same=y;
7
+ `,i+2);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`*`){if(a=!0,l())break;let t=e.indexOf(`*/`,i+2);if(t<0){let t=`unterminated /* comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);m(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
8
+ `)&&(s=!0),i=t+2;continue}if(t===`/`&&e[i+1]!==`/`){if(a=!0,l())break;let t=e.indexOf(`/`,i+1);if(t<0){let t=`unterminated / comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);m(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
9
+ `)&&(s=!0),i=t+1;continue}if(t===`,`&&!o){a=!0,o=!0,c=i,i++;continue}break}return{offset:i,hadSeparator:a,commaOffset:c}}function _(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=u,exports.default=u,exports.CBOR_OMIT=t.k,exports.CBOR_TAG=t.A,exports.CdnSyntaxError=e.o,exports.MapEntries=t.t,exports.Null=t.j,exports.Simple=t.O,exports.Tag=t.M,exports.Undefined=t.N,exports.b1=t.c,exports.b32=o,exports.dt_as_Date=t.d,exports.float=t.i,exports.h32=s,exports.ilbs=t.o,exports.ilts=t.s,exports.same=l,exports.t1=t.l;
13
10
  //# sourceMappingURL=index.cjs.map