@cbortech/cbor 0.25.0 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -326,37 +326,117 @@ console.log(text);
326
326
 
327
327
  ## オプション extension
328
328
 
329
+ このパッケージには、デフォルト有効ではないものの本体に同梱されている
330
+ extension があります。必要なものを `import` し、
331
+ `extensions` オプションに渡して使います。
332
+
333
+ ### b32 / h32
334
+
335
+ [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648) の Base32 エンコードによるバイト列リテラルです。
336
+ [RFC 8949](https://www.rfc-editor.org/rfc/rfc8949) §8 に記載があり、[draft-ietf-cbor-edn-literals](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/) でも触れられています。
337
+
338
+ - `b32` — §6 Base32(`A–Z 2–7` アルファベット)
339
+ - `h32` — §7 Base32Hex(`0–9 A–V` アルファベット)
340
+
341
+ ```ts
342
+ import { CBOR, b32, h32 } from '@cbortech/cbor';
343
+
344
+ const v1 = CBOR.fromCDN("b32'AEBAGBA'", { extensions: [b32] });
345
+ console.log(v1.toCDN({ appStrings: false }));
346
+ // h'01020304'
347
+
348
+ const v2 = CBOR.fromCDN("h32'00P00'", { extensions: [h32] });
349
+ console.log(v2.toCDN({ appStrings: false }));
350
+ // h'003200'
351
+ ```
352
+
353
+ ### float
354
+
355
+ 16 進数のビットパターンを IEEE 754 浮動小数点値として解釈します。
356
+ [draft-bormann-cbor-edn-app-ext](https://datatracker.ietf.org/doc/draft-bormann-cbor-edn-app-ext/)
357
+ に記載があり、[cbor-test-vectors](https://github.com/cbor-wg/cbor-test-vectors) でも使われています。
358
+
359
+ ```ts
360
+ import { CBOR, float } from '@cbortech/cbor';
361
+
362
+ const v = CBOR.fromCDN("float'7e00'", { extensions: [float] });
363
+ console.log(v.toCDN({ appStrings: false }));
364
+ // NaN
365
+
366
+ // バイト列から解釈する場合
367
+ const v2 = CBOR.fromCDN("float<<h'3f800000'>>", { extensions: [float] });
368
+ console.log(v2.toCDN({ appStrings: false }));
369
+ // 1.0_2
370
+ ```
371
+
372
+ ### same
373
+
374
+ `same<<expr, expr, ...>>` は、シーケンス内のすべての要素が同一の CBOR
375
+ バイト列になることを検証し、最初の要素を返す extension です。
376
+ [draft-bormann-cbor-edn-app-ext](https://datatracker.ietf.org/doc/draft-bormann-cbor-edn-app-ext/)
377
+ に記載があります。
378
+
379
+ ```ts
380
+ import { CBOR, same } from '@cbortech/cbor';
381
+
382
+ // すべての要素が同じバイト列かを検証し、最初の要素を返す
383
+ const v = CBOR.fromCDN("same<<h'0102', h'0102'>>", { extensions: [same] });
384
+ console.log(v.toCDN({ appStrings: false }));
385
+ // h'0102'
386
+
387
+ // 要素が 1 つでも有効(常にパスする)
388
+ const v2 = CBOR.fromCDN('same<<42>>', { extensions: [same] });
389
+ console.log(v2.toCDN({ appStrings: false }));
390
+ // 42
391
+ ```
392
+
393
+ ---
394
+
329
395
  追加の application extension は別パッケージとして公開されています。必要なものを
330
396
  インストールし、`extensions` オプションに渡して使います。
331
397
 
332
- `hash` は CDN の仕様に含まれる application extension ですが、利用には
333
- 外部パッケージが必要です。そのため、このパッケージ本体には含めず、
334
- `@cbortech/hash-extension` として提供しています。
398
+ ### hash
335
399
 
336
- `uuid` は CDN の仕様には定められていない、このライブラリ独自の
337
- application extension です。仕様上の標準機能と区別するため、
338
- `@cbortech/uuid-extension` として別パッケージで提供しています。
400
+ `hash` は [draft-ietf-cbor-edn-literals](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/) §3.3 で定義された標準の application extension です。
401
+ ハッシュアルゴリズムと値を `hash'algorithm:value'` の形式で表現します。
402
+ 実装には外部の暗号ライブラリが必要なため、[@cbortech/hash-extension](https://www.npmjs.com/package/@cbortech/hash-extension) として
403
+ 別パッケージで提供しています。
339
404
 
340
405
  ```bash
341
- npm install @cbortech/hash-extension @cbortech/uuid-extension
406
+ npm install @cbortech/hash-extension
342
407
  ```
343
408
 
344
409
  ```ts
345
410
  import { CBOR } from '@cbortech/cbor';
346
- import hashExtension from '@cbortech/hash-extension';
347
- import uuidExtension from '@cbortech/uuid-extension';
411
+ import { hash } from '@cbortech/hash-extension';
348
412
 
349
- const cbor = new CBOR({
350
- extensions: [hashExtension, uuidExtension],
351
- });
413
+ const cbor = new CBOR({ extensions: [hash] });
414
+
415
+ const digest = cbor.parse(
416
+ "hash'sha-256:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='"
417
+ );
418
+ // Uint8Array(32) [227, 176, 196, 66, 152, 252, 28, 20, 154, 251, 244, 200,
419
+ // 153, 111, 185, 36, 39, 174, 65, 228, 100, 155, 147, 76,
420
+ // 164, 149, 153, 27, 120, 82, 184, 85]
421
+ ```
422
+
423
+ ### uuid
424
+
425
+ `uuid` はこのライブラリ独自の application extension です。
426
+ [@cbortech/uuid-extension](https://www.npmjs.com/package/@cbortech/uuid-extension) として別パッケージで提供しています。
427
+
428
+ ```bash
429
+ npm install @cbortech/uuid-extension
430
+ ```
431
+
432
+ ```ts
433
+ import { CBOR } from '@cbortech/cbor';
434
+ import { uuid } from '@cbortech/uuid-extension';
352
435
 
353
- const digest = cbor.fromCDN("hash'foo'");
354
- console.log(digest.toCDN());
355
- // hash'foo'
436
+ const cbor = new CBOR({ extensions: [uuid] });
356
437
 
357
- const id = cbor.fromCDN("uuid'550e8400-e29b-41d4-a716-446655440000'");
358
- console.log(id.toCDN());
359
- // uuid'550e8400-e29b-41d4-a716-446655440000'
438
+ const id = cbor.parse("uuid'550e8400-e29b-41d4-a716-446655440000'");
439
+ // Uint8Array(16) [85, 14, 132, 0, 226, 155, 65, 212, 167, 22, 68, 102, 85, 68, 0, 0]
360
440
  ```
361
441
 
362
442
  ## タグ
package/README.md CHANGED
@@ -330,37 +330,118 @@ console.log(text);
330
330
 
331
331
  ## Optional Extensions
332
332
 
333
+ This package includes several bundled extensions that are not enabled by
334
+ default. Import what you need and pass it through the `extensions` option.
335
+
336
+ ### b32 / h32
337
+
338
+ Byte-string literals using [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648)
339
+ Base32 encoding. These prefixes are described in §8 of
340
+ [RFC 8949](https://www.rfc-editor.org/rfc/rfc8949) and also mentioned in
341
+ [draft-ietf-cbor-edn-literals](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/).
342
+
343
+ - `b32` — §6 Base32 (`A–Z 2–7` alphabet)
344
+ - `h32` — §7 Base32Hex (`0–9 A–V` alphabet)
345
+
346
+ ```ts
347
+ import { CBOR, b32, h32 } from '@cbortech/cbor';
348
+
349
+ const v1 = CBOR.fromCDN("b32'AEBAGBA'", { extensions: [b32] });
350
+ console.log(v1.toCDN({ appStrings: false }));
351
+ // h'01020304'
352
+
353
+ const v2 = CBOR.fromCDN("h32'00P00'", { extensions: [h32] });
354
+ console.log(v2.toCDN({ appStrings: false }));
355
+ // h'003200'
356
+ ```
357
+
358
+ ### float
359
+
360
+ Interprets a hex bit-pattern as an IEEE 754 floating-point value. This
361
+ extension is described in
362
+ [draft-bormann-cbor-edn-app-ext](https://datatracker.ietf.org/doc/draft-bormann-cbor-edn-app-ext/)
363
+ and also used in [cbor-test-vectors](https://github.com/cbor-wg/cbor-test-vectors).
364
+
365
+ ```ts
366
+ import { CBOR, float } from '@cbortech/cbor';
367
+
368
+ const v = CBOR.fromCDN("float'7e00'", { extensions: [float] });
369
+ console.log(v.toCDN({ appStrings: false }));
370
+ // NaN
371
+
372
+ // Interpret bytes as float bits
373
+ const v2 = CBOR.fromCDN("float<<h'3f800000'>>", { extensions: [float] });
374
+ console.log(v2.toCDN({ appStrings: false }));
375
+ // 1.0_2
376
+ ```
377
+
378
+ ### same
379
+
380
+ `same<<expr, expr, ...>>` verifies that every item in the sequence encodes to
381
+ identical CBOR bytes and returns the first item. This extension is described in
382
+ [draft-bormann-cbor-edn-app-ext](https://datatracker.ietf.org/doc/draft-bormann-cbor-edn-app-ext/).
383
+
384
+ ```ts
385
+ import { CBOR, same } from '@cbortech/cbor';
386
+
387
+ const v = CBOR.fromCDN("same<<h'0102', h'0102'>>", { extensions: [same] });
388
+ console.log(v.toCDN({ appStrings: false }));
389
+ // h'0102'
390
+
391
+ // A single-item sequence always passes
392
+ const v2 = CBOR.fromCDN('same<<42>>', { extensions: [same] });
393
+ console.log(v2.toCDN({ appStrings: false }));
394
+ // 42
395
+ ```
396
+
397
+ ---
398
+
333
399
  Additional application extensions are published as separate packages. Install
334
400
  the ones you need and pass them through the `extensions` option.
335
401
 
336
- `hash` is an application extension defined by the CDN specification, but
337
- it requires an external package. For that reason, it is not bundled with this
338
- package and is provided separately as `@cbortech/hash-extension`.
402
+ ### hash
339
403
 
340
- `uuid` is a library-specific application extension that is not defined by the
341
- CDN specification. To keep it distinct from standard CDN features, it
342
- is provided separately as `@cbortech/uuid-extension`.
404
+ `hash` is an application extension defined in §3.3 of
405
+ [draft-ietf-cbor-edn-literals](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/).
406
+ It represents cryptographic hash values in the form `hash'algorithm:value'`.
407
+ Because it requires an external cryptographic library, it is provided separately
408
+ as [@cbortech/hash-extension](https://www.npmjs.com/package/@cbortech/hash-extension).
343
409
 
344
410
  ```bash
345
- npm install @cbortech/hash-extension @cbortech/uuid-extension
411
+ npm install @cbortech/hash-extension
346
412
  ```
347
413
 
348
414
  ```ts
349
415
  import { CBOR } from '@cbortech/cbor';
350
- import hashExtension from '@cbortech/hash-extension';
351
- import uuidExtension from '@cbortech/uuid-extension';
416
+ import { hash } from '@cbortech/hash-extension';
352
417
 
353
- const cbor = new CBOR({
354
- extensions: [hashExtension, uuidExtension],
355
- });
418
+ const cbor = new CBOR({ extensions: [hash] });
419
+
420
+ const digest = cbor.parse(
421
+ "hash'sha-256:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='"
422
+ );
423
+ // Uint8Array(32) [227, 176, 196, 66, 152, 252, 28, 20, 154, 251, 244, 200,
424
+ // 153, 111, 185, 36, 39, 174, 65, 228, 100, 155, 147, 76,
425
+ // 164, 149, 153, 27, 120, 82, 184, 85]
426
+ ```
427
+
428
+ ### uuid
429
+
430
+ `uuid` is a library-specific application extension, provided separately as
431
+ [@cbortech/uuid-extension](https://www.npmjs.com/package/@cbortech/uuid-extension).
432
+
433
+ ```bash
434
+ npm install @cbortech/uuid-extension
435
+ ```
436
+
437
+ ```ts
438
+ import { CBOR } from '@cbortech/cbor';
439
+ import { uuid } from '@cbortech/uuid-extension';
356
440
 
357
- const digest = cbor.fromCDN("hash'foo'");
358
- console.log(digest.toCDN());
359
- // hash'foo'
441
+ const cbor = new CBOR({ extensions: [uuid] });
360
442
 
361
- const id = cbor.fromCDN("uuid'550e8400-e29b-41d4-a716-446655440000'");
362
- console.log(id.toCDN());
363
- // uuid'550e8400-e29b-41d4-a716-446655440000'
443
+ const id = cbor.parse("uuid'550e8400-e29b-41d4-a716-446655440000'");
444
+ // Uint8Array(16) [85, 14, 132, 0, 226, 155, 65, 212, 167, 22, 68, 102, 85, 68, 0, 0]
364
445
  ```
365
446
 
366
447
  ## Tags
@@ -0,0 +1,20 @@
1
+ import { ToCDNOptions, ToCBOROptions, ToJSOptions } from '../types';
2
+ import { CborItem } from './CborItem';
3
+ /**
4
+ * Wraps a resolved app-sequence result and preserves the original EDN source
5
+ * text for round-trip fidelity.
6
+ *
7
+ * When `appStrings !== false`, `_toCDN` returns the stored source text verbatim.
8
+ * Otherwise it delegates to the wrapped item so the caller gets a plain value.
9
+ *
10
+ * CBOR encoding and JS conversion always delegate to the inner item so the
11
+ * wrapper is fully transparent for those operations.
12
+ */
13
+ export declare class CborAppSeqResult extends CborItem {
14
+ readonly inner: CborItem;
15
+ readonly ednSource: string;
16
+ constructor(inner: CborItem, ednSource: string);
17
+ _toCBOR(options?: ToCBOROptions): Uint8Array;
18
+ _toCDN(options: ToCDNOptions | undefined, depth: number): string;
19
+ _toJS(options?: ToJSOptions): unknown;
20
+ }
@@ -18,6 +18,12 @@ export declare class CborFloat extends CborItem {
18
18
  * - `undefined`: encoder auto-selects the smallest lossless size.
19
19
  */
20
20
  readonly precision: FloatPrecision | undefined;
21
+ /**
22
+ * Original app-string source (e.g. `float'7e00'`), set by the parser when
23
+ * this float is the result of a `float'...'` app-string. Used by toCDN()
24
+ * to round-trip the literal when `appStrings` is not false.
25
+ */
26
+ ednSource?: string;
21
27
  constructor(value: number, options?: {
22
28
  precision?: FloatPrecision;
23
29
  });
@@ -1,4 +1,4 @@
1
- import { CBOROptions, ToCDNOptions, ToJSOptions, ToHexDumpOptions, ToCBOROptions, CborComments } from '../types';
1
+ import { CBOROptions, ToCDNOptions, ToJSOptions, ToHexDumpOptions, ToCBOROptions, CborComments, DecodeWarning, ParseWarning } from '../types';
2
2
  /** @internal One line of an annotated hex dump. */
3
3
  export interface AnnotatedLine {
4
4
  depth: number;
@@ -30,6 +30,12 @@ export declare abstract class CborItem {
30
30
  * They do not affect CBOR bytes or JS conversion.
31
31
  */
32
32
  comments?: CborComments;
33
+ /**
34
+ * Validity violations detected while decoding or parsing this node.
35
+ * Populated when `strict: false` is set in `FromCBOROptions` or
36
+ * `FromCDNOptions`.
37
+ */
38
+ warnings?: (DecodeWarning | ParseWarning)[];
33
39
  /**
34
40
  * Default options bound by a {@link CBOR} instance factory method.
35
41
  * Per-call options always take precedence.
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../mapEntries-CNxwMt7o.cjs`);exports.CborArray=e.p,exports.CborBigNint=e.c,exports.CborBigUint=e.l,exports.CborByteString=e.g,exports.CborEmbeddedCBOR=e.u,exports.CborFloat=e.v,exports.CborIndefiniteByteString=e.h,exports.CborIndefiniteTextString=e.m,exports.CborItem=e.x,exports.CborMap=e.f,exports.CborNint=e.y,exports.CborSimple=e.d,exports.CborTag=e._,exports.CborTextString=e.o,exports.CborUint=e.b;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../mapEntries-BccT62HT.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.S,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-Da-2HMRf.js";
2
- export { u as CborArray, n as CborBigNint, s as CborBigUint, a as CborByteString, d as CborEmbeddedCBOR, f as CborFloat, o as CborIndefiniteByteString, c as CborIndefiniteTextString, p as CborItem, i as CborMap, m as CborNint, r as CborSimple, e as CborTag, l as CborTextString, t as CborUint };
1
+ import { S as e, _ as t, b as n, c as r, d as i, f as a, g as o, h as s, l as c, m as l, o as u, p as d, u as f, v as p, y as m } from "../mapEntries-ZR8QJ0Yj.js";
2
+ export { d as CborArray, r as CborBigNint, c as CborBigUint, o as CborByteString, f as CborEmbeddedCBOR, p as CborFloat, s as CborIndefiniteByteString, l as CborIndefiniteTextString, e as CborItem, a as CborMap, m as CborNint, i as CborSimple, t as CborTag, u as CborTextString, n as CborUint };
@@ -1,4 +1,4 @@
1
- import { CborComments, ToCDNOptions } from '../types';
1
+ import { CborComment, CborComments, ToCDNOptions } from '../types';
2
2
  /** Resolve indent option to a string, or null for single-line output. */
3
3
  export declare function resolveIndent(options: ToCDNOptions | undefined): string | null;
4
4
  /** Build the indent prefix for a given depth. */
@@ -8,9 +8,22 @@ export interface Commented {
8
8
  }
9
9
  export declare function hasPreservedComments(item: Commented): boolean;
10
10
  export declare function hasContainerLayoutComments(item: Commented): boolean;
11
- export declare function formatLeadingComments(item: Commented, indent: string): string[];
12
- export declare function formatTrailingComments(item: Commented): string;
13
- export declare function formatDanglingComments(item: Commented, indent: string): string[];
11
+ /**
12
+ * Convert a single comment's text to the requested marker style.
13
+ *
14
+ * Conversion table:
15
+ * c-style : `#` → `//`, `/ … /` → `/* … *\/`
16
+ * cdn-style: `//` → `#`, `/* … *\/` → `/ … /`
17
+ *
18
+ * Special case for cdn-style: when the inner content of `/* … *\/` starts
19
+ * with `*` or `/` the result would look like `/*…` or `//…` — a different
20
+ * comment form. A single space is inserted after the opening `/` to prevent
21
+ * this (e.g. `/**…*\/` → `/ *…/`).
22
+ */
23
+ export declare function convertCommentText(comment: CborComment, style: 'c-style' | 'cdn-style' | undefined): string;
24
+ export declare function formatLeadingComments(item: Commented, indent: string, style?: 'c-style' | 'cdn-style' | undefined): string[];
25
+ export declare function formatTrailingComments(item: Commented, style?: 'c-style' | 'cdn-style' | undefined): string;
26
+ export declare function formatDanglingComments(item: Commented, indent: string, style?: 'c-style' | 'cdn-style' | undefined): string[];
14
27
  /**
15
28
  * Resolve separator options into concrete strings.
16
29
  *
@@ -0,0 +1,22 @@
1
+ import { CborExtension } from '../../extensions/types';
2
+ export declare function hexToBytes(hex: string): Uint8Array;
3
+ /** Decode an h]-prefixed input: hex bytes → UTF-8 string (may contain control chars). */
4
+ export declare function decodeInput(raw: string): string;
5
+ /**
6
+ * Minimal RFC 4180 CSV parser.
7
+ * Returns rows as [op, input, output] triples; comment rows (op starts with #)
8
+ * and the header row are excluded.
9
+ */
10
+ export declare function parseCSV(text: string): [string, string, string][];
11
+ /**
12
+ * Register Vitest tests for one CSV file.
13
+ *
14
+ * @param text - Raw CSV content (already read from disk).
15
+ * @param knownSkip - Map of test label → reason; matching tests are skipped.
16
+ * @param strictNegative - When true (default), a `-` test whose output field
17
+ * cannot be parsed fails rather than passes silently.
18
+ * Set to false only when the corpus is known to include
19
+ * intentionally unparseable output values (corpus-conflict
20
+ * cases should be listed in knownSkip instead).
21
+ */
22
+ export declare function registerTests(text: string, knownSkip?: Map<string, string>, strictNegative?: boolean, extensions?: CborExtension[]): void;
@@ -4,7 +4,7 @@
4
4
  * Used by parser.ts for parsing and by CborTextString serialization to collect
5
5
  * source offsets after parseCDN() has already validated embedded CDN.
6
6
  */
7
- export type TokenType = 'INTEGER' | 'FLOAT' | 'TSTR' | 'SQSTR' | 'RAWSTRING' | 'BYTES_HEX' | 'BYTES_HEX_ELIDED' | 'BYTES_B64' | 'BYTES_B32' | 'BYTES_H32' | 'APP_STRING' | 'APP_SEQUENCE' | 'EMPTY_INDEF_BYTES' | 'EMPTY_INDEF_TEXT' | 'TRUE' | 'FALSE' | 'NULL' | 'UNDEFINED' | 'SIMPLE' | 'LBRACKET' | 'RBRACKET' | 'LBRACE' | 'RBRACE' | 'LPAREN' | 'RPAREN' | 'COLON' | 'COMMA' | 'PLUS' | 'UNDERSCORE' | 'ENCODING_INDICATOR' | 'LT_LT' | 'GT_GT' | 'ELLIPSIS' | 'EOF';
7
+ export type TokenType = 'INTEGER' | 'FLOAT' | 'TSTR' | 'SQSTR' | 'RAWSTRING' | 'BYTES_HEX' | 'BYTES_HEX_ELIDED' | 'BYTES_B64' | 'APP_STRING' | 'APP_SEQUENCE' | 'EMPTY_INDEF_BYTES' | 'EMPTY_INDEF_TEXT' | 'TRUE' | 'FALSE' | 'NULL' | 'UNDEFINED' | 'SIMPLE' | 'LBRACKET' | 'RBRACKET' | 'LBRACE' | 'RBRACE' | 'LPAREN' | 'RPAREN' | 'COLON' | 'COMMA' | 'PLUS' | 'UNDERSCORE' | 'ENCODING_INDICATOR' | 'LT_LT' | 'GT_GT' | 'ELLIPSIS' | 'EOF';
8
8
  export interface Token {
9
9
  type: TokenType;
10
10
  /** Processed value: decoded string content, raw number text, raw byte content, etc. */
@@ -42,18 +42,26 @@ export declare class Tokenizer {
42
42
  private _lastConsumedEndOffset;
43
43
  /** Comments encountered while scanning, appended in source order. */
44
44
  readonly comments: EdnComment[];
45
+ /**
46
+ * When set, non-standard-but-JS-valid escape sequences are accepted instead
47
+ * of throwing. The callback receives a message and the position of the `\`
48
+ * (offset, line, column) so the parser can forward it as a ParseWarning.
49
+ */
50
+ onEscapeWarning?: (msg: string, offset: number, line: number, col: number) => void;
45
51
  constructor(input: string, options?: TokenizerOptions);
46
52
  peek(): Token;
47
53
  consume(): Token;
48
54
  /** Character offset just past the last character of the most recently consumed token. */
49
55
  get lastEndOffset(): number;
56
+ /** The full source text supplied to this tokenizer. */
57
+ get source(): string;
50
58
  private _ch;
51
59
  private _eof;
52
60
  private _advance;
53
61
  private _fail;
54
62
  private _skipWS;
55
63
  /**
56
- * Skip a comment in a quoted byte string literal (h'', b32'', h32'').
64
+ * Skip a comment in a quoted byte string literal (h'', b64'').
57
65
  * Returns true if a comment was consumed, false if the current char is not a
58
66
  * comment start. `quote` is the closing delimiter character.
59
67
  *
@@ -61,7 +69,16 @@ export declare class Tokenizer {
61
69
  */
62
70
  private _skipByteStringComment;
63
71
  /**
64
- * Skip a comment in a raw byte string (h``, b32``, h32``).
72
+ * Validate a `\uXXXX` or `\u{N}` escape inside a hex-string comment.
73
+ *
74
+ * Called immediately after the `u` character has been consumed. Rejects
75
+ * lone surrogates and invalid surrogate pairs; tolerates truncated/
76
+ * non-hex sequences (comments are informational, but surrogates are
77
+ * always illegal).
78
+ */
79
+ private _validateHexCommentUnicodeEscape;
80
+ /**
81
+ * Skip a comment in a raw byte string (h``, b64``).
65
82
  * Called with `i` pointing at the comment-start character.
66
83
  * Returns the index after the comment, or -1 if no comment was found.
67
84
  *
@@ -80,13 +97,13 @@ export declare class Tokenizer {
80
97
  * - Literal LF (U+000A) is allowed; all other C0 controls and U+007F are rejected.
81
98
  * - Literal CR (U+000D) is silently stripped (source-level CRLF normalisation).
82
99
  * - Only spec-defined escape sequences are accepted; `\q` etc. throw SyntaxError.
83
- * - `\/` is valid in both single- and double-quoted strings.
84
- * - `\\` (backslash) is always a valid escape.
100
+ * - `\/` is valid only in double-quoted strings (not in escapable-s, §5.1).
101
+ * - `\\` (backslash) is valid in both single- and double-quoted strings.
85
102
  * - `\uXXXX` for a high surrogate must be immediately followed by `\uXXXX` for
86
103
  * the corresponding low surrogate; lone surrogates are rejected.
87
104
  * - `\u{N}` … `\u{10FFFF}` extended syntax is supported; surrogates are rejected.
88
105
  * - In single-quoted strings, `\u` escapes to printable ASCII (U+0020–U+007E)
89
- * are forbidden (hexchar-s restriction, draft §2.5.2 / §5.1).
106
+ * are forbidden (hexchar-s restriction, draft-25 §5.1).
90
107
  */
91
108
  private _readStringContent;
92
109
  /**
@@ -101,9 +118,8 @@ export declare class Tokenizer {
101
118
  * which is then decoded into the corresponding non-BMP code point.
102
119
  *
103
120
  * In single-quoted strings (`quote === "'"`), `\u` escapes that resolve to
104
- * printable ASCII (U+0020–U+007E) are rejected per draft §2.5.2 / §5.1
105
- * hexchar-s, except for backslash (U+005C) and single-quote (U+0027), which
106
- * require escaping and cannot be written literally.
121
+ * printable ASCII (U+0020–U+007E) are rejected per draft-25 §5.1 hexchar-s.
122
+ * Use `\\` for backslash (U+005C) and `\'` for the single-quote delimiter.
107
123
  */
108
124
  private _readUnicodeEscape;
109
125
  /**
@@ -142,13 +158,6 @@ export declare class Tokenizer {
142
158
  * Returns the stripped base64 string.
143
159
  */
144
160
  private _processRawB64Content;
145
- /**
146
- * Post-process raw base32/base32hex content from `b32``…``\` / `h32``…``\` raw strings.
147
- *
148
- * Supports all comment forms (§2.2): `/ ... /`, `/*...*\/`, `//`, `#`.
149
- * HT is still forbidden (rawchars excludes %x09).
150
- */
151
- private _processRawB32Content;
152
161
  /**
153
162
  * Read raw byte-string content between `quote` chars (b64 / b64url).
154
163
  *
@@ -156,12 +165,6 @@ export declare class Tokenizer {
156
165
  * `/` is NOT treated as a comment delimiter because it is a valid base64 character.
157
166
  */
158
167
  private _readByteContent;
159
- /**
160
- * Read base32 / base32hex byte-string content (`b32'...'` / `h32'...'`).
161
- *
162
- * Supports all comment forms (§2.2): `/ ... /`, `/*...*\/`, `//`, `#`.
163
- */
164
- private _readB32Content;
165
168
  /**
166
169
  * Read hex byte-string content, recognising `...` ellipsis sequences (§4.2).
167
170
  *
@@ -0,0 +1,5 @@
1
+ import { CborExtension } from './types';
2
+ /** RFC 4648 §6 Base32 (A–Z 2–7) app-string extension. */
3
+ export declare const b32: CborExtension;
4
+ /** RFC 4648 §7 Base32Hex (0–9 A–V) app-string extension. */
5
+ export declare const h32: CborExtension;
@@ -19,16 +19,7 @@ import { EncodingWidth } from '../cbor/encode';
19
19
  * used so that the float64 value is faithfully represented.
20
20
  */
21
21
  export declare function epochToRfc3339(epochSeconds: number): string;
22
- /**
23
- * Parse an RFC 3339 string and produce the appropriate epoch CborItem subclass.
24
- * Integer seconds → CborEpochDtExtUint or CborEpochDtExtNint.
25
- * Fractional seconds → CborEpochDtExtFloat.
26
- *
27
- * Fractional seconds are extracted from the string directly (via parseFloat)
28
- * before passing the remainder to Date.parse, so sub-millisecond precision
29
- * is preserved rather than being rounded to the nearest millisecond.
30
- */
31
- export declare function parseDtAppString(str: string): CborEpochDtExtUint | CborEpochDtExtNint | CborEpochDtExtFloat;
22
+ export declare function parseDtAppString(str: string, onError?: (msg: string) => void): CborEpochDtExtUint | CborEpochDtExtNint | CborEpochDtExtFloat;
32
23
  export declare const PREFIX_DT = "dt";
33
24
  export declare const PREFIX_DT_TAGGED = "DT";
34
25
  export declare const TAG_EPOCH = 1n;
@@ -0,0 +1,7 @@
1
+ import { CborExtension } from './types';
2
+ /**
3
+ * Extension object for `float'...'` / `float<<...>>`.
4
+ * Pass to `parseCDN(..., { extensions: [float] })`.
5
+ */
6
+ export declare const float: CborExtension;
7
+ export default float;
@@ -0,0 +1,7 @@
1
+ import { CborExtension } from './types';
2
+ /**
3
+ * Extension object for `same<<...>>`.
4
+ * Pass to `parseCDN(..., { extensions: [same] })`.
5
+ */
6
+ export declare const same: CborExtension;
7
+ export default same;
@@ -1,5 +1,5 @@
1
1
  import { CborItem } from '../ast/CborItem';
2
- import { FromJSOptions } from '../types';
2
+ import { FromCBOROptions, FromJSOptions } from '../types';
3
3
  /**
4
4
  * Plugin that extends EDN parsing, CBOR decoding, and `fromJS()` for specific
5
5
  * application-string prefixes or CBOR tag numbers.
@@ -33,20 +33,42 @@ export interface CborExtension {
33
33
  * Parse an app-string literal: `prefix'content'` or `prefix"content"`.
34
34
  * Receives the matched `prefix` and the decoded string `content`.
35
35
  * Throw `SyntaxError` to report invalid content.
36
+ *
37
+ * The CDN parser always passes an `onError` callback. Extensions may call
38
+ * `onError(msg)` instead of throwing to emit a recoverable violation; the
39
+ * callback emits a warning and, in strict mode, also throws. Extensions
40
+ * that ignore `onError` and throw directly always hard-fail regardless of
41
+ * the `strict` setting.
36
42
  */
37
- parseAppString?(prefix: string, content: string): CborItem;
43
+ parseAppString?(prefix: string, content: string, onError?: (msg: string) => void): CborItem;
38
44
  /**
39
45
  * Parse an app-sequence literal: `prefix<<item, ...>>`.
40
46
  * Receives the matched `prefix` and the array of parsed CBOR values.
41
47
  * If omitted, the `<<...>>` form is rejected with a `SyntaxError`.
48
+ * The `onError` callback follows the same contract as in `parseAppString`.
42
49
  */
43
- parseAppSequence?(prefix: string, items: CborItem[]): CborItem;
50
+ parseAppSequence?(prefix: string, items: CborItem[], onError?: (msg: string) => void): CborItem;
51
+ /**
52
+ * When `true`, the CDN parser wraps the result of `parseAppSequence` in a
53
+ * `CborAppSeqResult` so that `toCDN()` round-trips the original
54
+ * `prefix<<...>>` notation when `appStrings !== false`.
55
+ *
56
+ * Extensions whose result is already a subclass that handles source
57
+ * preservation itself (e.g. `CborFloat` via its `ednSource` property) should
58
+ * leave this unset.
59
+ */
60
+ readonly preserveAppSeqSource?: boolean;
44
61
  /**
45
62
  * Called when a `CborTag` is encountered during CBOR decode (`fromCBOR`)
46
63
  * or EDN integer-tag parsing (`fromCDN`).
47
64
  * Return `undefined` to fall back to the default `CborTag` representation.
65
+ *
66
+ * `options` is supplied only from the binary CBOR decoder; it is `undefined`
67
+ * when called from the CDN parser. Extensions that perform nested CBOR
68
+ * decoding (e.g. tag 24) should forward these options to propagate
69
+ * `strict`, `onWarning`, and `silent` into the inner decode.
48
70
  */
49
- parseTag?(tag: bigint, value: CborItem): CborItem | undefined;
71
+ parseTag?(tag: bigint, value: CborItem, options?: FromCBOROptions): CborItem | undefined;
50
72
  /**
51
73
  * Called during `fromJS()` for every value before the default conversion
52
74
  * logic. Return `undefined` to fall through to the default behaviour.
package/dist/index.cjs CHANGED
@@ -1,3 +1,6 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./mapEntries-CNxwMt7o.cjs`);var t=class t{static OMIT=e.C;static TAG=e.w;static Tag=e.E;static Simple=e.S;static MapEntries=e.t;static dt_as_Date=e.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,n){let r=t.fromCBOR(e,this.#t(n));return r._defaults=this.#e,r}fromCDN(e,n){let r=t.fromCDN(e,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,n){let r=t.fromJS(e,this.#t(n));return r._defaults=this.#e,r}fromHexDump(e,n){let r=t.fromHexDump(e,this.#t(n));return r._defaults=this.#e,r}decode(e,n){return t.decode(e,this.#t(n))}encode(e,n){return t.encode(e,this.#t(n))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,n){return t.cborToCdn(e,this.#t(n))}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,n){return t.cdnToCbor(e,this.#t(n))}parse(e,n){if(typeof n==`function`){let r=this.#t({reviver:n});return t.fromCDN(e,r).toJS(r)}let r=this.#t(n);return t.fromCDN(e,r).toJS(r)}stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i={...this.#e};return n===null?i.replacer=void 0:(typeof n==`function`||Array.isArray(n))&&(i.replacer=n),r!==void 0&&(i.indent=a(r)),t.stringify(e,i)}return t.stringify(e,this.#t(n??void 0))}format(e,n){return t.format(e,this.#t(n))}static fromCBOR(t,n){return e.i(t,n)}static fromCDN(t,n){return e.s(t,n)}static fromEDN(e,n){return t.fromCDN(e,n)}static fromJS(t,n){return e.r(t,n)}static fromHexDump(t,r){let i=[],a=n(t).trim().split(/\s+/).filter(Boolean);for(let e of a){if(!/^[0-9A-Fa-f]{2}$/.test(e))throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);i.push(parseInt(e,16))}return e.i(new Uint8Array(i),r)}static decode(e,n){return t.fromCBOR(e,n).toJS(n)}static encode(e,n){return t.fromJS(e,n).toCBOR(n)}static cborToCdn(e,n){return t.fromCBOR(e,n).toCDN(n)}static cborToCborEdn(e,n){return t.cborToCdn(e,n)}static cdnToCbor(e,n){return t.fromCDN(e,n).toCBOR(n)}static cborEdnToCbor(e,n){return t.cdnToCbor(e,n)}static parse(e,n){return typeof n==`function`?t.fromCDN(e).toJS({reviver:n}):t.fromCDN(e,n).toJS(n)}static stringify(t,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i=typeof n==`function`||Array.isArray(n)?n:void 0,o=a(r);if(i){let n=e.n(t,i);return n===void 0||n===e.C?void 0:e.r(n).toCDN(o===void 0?void 0:{indent:o})}return e.r(t).toCDN(o===void 0?void 0:{indent:o})}let i=n;if(i?.replacer){let n=e.n(t,i.replacer,i.extensions,i.undefinedOmits);if(n===void 0||n===e.C)return;let{replacer:r,...a}=i;return e.r(n,Object.keys(a).length>0?a:void 0).toCDN(i)}return e.r(t,i).toCDN(i)}static format(e,n){return t.fromCDN(e,n).toCDN(n)}};function n(e){let t=``,n=0;for(;n<e.length;){let a=e[n],o=e[n+1]??``;if(a===`-`&&o===`-`){n=r(e,n+2),t+=` `;continue}if(a===`#`){n=r(e,n+1),t+=` `;continue}if(a===`/`&&o===`/`){n=r(e,n+2),t+=` `;continue}if(a===`/`&&o===`*`){let r=e.indexOf(`*/`,n+2);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=i(e.slice(n,r+2)),n=r+2;continue}if(a===`/`){let r=e.indexOf(`/`,n+1);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=i(e.slice(n,r+1)),n=r+1;continue}t+=a,n++}return t}function r(e,t){let n=e.indexOf(`
2
- `,t);return n<0?e.length:n}function i(e){return e.replace(/[^\r\n]/g,` `)}function a(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.CBOR=t,exports.default=t,exports.CBOR_OMIT=e.C,exports.CBOR_TAG=e.w,exports.MapEntries=e.t,exports.Null=e.T,exports.Simple=e.S,exports.Tag=e.E,exports.Undefined=e.D,exports.dt_as_Date=e.a;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./mapEntries-BccT62HT.cjs");function t(e){let t=``,n=0;for(;n<e.length;){let r=e[n];if(r===` `||r===`
2
+ `||r===`\r`){n++;continue}if(r===`#`){for(;n<e.length&&e[n]!==`
3
+ `;)n++;continue}if(r===`/`){let t=e[n+1]??``;if(t===`/`){for(;n<e.length&&e[n]!==`
4
+ `;)n++;continue}if(t===`*`){for(n+=2;n<e.length&&!(e[n]===`*`&&(e[n+1]??``)===`/`);)n++;if(n>=e.length)throw SyntaxError(`unterminated block comment`);n+=2;continue}for(n++;n<e.length&&e[n]!==`/`;)n++;if(n>=e.length)throw SyntaxError(`unterminated block comment`);n++;continue}t+=r,n++}return t}var n=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,r=`0123456789ABCDEFGHIJKLMNOPQRSTUV`;function i(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===61;)t--;return e.slice(0,t)}function a(e,t,n){let r=i(e).toUpperCase(),a=r.length%8;if(a===1||a===3||a===6)throw SyntaxError(`invalid base32 length: ${r.length} characters`);let o=new Uint8Array(128).fill(255);for(let e=0;e<t.length;e++)o[t.charCodeAt(e)]=e;let s=new Uint8Array(Math.floor(r.length*5/8)),c=0,l=0,u=0;for(let e of r){let t=e.charCodeAt(0),n=t<128?o[t]:255;if(n===255)throw SyntaxError(`invalid character in byte string: ${JSON.stringify(e)}`);c=c<<5|n,l+=5,l>=8&&(l-=8,s[u++]=c>>l&255)}if(l>0&&c&(1<<l)-1){let e=`non-zero trailing bits in base32 input`;if(n)n(e);else throw SyntaxError(e)}return s}var o={appStringPrefixes:[`b32`],parseAppString(r,i,o){return new e.g(a(t(i),n,o),{ednEncoding:`base32`})}},s={appStringPrefixes:[`h32`],parseAppString(n,i,o){return new e.g(a(t(i),r,o),{ednEncoding:`base32hex`})}},c=typeof Uint8Array.fromHex==`function`?e=>Uint8Array.fromHex(e):e=>{let t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.slice(n,n+2),16);return t},l=class extends e.v{_bits;constructor(t){super(e.x(t),{precision:`half`}),this._bits=t&65535}_toCBOR(){return new Uint8Array([249,this._bits>>8&255,this._bits&255])}},u=class extends e.v{_raw;constructor(e){super(new DataView(e.buffer,e.byteOffset).getFloat32(0,!1),{precision:`single`}),this._raw=e.slice()}_toCBOR(){let e=new Uint8Array(5);return e[0]=250,e.set(this._raw,1),e}},d=class extends e.v{_raw;constructor(e){super(new DataView(e.buffer,e.byteOffset).getFloat64(0,!1),{precision:`double`}),this._raw=e.slice()}_toCBOR(){let e=new Uint8Array(9);return e[0]=251,e.set(this._raw,1),e}};function f(e){if(e.length===2)return new l(e[0]<<8|e[1]);if(e.length===4)return new u(e);if(e.length===8)return new d(e);throw SyntaxError(`float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${e.length} bytes`)}var p={appStringPrefixes:[`float`],parseAppString(e,n){let r=t(n);if(!/^[0-9a-fA-F]*$/.test(r))throw SyntaxError(`float'...' contains non-hex characters`);if(r.length%2!=0)throw SyntaxError(`float'...' hex content has odd length (${r.length} digits)`);return f(c(r))},parseAppSequence(t,n,r){if(n.length===0)throw SyntaxError(`float<<...>> requires exactly one byte-string item`);if(n.length>1){let e=`float<<...>> expects 1 item; got ${n.length} — using first`;if(r)r(e);else throw SyntaxError(e)}if(!(n[0]instanceof e.g))throw SyntaxError(`float<<...>> item must be a byte string`);return f(n[0].value)}};function m(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var h={appStringPrefixes:[`same`],preserveAppSeqSource:!0,parseAppSequence(e,t,n){if(t.length===0)throw SyntaxError(`same<<...>> requires at least one item`);let r=t[0],i=r.toCBOR();for(let e=1;e<t.length;e++)if(!m(i,t[e].toCBOR())){let t=`same<<...>>: item ${e} produces different CBOR bytes than item 0`;if(n)n(t);else throw SyntaxError(t)}return r}},g=class t{static OMIT=e.w;static TAG=e.T;static Tag=e.D;static Simple=e.C;static MapEntries=e.t;static dt_as_Date=e.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,n){let r=t.fromCBOR(e,this.#t(n));return r._defaults=this.#e,r}fromCDN(e,n){let r=t.fromCDN(e,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,n){let r=t.fromJS(e,this.#t(n));return r._defaults=this.#e,r}fromHexDump(e,n){let r=t.fromHexDump(e,this.#t(n));return r._defaults=this.#e,r}decode(e,n){return t.decode(e,this.#t(n))}encode(e,n){return t.encode(e,this.#t(n))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,n){return t.cborToCdn(e,this.#t(n))}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,n){return t.cdnToCbor(e,this.#t(n))}parse(e,n){if(typeof n==`function`){let r=this.#t({reviver:n});return t.fromCDN(e,r).toJS(r)}let r=this.#t(n);return t.fromCDN(e,r).toJS(r)}stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i={...this.#e};return n===null?i.replacer=void 0:(typeof n==`function`||Array.isArray(n))&&(i.replacer=n),r!==void 0&&(i.indent=b(r)),t.stringify(e,i)}return t.stringify(e,this.#t(n??void 0))}format(e,n){return t.format(e,this.#t(n))}static fromCBOR(t,n){return e.i(t,n)}static fromCDN(t,n){return e.s(t,n)}static fromEDN(e,n){return t.fromCDN(e,n)}static fromJS(t,n){return e.r(t,n)}static fromHexDump(t,n){let r=[],i=_(t).trim().split(/\s+/).filter(Boolean);for(let e of i){if(!/^[0-9A-Fa-f]{2}$/.test(e))throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);r.push(parseInt(e,16))}return e.i(new Uint8Array(r),n)}static decode(e,n){return t.fromCBOR(e,n).toJS(n)}static encode(e,n){return t.fromJS(e,n).toCBOR(n)}static cborToCdn(e,n){return t.fromCBOR(e,n).toCDN(n)}static cborToCborEdn(e,n){return t.cborToCdn(e,n)}static cdnToCbor(e,n){return t.fromCDN(e,n).toCBOR(n)}static cborEdnToCbor(e,n){return t.cdnToCbor(e,n)}static parse(e,n){return typeof n==`function`?t.fromCDN(e).toJS({reviver:n}):t.fromCDN(e,n).toJS(n)}static stringify(t,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i=typeof n==`function`||Array.isArray(n)?n:void 0,a=b(r);if(i){let n=e.n(t,i);return n===void 0||n===e.w?void 0:e.r(n).toCDN(a===void 0?void 0:{indent:a})}return e.r(t).toCDN(a===void 0?void 0:{indent:a})}let i=n;if(i?.replacer){let n=e.n(t,i.replacer,i.extensions,i.undefinedOmits);if(n===void 0||n===e.w)return;let{replacer:r,...a}=i;return e.r(n,Object.keys(a).length>0?a:void 0).toCDN(i)}return e.r(t,i).toCDN(i)}static format(e,n){return t.fromCDN(e,n).toCDN(n)}};function _(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=v(e,n+2),t+=` `;continue}if(r===`#`){n=v(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=v(e,n+2),t+=` `;continue}if(r===`/`&&i===`*`){let r=e.indexOf(`*/`,n+2);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=y(e.slice(n,r+2)),n=r+2;continue}if(r===`/`){let r=e.indexOf(`/`,n+1);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=y(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function v(e,t){let n=e.indexOf(`
5
+ `,t);return n<0?e.length:n}function y(e){return e.replace(/[^\r\n]/g,` `)}function b(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.CBOR=g,exports.default=g,exports.CBOR_OMIT=e.w,exports.CBOR_TAG=e.T,exports.MapEntries=e.t,exports.Null=e.E,exports.Simple=e.C,exports.Tag=e.D,exports.Undefined=e.O,exports.b32=o,exports.dt_as_Date=e.a,exports.float=p,exports.h32=s,exports.same=h;
3
6
  //# sourceMappingURL=index.cjs.map