@cbortech/cbor 0.25.11 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +110 -21
- package/README.md +109 -22
- package/assets/cbor-cdn-js.png +0 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cdn/index.cjs +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/tokenizer.d.ts +8 -5
- package/dist/extensions/builtins.d.ts +24 -1
- package/dist/extensions/concat.d.ts +5 -0
- package/dist/extensions/ilstrings.d.ts +5 -0
- package/dist/index.cjs +6 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +139 -300
- package/dist/index.js.map +1 -1
- package/dist/js/fromJS.d.ts +1 -1
- package/dist/mapEntries-Bys9cXgV.cjs +14 -0
- package/dist/mapEntries-Bys9cXgV.cjs.map +1 -0
- package/dist/{mapEntries-CYvdsAfP.js → mapEntries-ClxYqDPp.js} +583 -267
- package/dist/mapEntries-ClxYqDPp.js.map +1 -0
- package/dist/{tokenizer-DkLlZ1gc.js → tokenizer-CeuixxXi.js} +20 -19
- package/dist/tokenizer-CeuixxXi.js.map +1 -0
- package/dist/{tokenizer-CVcIyZZa.cjs → tokenizer-EciPlN0n.cjs} +3 -3
- package/dist/tokenizer-EciPlN0n.cjs.map +1 -0
- package/dist/types.d.ts +55 -0
- package/package.json +3 -2
- package/dist/mapEntries-CYvdsAfP.js.map +0 -1
- package/dist/mapEntries-vOYb5Q1s.cjs +0 -11
- package/dist/mapEntries-vOYb5Q1s.cjs.map +0 -1
- package/dist/tokenizer-CVcIyZZa.cjs.map +0 -1
- package/dist/tokenizer-DkLlZ1gc.js.map +0 -1
package/README.ja.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[CBOR](#準拠している仕様)、[CDN (CBOR-EDN)](#準拠している仕様)、JavaScript 値を相互変換するための TypeScript ライブラリです。
|
|
4
4
|
|
|
5
|
+

|
|
6
|
+
|
|
5
7
|
プレイグラウンドを **https://cbor.tech/cbor/** で公開しています。
|
|
6
8
|
|
|
7
9
|
このパッケージは `CBOR` ファサードに加えて、extension の実装に必要な CBOR AST ノードクラス用の entrypoint を公開します。
|
|
@@ -13,6 +15,13 @@
|
|
|
13
15
|
npm install @cbortech/cbor
|
|
14
16
|
```
|
|
15
17
|
|
|
18
|
+
コマンドラインでの変換や確認には、CLI パッケージ
|
|
19
|
+
[@cbortech/cbor-cli](https://www.npmjs.com/package/@cbortech/cbor-cli) も利用できます。
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @cbortech/cbor-cli
|
|
23
|
+
```
|
|
24
|
+
|
|
16
25
|
## インポート
|
|
17
26
|
|
|
18
27
|
```ts
|
|
@@ -255,6 +264,9 @@ console.log(text);
|
|
|
255
264
|
|
|
256
265
|
### `+` による文字列連結を保持する
|
|
257
266
|
|
|
267
|
+
注意: `+` による文字列連結構文は draft-26 で削除されました。この節は legacy
|
|
268
|
+
syntax を扱う場合のためのものです。
|
|
269
|
+
|
|
258
270
|
デフォルトでは、`CBOR.format()` は `+` による文字列連結を 1 つのリテラルに
|
|
259
271
|
結合します。`preserveConcatenation` を指定すると、テキスト文字列・バイト文字列とも
|
|
260
272
|
元の連結の区切りを保持します。`preserveByteString` を併用すると、バイト文字列の
|
|
@@ -432,6 +444,63 @@ console.log(text);
|
|
|
432
444
|
// DT'2026-05-06T00:00:00Z'
|
|
433
445
|
```
|
|
434
446
|
|
|
447
|
+
## 文字列連結と不定長文字列
|
|
448
|
+
|
|
449
|
+
draft-ietf-cbor-edn-literals-26(§3.4 / §3.5)の application extension
|
|
450
|
+
`t1` / `b1` / `ilbs` / `ilts` は、デフォルトで有効です。
|
|
451
|
+
|
|
452
|
+
`t1<<...>>` と `b1<<...>>` は、(テキストまたはバイト)文字列の引数を左から
|
|
453
|
+
右へ結合し、1 つのテキスト文字列(`t1`)またはバイト文字列(`b1`)を
|
|
454
|
+
作ります。引数には省略記号(`...`)も使えます。
|
|
455
|
+
|
|
456
|
+
```ts
|
|
457
|
+
import { CBOR } from '@cbortech/cbor';
|
|
458
|
+
|
|
459
|
+
const text = CBOR.fromCDN('t1<<"Hello ", "world">>');
|
|
460
|
+
console.log(text.toCDN({ appStrings: false }));
|
|
461
|
+
// "Hello world"
|
|
462
|
+
|
|
463
|
+
const bytes = CBOR.fromCDN("b1<<'Hello ', h'776f726c64'>>");
|
|
464
|
+
console.log(bytes.toCDN({ appStrings: false }));
|
|
465
|
+
// 'Hello world'
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
`ilbs<<...>>` / `ilts<<...>>` は、引数 1 つにつき 1 チャンクの不定長
|
|
469
|
+
バイト列/テキスト文字列を作ります。各引数のエンコーディング指示子は
|
|
470
|
+
チャンクに引き継がれます。draft-26 で非推奨となった `(_ chunk, ...)`
|
|
471
|
+
streamstring 構文の置き換えですが、本ライブラリは従来構文の入力も
|
|
472
|
+
引き続き受理します。
|
|
473
|
+
|
|
474
|
+
```ts
|
|
475
|
+
import { CBOR } from '@cbortech/cbor';
|
|
476
|
+
|
|
477
|
+
const v = CBOR.fromCDN("ilbs<<'Hello ', 'world'>>");
|
|
478
|
+
console.log(v.toCDN({ appStrings: false }));
|
|
479
|
+
// (_ 'Hello ', 'world')
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
> [!NOTE]
|
|
483
|
+
> `t1` / `b1` という識別子は draft-26 で暫定(provisional)と明記されて
|
|
484
|
+
> おり、CBOR ワーキンググループにより改名される可能性があります。
|
|
485
|
+
|
|
486
|
+
## float
|
|
487
|
+
|
|
488
|
+
16 進数のビットパターンを IEEE 754 浮動小数点値として解釈します
|
|
489
|
+
(draft-ietf-cbor-edn-literals-26 §3.7)。デフォルトで有効です。
|
|
490
|
+
|
|
491
|
+
```ts
|
|
492
|
+
import { CBOR } from '@cbortech/cbor';
|
|
493
|
+
|
|
494
|
+
const v = CBOR.fromCDN("float'7e00'");
|
|
495
|
+
console.log(v.toCDN({ appStrings: false }));
|
|
496
|
+
// NaN
|
|
497
|
+
|
|
498
|
+
// バイト列から解釈する場合
|
|
499
|
+
const v2 = CBOR.fromCDN("float<<h'3f800000'>>");
|
|
500
|
+
console.log(v2.toCDN({ appStrings: false }));
|
|
501
|
+
// 1.0_2
|
|
502
|
+
```
|
|
503
|
+
|
|
435
504
|
## オプション extension
|
|
436
505
|
|
|
437
506
|
このパッケージには、デフォルト有効ではないものの本体に同梱されている
|
|
@@ -458,25 +527,6 @@ console.log(v2.toCDN({ appStrings: false }));
|
|
|
458
527
|
// h'003200'
|
|
459
528
|
```
|
|
460
529
|
|
|
461
|
-
### float
|
|
462
|
-
|
|
463
|
-
16 進数のビットパターンを IEEE 754 浮動小数点値として解釈します。
|
|
464
|
-
[draft-bormann-cbor-edn-app-ext](https://datatracker.ietf.org/doc/draft-bormann-cbor-edn-app-ext/)
|
|
465
|
-
に記載があり、[cbor-test-vectors](https://github.com/cbor-wg/cbor-test-vectors) でも使われています。
|
|
466
|
-
|
|
467
|
-
```ts
|
|
468
|
-
import { CBOR, float } from '@cbortech/cbor';
|
|
469
|
-
|
|
470
|
-
const v = CBOR.fromCDN("float'7e00'", { extensions: [float] });
|
|
471
|
-
console.log(v.toCDN({ appStrings: false }));
|
|
472
|
-
// NaN
|
|
473
|
-
|
|
474
|
-
// バイト列から解釈する場合
|
|
475
|
-
const v2 = CBOR.fromCDN("float<<h'3f800000'>>", { extensions: [float] });
|
|
476
|
-
console.log(v2.toCDN({ appStrings: false }));
|
|
477
|
-
// 1.0_2
|
|
478
|
-
```
|
|
479
|
-
|
|
480
530
|
### same
|
|
481
531
|
|
|
482
532
|
`same<<expr, expr, ...>>` は、シーケンス内のすべての要素が同一の CBOR
|
|
@@ -547,6 +597,31 @@ const id = cbor.parse("uuid'550e8400-e29b-41d4-a716-446655440000'");
|
|
|
547
597
|
// Uint8Array(16) [85, 14, 132, 0, 226, 155, 65, 212, 167, 22, 68, 102, 85, 68, 0, 0]
|
|
548
598
|
```
|
|
549
599
|
|
|
600
|
+
### set / map
|
|
601
|
+
|
|
602
|
+
`SET` と `MAP` は、タグ付きの Set / Map 値を扱うための、このライブラリ独自の
|
|
603
|
+
application extension です。
|
|
604
|
+
[@cbortech/set-map-extensions](https://www.npmjs.com/package/@cbortech/set-map-extensions)
|
|
605
|
+
としてまとめて別パッケージで提供しています。`SET<<[...]>>` は配列に CBOR tag
|
|
606
|
+
258 を付けた値、`MAP<<{...}>>` は map に CBOR tag 259 を付けた値を生成します。
|
|
607
|
+
|
|
608
|
+
```bash
|
|
609
|
+
npm install @cbortech/set-map-extensions
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
```ts
|
|
613
|
+
import { CBOR } from '@cbortech/cbor';
|
|
614
|
+
import { set, map } from '@cbortech/set-map-extensions';
|
|
615
|
+
|
|
616
|
+
const cbor = new CBOR({ extensions: [set, map] });
|
|
617
|
+
|
|
618
|
+
const roles = cbor.parse('SET<<["admin", "editor"]>>');
|
|
619
|
+
// Set { 'admin', 'editor' }
|
|
620
|
+
|
|
621
|
+
const scores = cbor.parse('MAP<<{"alice": 98, "bob": 72}>>');
|
|
622
|
+
// Map { 'alice' => 98, 'bob' => 72 }
|
|
623
|
+
```
|
|
624
|
+
|
|
550
625
|
## タグ
|
|
551
626
|
|
|
552
627
|
JavaScript 上で CBOR のタグ付き値を扱うには `CBOR.Tag` を使います。
|
|
@@ -729,6 +804,22 @@ AST ノードクラスは `@cbortech/cbor/ast` にあります。
|
|
|
729
804
|
- [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
|
|
730
805
|
- [Concise Diagnostic Notation (CDN), draft-ietf-cbor-edn-literals-25](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/)
|
|
731
806
|
|
|
807
|
+
draft -25 をベースに、
|
|
808
|
+
[draft -26](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/26/)
|
|
809
|
+
の一部仕様も先行して取り込んでいます。
|
|
810
|
+
|
|
811
|
+
- 文字列連結 extension `t1` / `b1`(§3.4)
|
|
812
|
+
- 不定長文字列 extension `ilbs` / `ilts`(§3.5)
|
|
813
|
+
- `float` extension のデフォルト有効化(§3.7)
|
|
814
|
+
- draft-26 の raw string 規則(§2.5.4): 終端デリミタは開始デリミタと
|
|
815
|
+
同数のバッククォートに限られ、スペース除去規則がすべてのデリミタ長に
|
|
816
|
+
適用されます
|
|
817
|
+
|
|
818
|
+
draft -26 で削除された `+` による文字列連結構文と、非推奨となった
|
|
819
|
+
`(_ ...)` streamstring 構文は、引き続き受理します。CDN は Internet-Draft
|
|
820
|
+
として策定中の仕様であり、今後も変更される可能性がある点に注意して
|
|
821
|
+
ください(たとえば extension 名 `t1` / `b1` は暫定とされています)。
|
|
822
|
+
|
|
732
823
|
CDN は、CBOR データを人間が読み書きしやすいテキストとして表現するための記法です。
|
|
733
824
|
サンプル、テストベクター、デバッグ、fixture、設定ファイルに近い用途など、CBOR のバイト列をそのまま扱うと読みにくい場面で役立ちます。
|
|
734
825
|
|
|
@@ -739,8 +830,6 @@ CDN は、CBOR データを人間が読み書きしやすいテキストとし
|
|
|
739
830
|
CDN は JSON / JSONC の上位互換なので、通常の JSON データやコメント付きの JSON 風データも、
|
|
740
831
|
特別な変換なしに CDN としてパース・整形できます。
|
|
741
832
|
|
|
742
|
-
CDN はまだ広く普及した RFC ではなく、Internet-Draft として策定中の仕様です。
|
|
743
|
-
|
|
744
833
|
## ライセンス
|
|
745
834
|
|
|
746
835
|
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
|
+

|
|
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
|
|
@@ -15,6 +17,13 @@ are not part of the documented public API.
|
|
|
15
17
|
npm install @cbortech/cbor
|
|
16
18
|
```
|
|
17
19
|
|
|
20
|
+
For command-line conversion and inspection, a companion CLI package is
|
|
21
|
+
available as [@cbortech/cbor-cli](https://www.npmjs.com/package/@cbortech/cbor-cli).
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g @cbortech/cbor-cli
|
|
25
|
+
```
|
|
26
|
+
|
|
18
27
|
## Import
|
|
19
28
|
|
|
20
29
|
```ts
|
|
@@ -258,6 +267,9 @@ console.log(text);
|
|
|
258
267
|
|
|
259
268
|
### Preserve `+` string concatenation
|
|
260
269
|
|
|
270
|
+
Note: `+` string concatenation was removed in draft-26. This section is for
|
|
271
|
+
handling legacy syntax.
|
|
272
|
+
|
|
261
273
|
By default, `CBOR.format()` joins `+` string concatenation into a single
|
|
262
274
|
literal. `preserveConcatenation` keeps the original part boundaries for both
|
|
263
275
|
text strings and byte strings; add `preserveByteString` to also keep the
|
|
@@ -438,6 +450,62 @@ console.log(text);
|
|
|
438
450
|
// DT'2026-05-06T00:00:00Z'
|
|
439
451
|
```
|
|
440
452
|
|
|
453
|
+
## String Concatenation and Indefinite-Length Strings
|
|
454
|
+
|
|
455
|
+
The `t1` / `b1` / `ilbs` / `ilts` application extensions from
|
|
456
|
+
draft-ietf-cbor-edn-literals-26 (§3.4 / §3.5) are enabled by default.
|
|
457
|
+
|
|
458
|
+
`t1<<...>>` and `b1<<...>>` join (text or byte) string arguments from left to
|
|
459
|
+
right into a single text string (`t1`) or byte string (`b1`). Arguments may
|
|
460
|
+
also be ellipses (`...`) to elide parts of a string.
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
import { CBOR } from '@cbortech/cbor';
|
|
464
|
+
|
|
465
|
+
const text = CBOR.fromCDN('t1<<"Hello ", "world">>');
|
|
466
|
+
console.log(text.toCDN({ appStrings: false }));
|
|
467
|
+
// "Hello world"
|
|
468
|
+
|
|
469
|
+
const bytes = CBOR.fromCDN("b1<<'Hello ', h'776f726c64'>>");
|
|
470
|
+
console.log(bytes.toCDN({ appStrings: false }));
|
|
471
|
+
// 'Hello world'
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
`ilbs<<...>>` / `ilts<<...>>` build an indefinite-length byte / text string
|
|
475
|
+
with one chunk per argument, honoring encoding indicators on each argument.
|
|
476
|
+
They replace the deprecated `(_ chunk, ...)` streamstring syntax for new CDN
|
|
477
|
+
documents; this library keeps accepting the legacy syntax on input.
|
|
478
|
+
|
|
479
|
+
```ts
|
|
480
|
+
import { CBOR } from '@cbortech/cbor';
|
|
481
|
+
|
|
482
|
+
const v = CBOR.fromCDN("ilbs<<'Hello ', 'world'>>");
|
|
483
|
+
console.log(v.toCDN({ appStrings: false }));
|
|
484
|
+
// (_ 'Hello ', 'world')
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
> [!NOTE]
|
|
488
|
+
> The identifiers `t1` and `b1` are explicitly provisional in draft-26 and
|
|
489
|
+
> may be renamed by the CBOR working group.
|
|
490
|
+
|
|
491
|
+
## float
|
|
492
|
+
|
|
493
|
+
Interprets a hex bit-pattern as an IEEE 754 floating-point value
|
|
494
|
+
(draft-ietf-cbor-edn-literals-26 §3.7). Enabled by default.
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
import { CBOR } from '@cbortech/cbor';
|
|
498
|
+
|
|
499
|
+
const v = CBOR.fromCDN("float'7e00'");
|
|
500
|
+
console.log(v.toCDN({ appStrings: false }));
|
|
501
|
+
// NaN
|
|
502
|
+
|
|
503
|
+
// Interpret bytes as float bits
|
|
504
|
+
const v2 = CBOR.fromCDN("float<<h'3f800000'>>");
|
|
505
|
+
console.log(v2.toCDN({ appStrings: false }));
|
|
506
|
+
// 1.0_2
|
|
507
|
+
```
|
|
508
|
+
|
|
441
509
|
## Optional Extensions
|
|
442
510
|
|
|
443
511
|
This package includes several bundled extensions that are not enabled by
|
|
@@ -465,26 +533,6 @@ console.log(v2.toCDN({ appStrings: false }));
|
|
|
465
533
|
// h'003200'
|
|
466
534
|
```
|
|
467
535
|
|
|
468
|
-
### float
|
|
469
|
-
|
|
470
|
-
Interprets a hex bit-pattern as an IEEE 754 floating-point value. This
|
|
471
|
-
extension is described in
|
|
472
|
-
[draft-bormann-cbor-edn-app-ext](https://datatracker.ietf.org/doc/draft-bormann-cbor-edn-app-ext/)
|
|
473
|
-
and also used in [cbor-test-vectors](https://github.com/cbor-wg/cbor-test-vectors).
|
|
474
|
-
|
|
475
|
-
```ts
|
|
476
|
-
import { CBOR, float } from '@cbortech/cbor';
|
|
477
|
-
|
|
478
|
-
const v = CBOR.fromCDN("float'7e00'", { extensions: [float] });
|
|
479
|
-
console.log(v.toCDN({ appStrings: false }));
|
|
480
|
-
// NaN
|
|
481
|
-
|
|
482
|
-
// Interpret bytes as float bits
|
|
483
|
-
const v2 = CBOR.fromCDN("float<<h'3f800000'>>", { extensions: [float] });
|
|
484
|
-
console.log(v2.toCDN({ appStrings: false }));
|
|
485
|
-
// 1.0_2
|
|
486
|
-
```
|
|
487
|
-
|
|
488
536
|
### same
|
|
489
537
|
|
|
490
538
|
`same<<expr, expr, ...>>` verifies that every item in the sequence encodes to
|
|
@@ -554,6 +602,31 @@ const id = cbor.parse("uuid'550e8400-e29b-41d4-a716-446655440000'");
|
|
|
554
602
|
// Uint8Array(16) [85, 14, 132, 0, 226, 155, 65, 212, 167, 22, 68, 102, 85, 68, 0, 0]
|
|
555
603
|
```
|
|
556
604
|
|
|
605
|
+
### set / map
|
|
606
|
+
|
|
607
|
+
`SET` and `MAP` are library-specific application extensions for tagged Set and
|
|
608
|
+
Map values. They are provided together as
|
|
609
|
+
[@cbortech/set-map-extensions](https://www.npmjs.com/package/@cbortech/set-map-extensions).
|
|
610
|
+
`SET<<[...]>>` produces CBOR tag 258 over an array, and `MAP<<{...}>>` produces
|
|
611
|
+
CBOR tag 259 over a map.
|
|
612
|
+
|
|
613
|
+
```bash
|
|
614
|
+
npm install @cbortech/set-map-extensions
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
```ts
|
|
618
|
+
import { CBOR } from '@cbortech/cbor';
|
|
619
|
+
import { set, map } from '@cbortech/set-map-extensions';
|
|
620
|
+
|
|
621
|
+
const cbor = new CBOR({ extensions: [set, map] });
|
|
622
|
+
|
|
623
|
+
const roles = cbor.parse('SET<<["admin", "editor"]>>');
|
|
624
|
+
// Set { 'admin', 'editor' }
|
|
625
|
+
|
|
626
|
+
const scores = cbor.parse('MAP<<{"alice": 98, "bob": 72}>>');
|
|
627
|
+
// Map { 'alice' => 98, 'bob' => 72 }
|
|
628
|
+
```
|
|
629
|
+
|
|
557
630
|
## Tags
|
|
558
631
|
|
|
559
632
|
Use `CBOR.Tag` for CBOR tagged values in JavaScript.
|
|
@@ -736,6 +809,22 @@ This library targets:
|
|
|
736
809
|
- [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
|
|
737
810
|
- [Concise Diagnostic Notation (CDN), draft-ietf-cbor-edn-literals-25](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/)
|
|
738
811
|
|
|
812
|
+
On top of draft -25, this library already incorporates parts of
|
|
813
|
+
[draft -26](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/26/):
|
|
814
|
+
|
|
815
|
+
- the `t1` / `b1` string-concatenation extensions (§3.4)
|
|
816
|
+
- the `ilbs` / `ilts` indefinite-length string extensions (§3.5)
|
|
817
|
+
- the `float` extension as a default extension (§3.7)
|
|
818
|
+
- the draft-26 raw-string delimiter and trimming rules (§2.5.4): the closing
|
|
819
|
+
delimiter must have exactly as many backquotes as the opening one, and the
|
|
820
|
+
space-trimming rule applies to all delimiter lengths
|
|
821
|
+
|
|
822
|
+
The legacy `+` string-concatenation syntax (removed in draft -26) and the
|
|
823
|
+
`(_ ...)` streamstring syntax (deprecated in draft -26) are still accepted.
|
|
824
|
+
Note that the CDN specification is still an Internet-Draft and may continue
|
|
825
|
+
to change (for example, the extension names `t1` and `b1` are explicitly
|
|
826
|
+
provisional).
|
|
827
|
+
|
|
739
828
|
CDN is a human-readable text notation for CBOR data. It is useful for
|
|
740
829
|
examples, test vectors, debugging, fixtures, and configuration-like files where
|
|
741
830
|
raw CBOR bytes would be hard to read.
|
|
@@ -749,8 +838,6 @@ CDN is a superset of JSON and JSONC, so ordinary JSON data and
|
|
|
749
838
|
commented JSON-style data can be parsed and formatted as CDN without
|
|
750
839
|
special handling.
|
|
751
840
|
|
|
752
|
-
CDN is still an Internet-Draft rather than a widely deployed RFC.
|
|
753
|
-
|
|
754
841
|
## License
|
|
755
842
|
|
|
756
843
|
Apache-2.0
|
|
Binary file
|
package/dist/ast/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-Bys9cXgV.cjs");exports.CborArray=e.C,exports.CborBigNint=e.v,exports.CborBigUint=e.y,exports.CborByteString=e.E,exports.CborEmbeddedCBOR=e.b,exports.CborFloat=e.O,exports.CborIndefiniteByteString=e.T,exports.CborIndefiniteTextString=e.w,exports.CborItem=e.j,exports.CborMap=e.S,exports.CborNint=e.k,exports.CborSimple=e.x,exports.CborTag=e.D,exports.CborTextString=e.g,exports.CborUint=e.A;
|
package/dist/ast/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { A as e, C as t, D as n, E as r, O as i, S as a, T as o, b as s, g as c, j as l, k as u, v as d, w as f, x as p, y as m } from "../mapEntries-ClxYqDPp.js";
|
|
2
|
+
export { t as CborArray, d as CborBigNint, m as CborBigUint, r as CborByteString, s as CborEmbeddedCBOR, i as CborFloat, o as CborIndefiniteByteString, f as CborIndefiniteTextString, l as CborItem, a as CborMap, u as CborNint, p as CborSimple, n as CborTag, c as CborTextString, e as CborUint };
|
package/dist/cdn/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../tokenizer-
|
|
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
package/dist/cdn/tokenizer.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
149
|
-
*
|
|
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
|
/**
|
|
@@ -1,2 +1,25 @@
|
|
|
1
1
|
import { CborExtension } from './types';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Core RFC 8949 data-model extensions (bignum tags 2/3, embedded-CBOR tag
|
|
4
|
+
* 24). These implement base CBOR representation rather than an
|
|
5
|
+
* application-oriented extension, so they are always active and are not
|
|
6
|
+
* affected by the `builtinExtensions` option.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CORE_EXTENSIONS: readonly CborExtension[];
|
|
9
|
+
/**
|
|
10
|
+
* Default application-oriented extensions bundled with the library.
|
|
11
|
+
* Overridable per call via `builtinExtensions` (an array to use instead, or
|
|
12
|
+
* `false` to disable all of them).
|
|
13
|
+
*
|
|
14
|
+
* `dt`, `ip`, `t1`, and `b1` are mandatory-to-implement per §2.1 of
|
|
15
|
+
* draft-ietf-cbor-edn-literals-26; `cri`, `ilbs`, `ilts`, and `float` are
|
|
16
|
+
* bundled but not mandatory.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BUILTIN_EXTENSIONS: readonly CborExtension[];
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the `builtinExtensions` option to the full list of built-in
|
|
21
|
+
* extensions that should be active: `CORE_EXTENSIONS` plus either the
|
|
22
|
+
* default `BUILTIN_EXTENSIONS` set (`undefined`), a caller-supplied
|
|
23
|
+
* replacement array, or nothing beyond core (`false`).
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveBuiltinExtensions(builtinExtensions?: CborExtension[] | false): readonly CborExtension[];
|
|
@@ -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-
|
|
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-Bys9cXgV.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.E(a(t.o(r),n,i),{ednEncoding:`base32`})}},s={appStringPrefixes:[`h32`],parseAppString(e,n,i){return new t.E(a(t.o(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.N;static TAG=t.P;static Tag=t.I;static Simple=t.M;static MapEntries=t.t;static dt_as_Date=t.h;#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.d(e,n)}static fromCDN(e,n){return t._(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.d(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._(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.d(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=
|
|
7
|
-
`,t);return n<0?e.length:n}function
|
|
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.N?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,i.builtinExtensions);if(n===void 0||n===t.N)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);
|
|
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);
|
|
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
|
|
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.BUILTIN_EXTENSIONS=t.i,exports.CBOR=u,exports.default=u,exports.CBOR_OMIT=t.N,exports.CBOR_TAG=t.P,exports.CdnSyntaxError=e.o,exports.MapEntries=t.t,exports.Null=t.F,exports.Simple=t.M,exports.Tag=t.I,exports.Undefined=t.L,exports.b1=t.l,exports.b32=o,exports.cri=t.f,exports.dt=t.m,exports.dt_as_Date=t.h,exports.float=t.a,exports.h32=s,exports.ilbs=t.s,exports.ilts=t.c,exports.ip=t.p,exports.same=l,exports.t1=t.u;
|
|
13
10
|
//# sourceMappingURL=index.cjs.map
|