@cbortech/cbor 0.25.9 → 0.25.11
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 +34 -5
- package/README.md +36 -5
- package/dist/ast/CborByteString.d.ts +9 -0
- package/dist/ast/CborFloat.d.ts +9 -0
- package/dist/ast/CborTextString.d.ts +3 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cbor/encode.d.ts +11 -0
- package/dist/cbor.d.ts +8 -1
- package/dist/cdn/index.cjs +2 -2
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/serialize-utils.d.ts +36 -0
- package/dist/cdn/tokenizer.d.ts +37 -2
- package/dist/index.cjs +10 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +83 -75
- package/dist/index.js.map +1 -1
- package/dist/{mapEntries-I8f0WuwK.js → mapEntries-CYvdsAfP.js} +1047 -872
- package/dist/mapEntries-CYvdsAfP.js.map +1 -0
- package/dist/mapEntries-vOYb5Q1s.cjs +11 -0
- package/dist/mapEntries-vOYb5Q1s.cjs.map +1 -0
- package/dist/tokenizer-CVcIyZZa.cjs +30 -0
- package/dist/tokenizer-CVcIyZZa.cjs.map +1 -0
- package/dist/{tokenizer-CETZf2NR.js → tokenizer-DkLlZ1gc.js} +161 -349
- package/dist/tokenizer-DkLlZ1gc.js.map +1 -0
- package/dist/types.d.ts +66 -1
- package/dist/utils/hex.d.ts +5 -0
- package/package.json +3 -3
- package/dist/mapEntries-BkcJsv3C.cjs +0 -12
- package/dist/mapEntries-BkcJsv3C.cjs.map +0 -1
- package/dist/mapEntries-I8f0WuwK.js.map +0 -1
- package/dist/tokenizer-CETZf2NR.js.map +0 -1
- package/dist/tokenizer-CMK8MtYl.cjs +0 -30
- package/dist/tokenizer-CMK8MtYl.cjs.map +0 -1
package/README.ja.md
CHANGED
|
@@ -212,15 +212,15 @@ console.log(text);
|
|
|
212
212
|
|
|
213
213
|
### テキスト文字列を分割して整形する
|
|
214
214
|
|
|
215
|
-
`
|
|
216
|
-
|
|
215
|
+
`splitNewline` を使うと、長いテキスト文字列を改行文字の位置で CDN の文字列連結として
|
|
216
|
+
分割できます。このオプションは `indent` を指定したときに適用されます。
|
|
217
217
|
|
|
218
218
|
```ts
|
|
219
219
|
import { CBOR } from '@cbortech/cbor';
|
|
220
220
|
|
|
221
221
|
const text = CBOR.format('{"text": "line1\\nline2\\nline3"}', {
|
|
222
222
|
indent: 2,
|
|
223
|
-
|
|
223
|
+
splitNewline: true,
|
|
224
224
|
});
|
|
225
225
|
|
|
226
226
|
console.log(text);
|
|
@@ -231,14 +231,16 @@ console.log(text);
|
|
|
231
231
|
// }
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
文字列の中身が CDN や JSON 風の内容なら、`
|
|
234
|
+
文字列の中身が CDN や JSON 風の内容なら、`splitCdn` で周囲の CDN と同じように
|
|
235
|
+
構造に応じた改行とインデントを入れて整形できます。両方のオプションは併用でき、
|
|
236
|
+
配列で指定する従来の `textStringFormat` オプションを置き換えます(非推奨)。
|
|
235
237
|
|
|
236
238
|
```ts
|
|
237
239
|
import { CBOR } from '@cbortech/cbor';
|
|
238
240
|
|
|
239
241
|
const text = CBOR.format('{"cdn": "[1,2,3]"}', {
|
|
240
242
|
indent: 2,
|
|
241
|
-
|
|
243
|
+
splitCdn: true,
|
|
242
244
|
});
|
|
243
245
|
|
|
244
246
|
console.log(text);
|
|
@@ -251,6 +253,33 @@ console.log(text);
|
|
|
251
253
|
// }
|
|
252
254
|
```
|
|
253
255
|
|
|
256
|
+
### `+` による文字列連結を保持する
|
|
257
|
+
|
|
258
|
+
デフォルトでは、`CBOR.format()` は `+` による文字列連結を 1 つのリテラルに
|
|
259
|
+
結合します。`preserveConcatenation` を指定すると、テキスト文字列・バイト文字列とも
|
|
260
|
+
元の連結の区切りを保持します。`preserveByteString` を併用すると、バイト文字列の
|
|
261
|
+
各パートの元の表記も保持されます。
|
|
262
|
+
|
|
263
|
+
分割オプションとの関係: 文字列の中身が CDN としてパースできる場合は `splitCdn` が
|
|
264
|
+
`preserveConcatenation` より優先されます。`splitNewline` は共存し、保持した各パートに
|
|
265
|
+
改行文字が含まれていればさらにそこで分割します。
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
import { CBOR } from '@cbortech/cbor';
|
|
269
|
+
|
|
270
|
+
CBOR.format('"a" + "b"');
|
|
271
|
+
// '"ab"'
|
|
272
|
+
|
|
273
|
+
CBOR.format('"a" + "b"', { preserveConcatenation: true });
|
|
274
|
+
// '"a" + "b"'
|
|
275
|
+
|
|
276
|
+
CBOR.format("h'68' + b64'aQ'", {
|
|
277
|
+
preserveConcatenation: true,
|
|
278
|
+
preserveByteString: true,
|
|
279
|
+
});
|
|
280
|
+
// "h'68' + b64'aQ'"
|
|
281
|
+
```
|
|
282
|
+
|
|
254
283
|
## AST を扱う
|
|
255
284
|
|
|
256
285
|
`CBOR.fromCBOR()`、`CBOR.fromCDN()`、`CBOR.fromJS()` は CBOR item を返します。
|
package/README.md
CHANGED
|
@@ -214,15 +214,15 @@ console.log(text);
|
|
|
214
214
|
|
|
215
215
|
### Split text strings while formatting
|
|
216
216
|
|
|
217
|
-
`
|
|
218
|
-
It is applied when `indent` is specified.
|
|
217
|
+
`splitNewline` splits long text strings at newline characters using CDN
|
|
218
|
+
string concatenation. It is applied when `indent` is specified.
|
|
219
219
|
|
|
220
220
|
```ts
|
|
221
221
|
import { CBOR } from '@cbortech/cbor';
|
|
222
222
|
|
|
223
223
|
const text = CBOR.format('{"text": "line1\\nline2\\nline3"}', {
|
|
224
224
|
indent: 2,
|
|
225
|
-
|
|
225
|
+
splitNewline: true,
|
|
226
226
|
});
|
|
227
227
|
|
|
228
228
|
console.log(text);
|
|
@@ -233,14 +233,17 @@ console.log(text);
|
|
|
233
233
|
// }
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
-
For strings that contain CDN or JSON-like content,
|
|
236
|
+
For strings that contain CDN or JSON-like content, `splitCdn` formats the
|
|
237
|
+
string content with structure-aware line breaks and indentation, the same
|
|
238
|
+
way the surrounding CDN is formatted. Both options can be combined, and they
|
|
239
|
+
replace the deprecated array-valued `textStringFormat` option.
|
|
237
240
|
|
|
238
241
|
```ts
|
|
239
242
|
import { CBOR } from '@cbortech/cbor';
|
|
240
243
|
|
|
241
244
|
const text = CBOR.format('{"cdn": "[1,2,3]"}', {
|
|
242
245
|
indent: 2,
|
|
243
|
-
|
|
246
|
+
splitCdn: true,
|
|
244
247
|
});
|
|
245
248
|
|
|
246
249
|
console.log(text);
|
|
@@ -253,6 +256,34 @@ console.log(text);
|
|
|
253
256
|
// }
|
|
254
257
|
```
|
|
255
258
|
|
|
259
|
+
### Preserve `+` string concatenation
|
|
260
|
+
|
|
261
|
+
By default, `CBOR.format()` joins `+` string concatenation into a single
|
|
262
|
+
literal. `preserveConcatenation` keeps the original part boundaries for both
|
|
263
|
+
text strings and byte strings; add `preserveByteString` to also keep the
|
|
264
|
+
original spelling of byte string parts.
|
|
265
|
+
|
|
266
|
+
`preserveConcatenation` interacts with the split options: `splitCdn` takes
|
|
267
|
+
precedence when the string content parses as CDN, while `splitNewline`
|
|
268
|
+
combines with it by further splitting the preserved parts at newline
|
|
269
|
+
characters.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
import { CBOR } from '@cbortech/cbor';
|
|
273
|
+
|
|
274
|
+
CBOR.format('"a" + "b"');
|
|
275
|
+
// '"ab"'
|
|
276
|
+
|
|
277
|
+
CBOR.format('"a" + "b"', { preserveConcatenation: true });
|
|
278
|
+
// '"a" + "b"'
|
|
279
|
+
|
|
280
|
+
CBOR.format("h'68' + b64'aQ'", {
|
|
281
|
+
preserveConcatenation: true,
|
|
282
|
+
preserveByteString: true,
|
|
283
|
+
});
|
|
284
|
+
// "h'68' + b64'aQ'"
|
|
285
|
+
```
|
|
286
|
+
|
|
256
287
|
## Working With The AST
|
|
257
288
|
|
|
258
289
|
`CBOR.fromCBOR()`, `CBOR.fromCDN()`, and `CBOR.fromJS()` return a CBOR item.
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
3
|
import { CborWriter, EncodingWidth } from '../cbor/encode';
|
|
4
|
+
/** One part of a byte string parsed from a CDN `+` concatenation chain. */
|
|
5
|
+
export interface CborByteStringPart {
|
|
6
|
+
bytes: Uint8Array;
|
|
7
|
+
/** Original literal source text, when the part came from a byte string token. */
|
|
8
|
+
source?: string;
|
|
9
|
+
}
|
|
4
10
|
/** CBOR Major Type 2 — definite-length byte string. */
|
|
5
11
|
export declare class CborByteString extends CborItem {
|
|
6
12
|
readonly indefiniteLength: false;
|
|
@@ -9,10 +15,13 @@ export declare class CborByteString extends CborItem {
|
|
|
9
15
|
readonly ednEncoding: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex';
|
|
10
16
|
encodingWidth: EncodingWidth | undefined;
|
|
11
17
|
readonly ednSource: string | undefined;
|
|
18
|
+
/** Part boundaries of the original `+` concatenation chain, if any. */
|
|
19
|
+
readonly ednParts: readonly CborByteStringPart[] | undefined;
|
|
12
20
|
constructor(value: Uint8Array, options?: {
|
|
13
21
|
ednEncoding?: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex';
|
|
14
22
|
encodingWidth?: EncodingWidth;
|
|
15
23
|
ednSource?: string;
|
|
24
|
+
ednParts?: readonly CborByteStringPart[];
|
|
16
25
|
});
|
|
17
26
|
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
18
27
|
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
package/dist/ast/CborFloat.d.ts
CHANGED
|
@@ -25,8 +25,17 @@ export declare class CborFloat extends CborItem {
|
|
|
25
25
|
* to round-trip the literal when `appStrings` is not false.
|
|
26
26
|
*/
|
|
27
27
|
ednSource?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Original encoded payload bytes (big-endian, without the initial byte),
|
|
30
|
+
* set by the decoder when the value is NaN so that NaN payloads survive a
|
|
31
|
+
* decode → encode round-trip (a JS `number` cannot carry them).
|
|
32
|
+
* Used by the encoder only when `value` is NaN and the length matches the
|
|
33
|
+
* byte size of the encoded `precision`; ignored otherwise.
|
|
34
|
+
*/
|
|
35
|
+
rawBits?: Uint8Array;
|
|
28
36
|
constructor(value: number, options?: {
|
|
29
37
|
precision?: FloatPrecision;
|
|
38
|
+
rawBits?: Uint8Array;
|
|
30
39
|
});
|
|
31
40
|
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
32
41
|
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
@@ -6,8 +6,11 @@ export declare class CborTextString extends CborItem {
|
|
|
6
6
|
readonly indefiniteLength: false;
|
|
7
7
|
readonly value: string;
|
|
8
8
|
encodingWidth: EncodingWidth | undefined;
|
|
9
|
+
/** Part boundaries of the original `+` concatenation chain, if any. */
|
|
10
|
+
readonly ednParts: readonly string[] | undefined;
|
|
9
11
|
constructor(value: string, options?: {
|
|
10
12
|
encodingWidth?: EncodingWidth;
|
|
13
|
+
ednParts?: readonly string[];
|
|
11
14
|
});
|
|
12
15
|
_encodeTo(writer: CborWriter, _options?: ToCBOROptions): void;
|
|
13
16
|
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
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-vOYb5Q1s.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-CYvdsAfP.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/encode.d.ts
CHANGED
|
@@ -30,6 +30,17 @@ export declare class CborWriter {
|
|
|
30
30
|
writeFloat16(value: number): void;
|
|
31
31
|
writeFloat32(value: number): void;
|
|
32
32
|
writeFloat64(value: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Write a definite-length string head + UTF-8 body in one pass.
|
|
35
|
+
*
|
|
36
|
+
* The body is encoded directly into this writer's buffer with
|
|
37
|
+
* TextEncoder.encodeInto(), avoiding the temporary Uint8Array that
|
|
38
|
+
* TextEncoder.encode() allocates for every string. The head position is
|
|
39
|
+
* predicted from the UTF-16 length (a lower bound on the UTF-8 length);
|
|
40
|
+
* when multi-byte characters push the byte count across a head-width
|
|
41
|
+
* boundary the body is shifted up with copyWithin (rare in practice).
|
|
42
|
+
*/
|
|
43
|
+
writeTextString(mt: number, value: string, encodingWidth?: EncodingWidth): void;
|
|
33
44
|
/** Copy of the bytes written so far. */
|
|
34
45
|
finish(): Uint8Array;
|
|
35
46
|
}
|
package/dist/cbor.d.ts
CHANGED
|
@@ -98,7 +98,14 @@ export declare class CBOR {
|
|
|
98
98
|
static fromHexDumpSeq(text: string, options?: FromHexDumpOptions): Generator<CborItem>;
|
|
99
99
|
/** CBOR Sequence (RFC 8742) を item ごとにデコードするジェネレータ。 */
|
|
100
100
|
static fromCBORSeq(input: ArrayBufferView | ArrayBufferLike, options?: FromCBORSeqOptions): Generator<CborItem>;
|
|
101
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* CDN テキストの複数 item を 1 つずつパースするジェネレータ。
|
|
103
|
+
*
|
|
104
|
+
* `preserveComments` が有効な場合、item 間のコメントは次の item の
|
|
105
|
+
* leading コメントとして、item と同じ行にあるコメントはその item の
|
|
106
|
+
* trailing コメントとして付与される。最後の item の後の行にだけ
|
|
107
|
+
* コメントが残る場合、そのコメントはどの item にも属さず破棄される。
|
|
108
|
+
*/
|
|
102
109
|
static fromCDNSeq(text: string, options?: FromCDNSeqOptions): Generator<CborItem>;
|
|
103
110
|
/** Convert a JavaScript value into an AST node. */
|
|
104
111
|
static fromJS(value: unknown, options?: FromJSOptions): CborItem;
|
package/dist/cdn/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../tokenizer-
|
|
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.
|
|
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]===`
|
|
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
|
@@ -4,6 +4,13 @@ import { EncodingWidth } from '../cbor/encode';
|
|
|
4
4
|
export declare function resolveIndent(options: ToCDNOptions | undefined): string | null;
|
|
5
5
|
/** Build the indent prefix for a given depth. */
|
|
6
6
|
export declare function indentOf(indentStr: string, depth: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* Join pre-serialized string-concatenation part literals with `+`.
|
|
9
|
+
*
|
|
10
|
+
* Single-line (` + `) when indent is disabled; otherwise each continuation
|
|
11
|
+
* part starts on its own line, indented one level deeper than the owner.
|
|
12
|
+
*/
|
|
13
|
+
export declare function joinConcatParts(literals: readonly string[], indentStr: string | null, depth: number): string;
|
|
7
14
|
export interface Commented {
|
|
8
15
|
comments?: CborComments;
|
|
9
16
|
}
|
|
@@ -43,6 +50,35 @@ export declare function resolveSeparators(options: ToCDNOptions | undefined, com
|
|
|
43
50
|
trailSep: string;
|
|
44
51
|
colSep: string;
|
|
45
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Shared CDN serialization for bracketed containers (CborArray / CborMap):
|
|
55
|
+
* encoding-indicator / `_` prefix resolution, single-line vs multi-line
|
|
56
|
+
* selection (comments force multi-line), separators, and per-entry
|
|
57
|
+
* leading/trailing plus container dangling comments.
|
|
58
|
+
*
|
|
59
|
+
* Entries are accessed through per-index callbacks (not materialised entry
|
|
60
|
+
* objects) so the common no-comments path allocates nothing per entry.
|
|
61
|
+
* `hasEntryComments`, `entryLeadingNode`, and `entryTrailing` are consulted
|
|
62
|
+
* only when `preserveComments` is set. `renderEntry` receives the resolved
|
|
63
|
+
* `colSep` (': ' or ':' depending on compact mode) for rendering map pairs.
|
|
64
|
+
*/
|
|
65
|
+
export declare function serializeContainer(p: {
|
|
66
|
+
node: Commented;
|
|
67
|
+
options: ToCDNOptions | undefined;
|
|
68
|
+
depth: number;
|
|
69
|
+
openChar: '[' | '{';
|
|
70
|
+
closeChar: ']' | '}';
|
|
71
|
+
count: number;
|
|
72
|
+
indefiniteLength: boolean;
|
|
73
|
+
encodingWidth: EncodingWidth | undefined;
|
|
74
|
+
hasEntryComments: () => boolean;
|
|
75
|
+
/** Render entry `i` at child depth (`item` or `key: value`). */
|
|
76
|
+
renderEntry: (i: number, colSep: string) => string;
|
|
77
|
+
/** Node whose leading comments are emitted above entry `i` (item / map key). */
|
|
78
|
+
entryLeadingNode: (i: number) => Commented;
|
|
79
|
+
/** Pre-formatted trailing comment text for entry `i` (starts with ' ', or ''). */
|
|
80
|
+
entryTrailing: (i: number, style: 'c-style' | 'cdn-style' | undefined) => string;
|
|
81
|
+
}): string;
|
|
46
82
|
export declare function serializeBytes(bytes: Uint8Array, encoding?: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex', sqstr?: 'printable-string' | 'string' | 'none'): string;
|
|
47
83
|
/**
|
|
48
84
|
* Produce a single-quoted EDN app-string content `'...'` from a string value.
|
package/dist/cdn/tokenizer.d.ts
CHANGED
|
@@ -22,6 +22,16 @@ export interface Token {
|
|
|
22
22
|
/** Only set when type === 'APP_STRING': the extension prefix (e.g. 'dt', 'DT'). */
|
|
23
23
|
appPrefix?: string;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
* SQSTR tokens carry the UTF-8 payload the tokenizer already encoded, so the
|
|
28
|
+
* parser does not decode the hex `value` back into the same bytes. The
|
|
29
|
+
* property is non-enumerable and deliberately absent from the public `Token`
|
|
30
|
+
* type: the tokenize() API shape (keys, JSON.stringify, spread) is unchanged.
|
|
31
|
+
*/
|
|
32
|
+
export interface SqstrToken extends Token {
|
|
33
|
+
readonly _sqstrBytes?: Uint8Array;
|
|
34
|
+
}
|
|
25
35
|
export interface TokenizerOptions {
|
|
26
36
|
/** Character offset at which tokenization starts. */
|
|
27
37
|
offset?: number;
|
|
@@ -50,9 +60,10 @@ export declare class Tokenizer {
|
|
|
50
60
|
/**
|
|
51
61
|
* When set, non-standard-but-JS-valid escape sequences are accepted instead
|
|
52
62
|
* of throwing. The callback receives a message and the position of the `\`
|
|
53
|
-
* (offset, line, column)
|
|
63
|
+
* (offset, line, column) plus the offset just past the escape sequence, so
|
|
64
|
+
* the parser can forward it as a range-carrying ParseWarning.
|
|
54
65
|
*/
|
|
55
|
-
onEscapeWarning?: (msg: string, offset: number, line: number, col: number) => void;
|
|
66
|
+
onEscapeWarning?: (msg: string, offset: number, line: number, col: number, endOffset: number) => void;
|
|
56
67
|
constructor(input: string, options?: TokenizerOptions);
|
|
57
68
|
peek(): Token;
|
|
58
69
|
consume(): Token;
|
|
@@ -177,7 +188,31 @@ export declare class Tokenizer {
|
|
|
177
188
|
* indicating whether any ellipsis was found.
|
|
178
189
|
*/
|
|
179
190
|
private _readHexByteContentElisionAware;
|
|
191
|
+
/** Start offset of the token currently being read (set by _readNext). */
|
|
192
|
+
private _tokStart;
|
|
180
193
|
private _readNext;
|
|
194
|
+
/**
|
|
195
|
+
* Build a complete Token for the source range [_tokStart, pos).
|
|
196
|
+
* Every token is constructed exactly once here — the previous two-step
|
|
197
|
+
* "partial object, then spread in raw/offsets" cost an extra object and a
|
|
198
|
+
* property-copy pass per token on the parse hot path.
|
|
199
|
+
*
|
|
200
|
+
* `appPrefix` is added only for app-string/app-sequence tokens so that
|
|
201
|
+
* ordinary tokens keep `'appPrefix' in tok === false`, matching the public
|
|
202
|
+
* tokenize() API shape documented on the Token interface.
|
|
203
|
+
*
|
|
204
|
+
* `raw` stays an eagerly-sliced own data property: Token is public API, and
|
|
205
|
+
* a getter would vanish under the consumer's own `{ ...token }` spread or
|
|
206
|
+
* JSON.stringify. The slice cost is minor next to the removed extra object.
|
|
207
|
+
*/
|
|
208
|
+
private _tok;
|
|
209
|
+
/**
|
|
210
|
+
* {@link _tok} variant for tokens whose processed `value` IS the raw source
|
|
211
|
+
* text — punctuation, keywords, and numbers without a leading `+`. Reuses
|
|
212
|
+
* `value` as `raw`, skipping a per-token slice on the densest token kinds.
|
|
213
|
+
* Callers must guarantee `value === input.slice(_tokStart, pos)`.
|
|
214
|
+
*/
|
|
215
|
+
private _tokV;
|
|
181
216
|
private _readNextCore;
|
|
182
217
|
/**
|
|
183
218
|
* Try to read `Infinity[_N]` immediately after a `+`/`-` sign at this.pos.
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
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-CVcIyZZa.cjs"),t=require("./mapEntries-vOYb5Q1s.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(
|
|
5
|
-
`)}static toHex(t
|
|
6
|
-
`)}static fromHex(t
|
|
7
|
-
`,t);return n<0?e.length:n}function C(e){return e.replace(/[^\r\n]/g,` `)}function w(e,t,n){let
|
|
8
|
-
|
|
9
|
-
`,
|
|
10
|
-
`,
|
|
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(`
|
|
5
|
+
`)}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===`
|
|
8
|
+
`){a=!0,s=!0,i++;continue}if(t===`#`){if(a=!0,l())break;let t=e.indexOf(`
|
|
9
|
+
`,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;
|
|
11
13
|
//# sourceMappingURL=index.cjs.map
|