@cbortech/cbor 0.25.7 → 0.25.8
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 +83 -5
- package/README.md +83 -5
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cbor.d.ts +48 -15
- package/dist/cdn/index.cjs +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/tokenizer.d.ts +3 -0
- package/dist/index.cjs +8 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +176 -16
- package/dist/index.js.map +1 -1
- package/dist/{mapEntries-C5S6uTIO.cjs → mapEntries-BQYXoTz7.cjs} +4 -4
- package/dist/mapEntries-BQYXoTz7.cjs.map +1 -0
- package/dist/{mapEntries-bvRWFfqX.js → mapEntries-Cc4If3gy.js} +44 -18
- package/dist/mapEntries-Cc4If3gy.js.map +1 -0
- package/dist/{tokenizer-M2pf9ud0.cjs → tokenizer-Cg5EIl83.cjs} +3 -3
- package/dist/tokenizer-Cg5EIl83.cjs.map +1 -0
- package/dist/{tokenizer-BuRSmdyM.js → tokenizer-IDqJN0Dw.js} +4 -3
- package/dist/tokenizer-IDqJN0Dw.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/package.json +3 -3
- package/dist/mapEntries-C5S6uTIO.cjs.map +0 -1
- package/dist/mapEntries-bvRWFfqX.js.map +0 -1
- package/dist/tokenizer-BuRSmdyM.js.map +0 -1
- package/dist/tokenizer-M2pf9ud0.cjs.map +0 -1
package/README.ja.md
CHANGED
|
@@ -54,26 +54,88 @@ console.log(value);
|
|
|
54
54
|
// { hello: 'world', n: 42 }
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
### CBOR
|
|
57
|
+
### CBOR Sequence から JavaScript へ
|
|
58
|
+
|
|
59
|
+
`decodeSeq` は連結された CBOR item を CBOR Sequence として読み取り、各 item を JavaScript 値として yield します。
|
|
58
60
|
|
|
59
61
|
```ts
|
|
60
62
|
import { CBOR } from '@cbortech/cbor';
|
|
61
63
|
|
|
62
|
-
const
|
|
64
|
+
const a = CBOR.encode({ id: 1 });
|
|
65
|
+
const b = CBOR.encode({ id: 2 });
|
|
66
|
+
const seq = new Uint8Array([...a, ...b]);
|
|
67
|
+
|
|
68
|
+
const values = [...CBOR.decodeSeq(seq)];
|
|
69
|
+
// [{ id: 1 }, { id: 2 }]
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### CBOR バイト列から CDN へ
|
|
63
73
|
|
|
74
|
+
`decompile` は CBOR バイト列を CDN テキスト文字列に変換します。CBOR Sequence には自動対応しており、複数 item が連結されている場合は改行区切りの CDN 出力になります。
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { CBOR } from '@cbortech/cbor';
|
|
78
|
+
|
|
79
|
+
// 単一 item
|
|
80
|
+
const text = CBOR.decompile(new Uint8Array([0x83, 0x01, 0x02, 0x03]));
|
|
64
81
|
console.log(text);
|
|
65
82
|
// [1,2,3]
|
|
83
|
+
|
|
84
|
+
// CBOR Sequence — item ごとに 1 行
|
|
85
|
+
const seq = new Uint8Array([...CBOR.encode(1), ...CBOR.encode('two')]);
|
|
86
|
+
console.log(CBOR.decompile(seq));
|
|
87
|
+
// 1
|
|
88
|
+
// "two"
|
|
66
89
|
```
|
|
67
90
|
|
|
68
91
|
### CDN から CBOR バイト列へ
|
|
69
92
|
|
|
93
|
+
`compile` は CDN テキスト文字列を CBOR バイト列に変換します。CDN Sequence(複数 item)を入力すると、CBOR Sequence (RFC 8742) として連結されたバイト列を自動的に出力します。
|
|
94
|
+
|
|
70
95
|
```ts
|
|
71
96
|
import { CBOR } from '@cbortech/cbor';
|
|
72
97
|
|
|
73
|
-
|
|
74
|
-
|
|
98
|
+
// 単一 item
|
|
99
|
+
const bytes = CBOR.compile('[1, 2, 3]');
|
|
75
100
|
console.log(bytes);
|
|
76
101
|
// Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
102
|
+
|
|
103
|
+
// CDN Sequence — 出力は CBOR Sequence
|
|
104
|
+
const seq = CBOR.compile('{"id":1}\n{"id":2}');
|
|
105
|
+
console.log([...CBOR.decodeSeq(seq)]);
|
|
106
|
+
// [{ id: 1 }, { id: 2 }]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### CBOR バイト列から hex dump へ
|
|
110
|
+
|
|
111
|
+
`toHex` は CBOR バイト列をアノテーション付き hex dump テキストに変換します。CBOR Sequence には自動対応しており、各 item が改行区切りで出力されます。
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { CBOR } from '@cbortech/cbor';
|
|
115
|
+
|
|
116
|
+
const bytes = CBOR.encode([1, 2, 3]);
|
|
117
|
+
console.log(CBOR.toHex(bytes));
|
|
118
|
+
// 83 -- Array of length 3
|
|
119
|
+
// 01 -- 1
|
|
120
|
+
// 02 -- 2
|
|
121
|
+
// 03 -- 3
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### hex dump から CBOR バイト列へ
|
|
125
|
+
|
|
126
|
+
`fromHex` はアノテーション付き hex dump を CBOR バイト列に変換します。複数 item のダンプは CBOR Sequence (RFC 8742) として連結されたバイト列を出力します。
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { CBOR } from '@cbortech/cbor';
|
|
130
|
+
|
|
131
|
+
const bytes = CBOR.fromHex(`
|
|
132
|
+
83 -- Array of length 3
|
|
133
|
+
01 -- 1
|
|
134
|
+
02 -- 2
|
|
135
|
+
03 -- 3
|
|
136
|
+
`);
|
|
137
|
+
console.log([...CBOR.decodeSeq(bytes)]);
|
|
138
|
+
// [[1, 2, 3]]
|
|
77
139
|
```
|
|
78
140
|
|
|
79
141
|
### JavaScript から CDN へ
|
|
@@ -116,6 +178,21 @@ console.log(value);
|
|
|
116
178
|
// [1, Uint8Array(...), true, null]
|
|
117
179
|
```
|
|
118
180
|
|
|
181
|
+
### CDN Sequence から JavaScript へ
|
|
182
|
+
|
|
183
|
+
`parseSeq` は複数 item を含む CDN テキスト文字列(空白・カンマ・コメント区切り)をパースし、各 item を JavaScript 値として yield します。JSONL / NDJSON もそのまま扱えます。
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { CBOR } from '@cbortech/cbor';
|
|
187
|
+
|
|
188
|
+
const values = [...CBOR.parseSeq('1 "two" [3]')];
|
|
189
|
+
// [1, 'two', [3]]
|
|
190
|
+
|
|
191
|
+
const jsonl = '{"id":1}\n{"id":2}\n{"id":3}';
|
|
192
|
+
const rows = [...CBOR.parseSeq(jsonl)];
|
|
193
|
+
// [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
194
|
+
```
|
|
195
|
+
|
|
119
196
|
### CDN を正規化する
|
|
120
197
|
|
|
121
198
|
```ts
|
|
@@ -546,7 +623,8 @@ console.log(CBOR.stringify(entries));
|
|
|
546
623
|
|
|
547
624
|
## Hex Dump
|
|
548
625
|
|
|
549
|
-
CBOR
|
|
626
|
+
`CBOR.toHex()` / `CBOR.fromHex()` がショートカット入口です([クイック例](#cbor-バイト列から-hex-dump-へ) 参照)。
|
|
627
|
+
バイト範囲の取得や再エンコードなど AST レベルの操作が必要な場合は、`item.toHexDump()` / `CBOR.fromHexDump()` を直接使います。
|
|
550
628
|
|
|
551
629
|
```ts
|
|
552
630
|
import { CBOR } from '@cbortech/cbor';
|
package/README.md
CHANGED
|
@@ -56,26 +56,88 @@ console.log(value);
|
|
|
56
56
|
// { hello: 'world', n: 42 }
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
### CBOR
|
|
59
|
+
### CBOR Sequence to JavaScript values
|
|
60
|
+
|
|
61
|
+
`decodeSeq` reads concatenated CBOR items as a CBOR Sequence and yields each item as a JavaScript value.
|
|
60
62
|
|
|
61
63
|
```ts
|
|
62
64
|
import { CBOR } from '@cbortech/cbor';
|
|
63
65
|
|
|
64
|
-
const
|
|
66
|
+
const a = CBOR.encode({ id: 1 });
|
|
67
|
+
const b = CBOR.encode({ id: 2 });
|
|
68
|
+
const seq = new Uint8Array([...a, ...b]);
|
|
69
|
+
|
|
70
|
+
const values = [...CBOR.decodeSeq(seq)];
|
|
71
|
+
// [{ id: 1 }, { id: 2 }]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### CBOR bytes to CDN
|
|
65
75
|
|
|
76
|
+
`decompile` converts CBOR binary data to a CDN text string. It handles CBOR Sequences automatically: multiple concatenated items produce newline-separated CDN output.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { CBOR } from '@cbortech/cbor';
|
|
80
|
+
|
|
81
|
+
// Single item
|
|
82
|
+
const text = CBOR.decompile(new Uint8Array([0x83, 0x01, 0x02, 0x03]));
|
|
66
83
|
console.log(text);
|
|
67
84
|
// [1,2,3]
|
|
85
|
+
|
|
86
|
+
// CBOR Sequence — each item on its own line
|
|
87
|
+
const seq = new Uint8Array([...CBOR.encode(1), ...CBOR.encode('two')]);
|
|
88
|
+
console.log(CBOR.decompile(seq));
|
|
89
|
+
// 1
|
|
90
|
+
// "two"
|
|
68
91
|
```
|
|
69
92
|
|
|
70
93
|
### CDN to CBOR bytes
|
|
71
94
|
|
|
95
|
+
`compile` converts a CDN text string to CBOR binary data. Multi-item CDN Sequences automatically produce a CBOR Sequence (RFC 8742): concatenated items.
|
|
96
|
+
|
|
72
97
|
```ts
|
|
73
98
|
import { CBOR } from '@cbortech/cbor';
|
|
74
99
|
|
|
75
|
-
|
|
76
|
-
|
|
100
|
+
// Single item
|
|
101
|
+
const bytes = CBOR.compile('[1, 2, 3]');
|
|
77
102
|
console.log(bytes);
|
|
78
103
|
// Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
104
|
+
|
|
105
|
+
// CDN Sequence — output is a CBOR Sequence
|
|
106
|
+
const seq = CBOR.compile('{"id":1}\n{"id":2}');
|
|
107
|
+
console.log([...CBOR.decodeSeq(seq)]);
|
|
108
|
+
// [{ id: 1 }, { id: 2 }]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### CBOR bytes to hex dump
|
|
112
|
+
|
|
113
|
+
`toHex` converts CBOR binary data to an annotated hex dump string. CBOR Sequences are handled automatically: each item produces its own dump, separated by newlines.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { CBOR } from '@cbortech/cbor';
|
|
117
|
+
|
|
118
|
+
const bytes = CBOR.encode([1, 2, 3]);
|
|
119
|
+
console.log(CBOR.toHex(bytes));
|
|
120
|
+
// 83 -- Array of length 3
|
|
121
|
+
// 01 -- 1
|
|
122
|
+
// 02 -- 2
|
|
123
|
+
// 03 -- 3
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Hex dump to CBOR bytes
|
|
127
|
+
|
|
128
|
+
`fromHex` parses an annotated hex dump back to CBOR binary data. Multi-item dumps produce a CBOR Sequence (RFC 8742): concatenated items.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { CBOR } from '@cbortech/cbor';
|
|
132
|
+
|
|
133
|
+
const bytes = CBOR.fromHex(`
|
|
134
|
+
83 -- Array of length 3
|
|
135
|
+
01 -- 1
|
|
136
|
+
02 -- 2
|
|
137
|
+
03 -- 3
|
|
138
|
+
`);
|
|
139
|
+
console.log([...CBOR.decodeSeq(bytes)]);
|
|
140
|
+
// [[1, 2, 3]]
|
|
79
141
|
```
|
|
80
142
|
|
|
81
143
|
### JavaScript to CDN
|
|
@@ -118,6 +180,21 @@ console.log(value);
|
|
|
118
180
|
// [1, Uint8Array(...), true, null]
|
|
119
181
|
```
|
|
120
182
|
|
|
183
|
+
### CDN Sequence to JavaScript values
|
|
184
|
+
|
|
185
|
+
`parseSeq` parses multiple CDN items separated by whitespace, commas, or comments, and also accepts JSONL / NDJSON input.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { CBOR } from '@cbortech/cbor';
|
|
189
|
+
|
|
190
|
+
const values = [...CBOR.parseSeq('1 "two" [3]')];
|
|
191
|
+
// [1, 'two', [3]]
|
|
192
|
+
|
|
193
|
+
const jsonl = '{"id":1}\n{"id":2}\n{"id":3}';
|
|
194
|
+
const rows = [...CBOR.parseSeq(jsonl)];
|
|
195
|
+
// [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
196
|
+
```
|
|
197
|
+
|
|
121
198
|
### Normalize CDN
|
|
122
199
|
|
|
123
200
|
```ts
|
|
@@ -553,7 +630,8 @@ console.log(CBOR.stringify(entries));
|
|
|
553
630
|
|
|
554
631
|
## Hex Dumps
|
|
555
632
|
|
|
556
|
-
CBOR
|
|
633
|
+
`CBOR.toHex()` and `CBOR.fromHex()` are the shortcut entry points (see [Quick Examples](#cbor-bytes-to-hex-dump)).
|
|
634
|
+
For full AST access — byte ranges, re-encoding, selective inspection — use `item.toHexDump()` and `CBOR.fromHexDump()` directly:
|
|
557
635
|
|
|
558
636
|
```ts
|
|
559
637
|
import { CBOR } from '@cbortech/cbor';
|
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-BQYXoTz7.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;
|
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-
|
|
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-Cc4If3gy.js";
|
|
2
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 };
|
package/dist/cbor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CborItem } from './ast/CborItem';
|
|
2
|
-
import { CBOROptions, FromCBOROptions, FromCDNOptions, FromHexDumpOptions, FromJSOptions, ToCBOROptions, ToCDNOptions, ToJSOptions, CBOR_OMIT } from './types';
|
|
2
|
+
import { CBOROptions, FromCBOROptions, FromCBORSeqOptions, FromCDNOptions, FromCDNSeqOptions, FromHexDumpOptions, FromJSOptions, ToCBOROptions, ToCDNOptions, ToHexDumpOptions, ToJSOptions, CBOR_OMIT } from './types';
|
|
3
3
|
import { dt_as_Date as _dt_as_Date } from './extensions/dt';
|
|
4
4
|
import { MapEntries as _MapEntries } from './mapEntries';
|
|
5
5
|
import { Simple as _Simple } from './simple';
|
|
@@ -58,17 +58,24 @@ export declare class CBOR {
|
|
|
58
58
|
fromEDN(text: string, options?: FromCDNOptions): CborItem;
|
|
59
59
|
fromJS(value: unknown, options?: FromJSOptions): CborItem;
|
|
60
60
|
fromHexDump(text: string, options?: FromHexDumpOptions): CborItem;
|
|
61
|
+
fromCBORSeq(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions): Generator<CborItem>;
|
|
62
|
+
fromCDNSeq(text: string, options?: FromCDNSeqOptions): Generator<CborItem>;
|
|
63
|
+
fromHexDumpSeq(text: string, options?: FromHexDumpOptions): Generator<CborItem>;
|
|
61
64
|
decode(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToJSOptions): unknown;
|
|
65
|
+
decodeSeq(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions & ToJSOptions): Generator<unknown>;
|
|
66
|
+
parseSeq(text: string, options?: FromCDNSeqOptions & ToJSOptions): Generator<unknown>;
|
|
62
67
|
encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
compile(text: string, options?: FromCDNSeqOptions & ToCBOROptions): Uint8Array;
|
|
69
|
+
decompile(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions & ToCDNOptions): string;
|
|
70
|
+
toHex(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions & ToHexDumpOptions): string;
|
|
71
|
+
fromHex(text: string, options?: FromHexDumpOptions & ToCBOROptions): Uint8Array;
|
|
72
|
+
/** @deprecated Use `decompile()` instead. */
|
|
66
73
|
cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
74
|
+
/** @deprecated Use `decompile()` instead. */
|
|
67
75
|
cborToCdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
68
|
-
/**
|
|
69
|
-
* @deprecated Use `cdnToCbor()` or `fromCDN(text, options).toCBOR(options)` instead.
|
|
70
|
-
*/
|
|
76
|
+
/** @deprecated Use `compile()` instead. */
|
|
71
77
|
cborEdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
78
|
+
/** @deprecated Use `compile()` instead. */
|
|
72
79
|
cdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
73
80
|
parse(text: string): unknown;
|
|
74
81
|
parse(text: string, reviver: (this: unknown, key: unknown, value: unknown) => unknown): unknown;
|
|
@@ -87,6 +94,12 @@ export declare class CBOR {
|
|
|
87
94
|
* @deprecated Use `fromCDN()` instead.
|
|
88
95
|
*/
|
|
89
96
|
static fromEDN(text: string, options?: FromCDNOptions): CborItem;
|
|
97
|
+
/** アノテーション付き hex dump テキストから CBOR Sequence を item ごとにデコードするジェネレータ。 */
|
|
98
|
+
static fromHexDumpSeq(text: string, options?: FromHexDumpOptions): Generator<CborItem>;
|
|
99
|
+
/** CBOR Sequence (RFC 8742) を item ごとにデコードするジェネレータ。 */
|
|
100
|
+
static fromCBORSeq(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions): Generator<CborItem>;
|
|
101
|
+
/** CDN テキストの複数 item を 1 つずつパースするジェネレータ。 */
|
|
102
|
+
static fromCDNSeq(text: string, options?: FromCDNSeqOptions): Generator<CborItem>;
|
|
90
103
|
/** Convert a JavaScript value into an AST node. */
|
|
91
104
|
static fromJS(value: unknown, options?: FromJSOptions): CborItem;
|
|
92
105
|
/**
|
|
@@ -103,27 +116,47 @@ export declare class CBOR {
|
|
|
103
116
|
static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem;
|
|
104
117
|
/** Decode CBOR binary data directly to a JavaScript value. */
|
|
105
118
|
static decode(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToJSOptions): unknown;
|
|
119
|
+
/** Decode a CBOR Sequence (RFC 8742), yielding each item as a JavaScript value. */
|
|
120
|
+
static decodeSeq(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions & ToJSOptions): Generator<unknown>;
|
|
121
|
+
/** Parse a CDN Sequence text string, yielding each item as a JavaScript value. */
|
|
122
|
+
static parseSeq(text: string, options?: FromCDNSeqOptions & ToJSOptions): Generator<unknown>;
|
|
106
123
|
/** Encode a JavaScript value directly to CBOR binary data. */
|
|
107
124
|
static encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array;
|
|
108
125
|
/**
|
|
109
|
-
*
|
|
126
|
+
* Compile a CDN text string to CBOR binary data.
|
|
127
|
+
* Multi-item CDN Sequences produce a CBOR Sequence (RFC 8742): concatenated items.
|
|
110
128
|
*/
|
|
111
|
-
static
|
|
129
|
+
static compile(text: string, options?: FromCDNSeqOptions & ToCBOROptions): Uint8Array;
|
|
130
|
+
/**
|
|
131
|
+
* Decompile CBOR binary data to a CDN text string.
|
|
132
|
+
* CBOR Sequences (RFC 8742) produce multi-item CDN output, with items separated by newlines.
|
|
133
|
+
*/
|
|
134
|
+
static decompile(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions & ToCDNOptions): string;
|
|
135
|
+
/**
|
|
136
|
+
* Convert CBOR binary data to an annotated hex dump string.
|
|
137
|
+
* CBOR Sequences (RFC 8742) produce one dump per item, separated by newlines.
|
|
138
|
+
*/
|
|
139
|
+
static toHex(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions & ToHexDumpOptions): string;
|
|
140
|
+
/**
|
|
141
|
+
* Parse an annotated hex dump string to CBOR binary data.
|
|
142
|
+
* Multi-item dumps produce a CBOR Sequence (RFC 8742): concatenated items.
|
|
143
|
+
*/
|
|
144
|
+
static fromHex(text: string, options?: FromHexDumpOptions & ToCBOROptions): Uint8Array;
|
|
112
145
|
/**
|
|
113
146
|
* Convert CBOR binary data directly to a CDN text string.
|
|
114
147
|
*
|
|
115
|
-
* @deprecated Use `CBOR.
|
|
148
|
+
* @deprecated Use `CBOR.decompile()` instead.
|
|
116
149
|
*/
|
|
150
|
+
static cborToCdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
151
|
+
/** @deprecated Use `CBOR.decompile()` instead. */
|
|
117
152
|
static cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
118
|
-
/**
|
|
119
|
-
* Convert a CDN text string directly to CBOR binary data.
|
|
120
|
-
*/
|
|
121
|
-
static cdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
122
153
|
/**
|
|
123
154
|
* Convert a CDN text string directly to CBOR binary data.
|
|
124
155
|
*
|
|
125
|
-
* @deprecated Use `CBOR.
|
|
156
|
+
* @deprecated Use `CBOR.compile()` instead.
|
|
126
157
|
*/
|
|
158
|
+
static cdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
159
|
+
/** @deprecated Use `CBOR.compile()` instead. */
|
|
127
160
|
static cborEdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
128
161
|
/**
|
|
129
162
|
* Parse a CDN text string directly to a JavaScript value.
|
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-Cg5EIl83.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.n?i:new e.n(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.n,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
|
@@ -25,6 +25,8 @@ export interface Token {
|
|
|
25
25
|
export interface TokenizerOptions {
|
|
26
26
|
/** Character offset at which tokenization starts. */
|
|
27
27
|
offset?: number;
|
|
28
|
+
/** When true, RS (U+001E, RFC 7464 record separator) is treated as whitespace. */
|
|
29
|
+
skipRS?: boolean;
|
|
28
30
|
}
|
|
29
31
|
export interface EdnComment {
|
|
30
32
|
kind: 'line' | 'block';
|
|
@@ -42,6 +44,7 @@ export declare class Tokenizer {
|
|
|
42
44
|
private col;
|
|
43
45
|
private _peeked;
|
|
44
46
|
private _lastConsumedEndOffset;
|
|
47
|
+
private readonly skipRS;
|
|
45
48
|
/** Comments encountered while scanning, appended in source order. */
|
|
46
49
|
readonly comments: EdnComment[];
|
|
47
50
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./tokenizer-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./tokenizer-Cg5EIl83.cjs"),t=require("./mapEntries-BQYXoTz7.cjs");function n(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===`
|
|
2
2
|
`||r===`\r`){n++;continue}if(r===`#`){for(;n<e.length&&e[n]!==`
|
|
3
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(e,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=t.w(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 e{static OMIT=t.E;static TAG=t.D;static Tag=t.k;static Simple=t.T;static MapEntries=t.t;static dt_as_Date=t.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(t,n){let r=e.fromCBOR(t,this.#t(n));return r._defaults=this.#e,r}fromCDN(t,n){let r=e.fromCDN(t,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(t,n){let r=e.fromJS(t,this.#t(n));return r._defaults=this.#e,r}fromHexDump(t,n){let r=e.fromHexDump(t,this.#t(n));return r._defaults=this.#e,r}decode(t,n){return e.decode(t,this.#t(n))}encode(t,n){return e.encode(t,this.#t(n))}
|
|
5
|
-
|
|
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(e,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=t.w(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 e{static OMIT=t.E;static TAG=t.D;static Tag=t.k;static Simple=t.T;static MapEntries=t.t;static dt_as_Date=t.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(t,n){let r=e.fromCBOR(t,this.#t(n));return r._defaults=this.#e,r}fromCDN(t,n){let r=e.fromCDN(t,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(t,n){let r=e.fromJS(t,this.#t(n));return r._defaults=this.#e,r}fromHexDump(t,n){let r=e.fromHexDump(t,this.#t(n));return r._defaults=this.#e,r}*fromCBORSeq(t,n){for(let r of e.fromCBORSeq(t,this.#t(n)))r._defaults=this.#e,yield r}*fromCDNSeq(t,n){for(let r of e.fromCDNSeq(t,this.#t(n)))r._defaults=this.#e,yield r}*fromHexDumpSeq(t,n){for(let r of e.fromHexDumpSeq(t,this.#t(n)))r._defaults=this.#e,yield r}decode(t,n){return e.decode(t,this.#t(n))}*decodeSeq(t,n){yield*e.decodeSeq(t,this.#t(n))}*parseSeq(t,n){yield*e.parseSeq(t,this.#t(n))}encode(t,n){return e.encode(t,this.#t(n))}compile(t,n){return e.compile(t,this.#t(n))}decompile(t,n){return e.decompile(t,this.#t(n))}toHex(t,n){return e.toHex(t,this.#t(n))}fromHex(t,n){return e.fromHex(t,this.#t(n))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(t,n){let r=this.#t(n),i=e.fromCBOR(t,r);return i._defaults=this.#e,i.toCDN(r)}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(t,n){let r=this.#t(n);return e.fromCDN(t,r).toCBOR(r)}parse(t,n){if(typeof n==`function`){let r=this.#t({reviver:n});return e.fromCDN(t,r).toJS(r)}let r=this.#t(n);return e.fromCDN(t,r).toJS(r)}stringify(t,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=E(r)),e.stringify(t,i)}return e.stringify(t,this.#t(n??void 0))}format(t,n){return e.format(t,this.#t(n))}static fromCBOR(e,n){return t.i(e,n)}static fromCDN(e,n){return t.s(e,n)}static fromEDN(t,n){return e.fromCDN(t,n)}static*fromHexDumpSeq(t,n){let r=[],i=x(t).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*e.fromCBORSeq(new Uint8Array(r),n)}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 r=t.i(e,{...n,offset:i,allowTrailing:!0});yield r,i=r.end}}static*fromCDNSeq(e,n){let r=0,i=!0;for(;;){let{offset:a,hadSeparator:o,commaOffset:s}=T(e,r,n);if(i&&s>=0){let e=`leading comma in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(e);w(e,s,n)}if(a>=e.length)break;if(!i&&!o){let e=`CDN sequence items must be separated by whitespace, comma, or comment`;if(n?.strict!==!1)throw SyntaxError(e);w(e,a,n)}r=a;let c;try{c=t.s(e,{...n,offset:r,allowTrailing:!0,_skipRS:!0})}catch(e){if(n?.strict!==!1)throw e;w(e instanceof Error?e.message:String(e),r,n);break}yield c,r=c.end,i=!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(t,n){return e.fromCBOR(t,n).toJS(n)}static*decodeSeq(t,n){for(let r of e.fromCBORSeq(t,n))yield r.toJS(n)}static*parseSeq(t,n){for(let r of e.fromCDNSeq(t,n))yield r.toJS(n)}static encode(t,n){return e.fromJS(t,n).toCBOR(n)}static compile(t,n){let r=[...e.fromCDNSeq(t,n)].map(e=>e.toCBOR(n)),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(t,n){return[...e.fromCBORSeq(t,n)].map(e=>e.toCDN(n)).join(`
|
|
5
|
+
`)}static toHex(t,n){return[...e.fromCBORSeq(t,n)].map(e=>e.toHexDump(n)).join(`
|
|
6
|
+
`)}static fromHex(t,n){let r=[...e.fromHexDumpSeq(t,n)].map(e=>e.toCBOR(n)),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(t,n){return e.fromCBOR(t,n).toCDN(n)}static cborToCborEdn(t,n){return e.fromCBOR(t,n).toCDN(n)}static cdnToCbor(t,n){return e.fromCDN(t,n).toCBOR(n)}static cborEdnToCbor(t,n){return e.fromCDN(t,n).toCBOR(n)}static parse(t,n){return typeof n==`function`?e.fromCDN(t).toJS({reviver:n}):e.fromCDN(t,n).toJS(n)}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=E(r);if(i){let n=t.n(e,i);return n===void 0||n===t.E?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.E)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(t,n){return e.fromCDN(t,n).toCDN(n)}};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){let r={message:e,offset:t};n?.onWarning?n.onWarning(r):n?.silent||console.warn(`CDN sequence warning at offset ${t}: ${e}`)}function T(e,t,n){let r=t,i=!1,a=!1,o=-1;for(;r<e.length;){let t=e[r];if(t===` `||t===` `||t===`\r`||t===`
|
|
8
|
+
`||t===``){i=!0,r++;continue}if(t===`#`){i=!0;let t=e.indexOf(`
|
|
9
|
+
`,r+1);r=t<0?e.length:t+1;continue}if(t===`/`&&e[r+1]===`/`){i=!0;let t=e.indexOf(`
|
|
10
|
+
`,r+2);r=t<0?e.length:t+1;continue}if(t===`/`&&e[r+1]===`*`){i=!0;let t=e.indexOf(`*/`,r+2);if(t<0){let t=`unterminated /* comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);w(t,r,n),r=e.length}else r=t+2;continue}if(t===`/`&&e[r+1]!==`/`){i=!0;let t=e.indexOf(`/`,r+1);if(t<0){let t=`unterminated / comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);w(t,r,n),r=e.length}else r=t+1;continue}if(t===`,`&&!a){i=!0,a=!0,o=r,r++;continue}break}return{offset:r,hadSeparator:i,commaOffset:o}}function E(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.E,exports.CBOR_TAG=t.D,exports.CdnSyntaxError=e.n,exports.MapEntries=t.t,exports.Null=t.O,exports.Simple=t.T,exports.Tag=t.k,exports.Undefined=t.A,exports.b32=s,exports.dt_as_Date=t.a,exports.float=_,exports.h32=c,exports.same=y;
|
|
6
11
|
//# sourceMappingURL=index.cjs.map
|