@cbortech/cbor 0.26.7 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +120 -47
- package/README.md +121 -48
- package/dist/ast/CborAppSeqResult.d.ts +22 -0
- package/dist/ast/CborByteString.d.ts +27 -0
- package/dist/ast/CborEmbeddedCBOR.d.ts +1 -1
- package/dist/ast/CborFloat.d.ts +1 -1
- package/dist/ast/CborIndefiniteByteString.d.ts +24 -0
- package/dist/ast/CborIndefiniteTextString.d.ts +16 -0
- package/dist/ast/CborItem.d.ts +44 -4
- package/dist/ast/CborTag.d.ts +27 -0
- package/dist/ast/CborTextString.d.ts +18 -1
- package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +2 -2
- package/dist/cddl/index.cjs +1 -1
- package/dist/cddl/index.js +1 -1
- package/dist/cdn/index.cjs +2 -2
- package/dist/cdn/index.cjs.map +1 -1
- package/dist/cdn/index.d.ts +2 -0
- package/dist/cdn/index.js +15 -15
- package/dist/cdn/index.js.map +1 -1
- package/dist/cdn/serialize-utils.d.ts +241 -21
- package/dist/cdn/tokenizer.d.ts +12 -11
- package/dist/extensions/builtins.d.ts +5 -5
- package/dist/extensions/cri.d.ts +2 -2
- package/dist/extensions/ip.d.ts +1 -1
- package/dist/extensions/types.d.ts +4 -4
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +158 -158
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-C1f7G0AM.cjs +13 -0
- package/dist/mapEntries-C1f7G0AM.cjs.map +1 -0
- package/dist/{mapEntries-DxrDre2P.js → mapEntries-CvLdiN0h.js} +1479 -1558
- package/dist/mapEntries-CvLdiN0h.js.map +1 -0
- package/dist/{schema-Bofmsptw.js → schema-CNfrVRYp.js} +294 -294
- package/dist/{schema-Bofmsptw.js.map → schema-CNfrVRYp.js.map} +1 -1
- package/dist/schema-iXpYtKQl.cjs +63 -0
- package/dist/{schema-t_bdPk8_.cjs.map → schema-iXpYtKQl.cjs.map} +1 -1
- package/dist/{tokenizer-CeuixxXi.js → serialize-utils-BuIZPaUc.js} +634 -30
- package/dist/serialize-utils-BuIZPaUc.js.map +1 -0
- package/dist/serialize-utils-CjTqQivB.cjs +37 -0
- package/dist/serialize-utils-CjTqQivB.cjs.map +1 -0
- package/dist/types.d.ts +248 -64
- package/dist/utils/base64.d.ts +1 -1
- package/dist/utils/hexfloat.d.ts +1 -1
- package/dist/utils/strip-comments.d.ts +1 -1
- package/package.json +8 -7
- package/dist/mapEntries-D2NyeCX3.cjs +0 -17
- package/dist/mapEntries-D2NyeCX3.cjs.map +0 -1
- package/dist/mapEntries-DxrDre2P.js.map +0 -1
- package/dist/schema-t_bdPk8_.cjs +0 -63
- package/dist/tokenizer-CeuixxXi.js.map +0 -1
- package/dist/tokenizer-EciPlN0n.cjs +0 -30
- package/dist/tokenizer-EciPlN0n.cjs.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export interface ToJSOptions {
|
|
|
43
43
|
* - `'object'`: always `Record<string, unknown>` — non-string keys are
|
|
44
44
|
* converted via `String()`. Duplicate keys are overwritten (last wins).
|
|
45
45
|
* - `'entries'`: always `MapEntries` (a typed `Array` subclass) — preserves all
|
|
46
|
-
* entries including duplicate keys (§2.
|
|
46
|
+
* entries including duplicate keys (§2.4.2 of draft-ietf-cbor-edn-literals-27).
|
|
47
47
|
* `fromJS()` recognises `MapEntries` instances and converts them back to `CborMap`.
|
|
48
48
|
* @default 'auto'
|
|
49
49
|
*/
|
|
@@ -165,7 +165,7 @@ export interface FromCBOROptions {
|
|
|
165
165
|
*/
|
|
166
166
|
extensions?: CborExtension[];
|
|
167
167
|
/**
|
|
168
|
-
* Override the default set of bundled
|
|
168
|
+
* Override the default set of bundled app-extensions
|
|
169
169
|
* (`dt`, `ip`, `cri`, `t1`, `b1`, `ilbs`, `ilts`, `float`).
|
|
170
170
|
*
|
|
171
171
|
* - omitted (default): use the standard bundled set.
|
|
@@ -173,13 +173,13 @@ export interface FromCBOROptions {
|
|
|
173
173
|
* - `false`: disable all of them.
|
|
174
174
|
*
|
|
175
175
|
* `bignum` (tags 2/3) and embedded-CBOR (tag 24) support are core RFC 8949
|
|
176
|
-
* representation features, not
|
|
177
|
-
*
|
|
176
|
+
* representation features, not app-extensions, and are always active
|
|
177
|
+
* regardless of this option.
|
|
178
178
|
*
|
|
179
|
-
* `dt`, `ip`, `t1`, and `b1` are mandatory-to-implement per §
|
|
180
|
-
* draft-ietf-cbor-edn-literals-
|
|
179
|
+
* `dt`, `ip`, `t1`, and `b1` are mandatory-to-implement per §3 of
|
|
180
|
+
* draft-ietf-cbor-edn-literals-27; disabling them produces a decoder that
|
|
181
181
|
* no longer conforms to that recommendation. This is intended for
|
|
182
|
-
* allowlisting scenarios (see §
|
|
182
|
+
* allowlisting scenarios (see §8 Security considerations of the same
|
|
183
183
|
* draft) where an application wants explicit control over which
|
|
184
184
|
* extensions it accepts.
|
|
185
185
|
*/
|
|
@@ -254,7 +254,7 @@ export interface FromHexDumpOptions {
|
|
|
254
254
|
*/
|
|
255
255
|
extensions?: CborExtension[];
|
|
256
256
|
/**
|
|
257
|
-
* Override the default set of bundled
|
|
257
|
+
* Override the default set of bundled app-extensions.
|
|
258
258
|
* Mirrors `FromCBOROptions.builtinExtensions`.
|
|
259
259
|
*/
|
|
260
260
|
builtinExtensions?: CborExtension[] | false;
|
|
@@ -332,7 +332,7 @@ export interface FromCDNOptions {
|
|
|
332
332
|
*/
|
|
333
333
|
extensions?: CborExtension[];
|
|
334
334
|
/**
|
|
335
|
-
* Override the default set of bundled
|
|
335
|
+
* Override the default set of bundled app-extensions
|
|
336
336
|
* (`dt`, `ip`, `cri`, `t1`, `b1`, `ilbs`, `ilts`, `float`).
|
|
337
337
|
*
|
|
338
338
|
* - omitted (default): use the standard bundled set.
|
|
@@ -340,10 +340,10 @@ export interface FromCDNOptions {
|
|
|
340
340
|
* - `false`: disable all of them; app-string literals using their
|
|
341
341
|
* prefixes then fall through to `unresolvedExtension` handling.
|
|
342
342
|
*
|
|
343
|
-
* `dt`, `ip`, `t1`, and `b1` are mandatory-to-implement per §
|
|
344
|
-
* draft-ietf-cbor-edn-literals-
|
|
343
|
+
* `dt`, `ip`, `t1`, and `b1` are mandatory-to-implement per §3 of
|
|
344
|
+
* draft-ietf-cbor-edn-literals-27; disabling them produces a parser that
|
|
345
345
|
* no longer conforms to that recommendation. This is intended for
|
|
346
|
-
* allowlisting scenarios (see §
|
|
346
|
+
* allowlisting scenarios (see §8 Security considerations of the same
|
|
347
347
|
* draft) where an application wants explicit control over which
|
|
348
348
|
* extensions it accepts from untrusted CDN input.
|
|
349
349
|
*
|
|
@@ -354,8 +354,8 @@ export interface FromCDNOptions {
|
|
|
354
354
|
*/
|
|
355
355
|
builtinExtensions?: CborExtension[] | false;
|
|
356
356
|
/**
|
|
357
|
-
* How to handle unrecognised
|
|
358
|
-
* (§
|
|
357
|
+
* How to handle unrecognised app-extension identifiers
|
|
358
|
+
* (§5.1 of draft-ietf-cbor-edn-literals-27).
|
|
359
359
|
*
|
|
360
360
|
* - `'cpa999'`: wrap the literal in a `CPA999` tag
|
|
361
361
|
* (`CborUnresolvedAppExt`) instead of failing. The resulting node
|
|
@@ -381,14 +381,28 @@ export interface FromCDNOptions {
|
|
|
381
381
|
*
|
|
382
382
|
* Comments are metadata only: they are ignored by CBOR binary encoding and
|
|
383
383
|
* JavaScript conversion. Use together with `ToCDNOptions.preserveComments`
|
|
384
|
-
* to include them when formatting back to CDN.
|
|
384
|
+
* (or `comments`) to include them when formatting back to CDN.
|
|
385
385
|
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
386
|
+
* Passing `'c-style'`/`'cdn-style'` directly is a deprecated shorthand for
|
|
387
|
+
* `true` plus the equivalent `comments` — still accepted, but prefer
|
|
388
|
+
* `comments` for the output style going forward.
|
|
388
389
|
*
|
|
389
390
|
* @default false
|
|
390
391
|
*/
|
|
391
392
|
preserveComments?: boolean | 'c-style' | 'cdn-style';
|
|
393
|
+
/**
|
|
394
|
+
* Companion to `preserveComments` for a single options object shared with
|
|
395
|
+
* `toCDN()` (as `CBOR.format()` does internally) — see
|
|
396
|
+
* `ToCDNOptions.comments` for what each value means there. On the
|
|
397
|
+
* parse side, only *whether* a style other than `'strip'` was requested
|
|
398
|
+
* matters: comments are captured when `preserveComments` is `true`, or
|
|
399
|
+
* when `comments` is set to anything other than `'strip'`. Left
|
|
400
|
+
* unset alongside an unset/`false` `preserveComments`, nothing is
|
|
401
|
+
* captured.
|
|
402
|
+
*
|
|
403
|
+
* @default undefined
|
|
404
|
+
*/
|
|
405
|
+
comments?: 'strip' | 'c-style' | 'cdn-style';
|
|
392
406
|
/**
|
|
393
407
|
* Shorthand for `ToCDNOptions.preserveAll`, so a single option enables
|
|
394
408
|
* round-tripping through both `fromCDN()` and `toCDN()` (as
|
|
@@ -457,10 +471,10 @@ export interface FromJSOptions {
|
|
|
457
471
|
*/
|
|
458
472
|
extensions?: CborExtension[];
|
|
459
473
|
/**
|
|
460
|
-
* Override the default set of bundled
|
|
474
|
+
* Override the default set of bundled app-extensions.
|
|
461
475
|
* Mirrors `FromCDNOptions.builtinExtensions`. Only affects builtins that
|
|
462
|
-
* implement `fromJS()` / `parseTag()` (none of the bundled
|
|
463
|
-
*
|
|
476
|
+
* implement `fromJS()` / `parseTag()` (none of the bundled app-extensions
|
|
477
|
+
* implement `fromJS()` by default — use `dt_as_Date` via
|
|
464
478
|
* `extensions` for `Date` round-tripping).
|
|
465
479
|
*/
|
|
466
480
|
builtinExtensions?: CborExtension[] | false;
|
|
@@ -527,18 +541,22 @@ export interface ToCDNOptions {
|
|
|
527
541
|
*/
|
|
528
542
|
indent?: number | string;
|
|
529
543
|
/**
|
|
530
|
-
* Master switch that turns on every `preserve*` option below at once
|
|
531
|
-
*
|
|
532
|
-
* `
|
|
533
|
-
* `
|
|
534
|
-
* text (e.g. on save in an
|
|
535
|
-
* whitespace/indentation, plus
|
|
536
|
-
* option overrides.
|
|
544
|
+
* Master switch that turns on every `preserve*` option below at once,
|
|
545
|
+
* except the deprecated `preserveTextString` — `preserveComments`,
|
|
546
|
+
* `preserveByteString`, `preserveRawString`, `preserveConcatenation`,
|
|
547
|
+
* `preserveNumberFormat`, `preserveAppPrefix`, and
|
|
548
|
+
* `preserveBlankLines` — for reformatting CDN text (e.g. on save in an
|
|
549
|
+
* editor) with minimal changes: only whitespace/indentation, plus
|
|
550
|
+
* anything an explicitly-set individual option overrides.
|
|
537
551
|
*
|
|
538
552
|
* An option explicitly set to a value (including `false`) is left as-is;
|
|
539
553
|
* `preserveAll` only fills in the ones left `undefined`. So
|
|
540
554
|
* `{ preserveAll: true, preserveNumberFormat: false }` preserves
|
|
541
|
-
* everything except number literal spelling.
|
|
555
|
+
* everything except number literal spelling. `preserveComments` is filled
|
|
556
|
+
* in with `true` only when `comments` is *also* left unset — an
|
|
557
|
+
* explicit `comments` with no `preserveComments` still normalizes
|
|
558
|
+
* comments to that style under `preserveAll`, instead of being overridden
|
|
559
|
+
* by the verbatim fill-in.
|
|
542
560
|
*
|
|
543
561
|
* When parsing via `CBOR.fromCDN()` separately from `toCDN()` (rather
|
|
544
562
|
* than through `CBOR.format()`, which passes the same options to both),
|
|
@@ -551,24 +569,45 @@ export interface ToCDNOptions {
|
|
|
551
569
|
*/
|
|
552
570
|
preserveAll?: boolean;
|
|
553
571
|
/**
|
|
554
|
-
* Emit comments previously captured by `FromCDNOptions.preserveComments
|
|
572
|
+
* Emit comments previously captured by `FromCDNOptions.preserveComments`,
|
|
573
|
+
* with their original markers kept as-is (no normalization) — takes
|
|
574
|
+
* precedence over `comments` when `true`.
|
|
575
|
+
*
|
|
576
|
+
* - `true`: emit comments verbatim, with whichever marker each one was
|
|
577
|
+
* originally written with.
|
|
578
|
+
* - `false` / omitted: defer to `comments` (see below) — `'strip'` (the
|
|
579
|
+
* default when that's also unset) or unset means no comments are
|
|
580
|
+
* emitted.
|
|
581
|
+
* - `'c-style'` / `'cdn-style'`: deprecated shorthand for `false` plus the
|
|
582
|
+
* equivalent `comments`; still accepted, but prefer setting
|
|
583
|
+
* `comments` directly.
|
|
584
|
+
*
|
|
585
|
+
* Only effective when `indent` enables pretty-printing: single-line
|
|
586
|
+
* output strips all comments regardless, since line comments (`#`, `//`)
|
|
587
|
+
* can only be terminated by a newline.
|
|
588
|
+
*
|
|
589
|
+
* @default false
|
|
590
|
+
*/
|
|
591
|
+
preserveComments?: boolean | 'c-style' | 'cdn-style';
|
|
592
|
+
/**
|
|
593
|
+
* Style to normalize comment markers to when emitting comments previously
|
|
594
|
+
* captured by `FromCDNOptions.preserveComments` — only consulted when
|
|
595
|
+
* `preserveComments` is not `true` (see there).
|
|
555
596
|
*
|
|
556
|
-
* - `
|
|
597
|
+
* - `'strip'` / omitted: don't emit comments at all.
|
|
557
598
|
* - `'c-style'`: emit comments, normalising line comments to `//` and block
|
|
558
599
|
* comments to `/* … *\/`.
|
|
559
600
|
* - `'cdn-style'`: emit comments, normalising line comments to `#` and block
|
|
560
601
|
* comments to `/ … /`. When a `/* … *\/` comment's content contains `/`
|
|
561
602
|
* (which cannot be represented inside `/ … /`), the `/* … *\/` form is
|
|
562
603
|
* kept as-is.
|
|
563
|
-
* - `false` / omitted: strip all comments from the output.
|
|
564
604
|
*
|
|
565
|
-
* Only effective when `indent` enables pretty-printing
|
|
566
|
-
*
|
|
567
|
-
* be terminated by a newline.
|
|
605
|
+
* Only effective when `indent` enables pretty-printing; see
|
|
606
|
+
* `preserveComments`.
|
|
568
607
|
*
|
|
569
|
-
* @default
|
|
608
|
+
* @default 'strip'
|
|
570
609
|
*/
|
|
571
|
-
|
|
610
|
+
comments?: 'strip' | 'c-style' | 'cdn-style';
|
|
572
611
|
/**
|
|
573
612
|
* Re-emit a blank line above an array/map entry (or indefinite-length
|
|
574
613
|
* string chunk) that had one before it anywhere in the parsed CDN source,
|
|
@@ -594,7 +633,7 @@ export interface ToCDNOptions {
|
|
|
594
633
|
* This preserves the spelling and interior layout of non-concatenated
|
|
595
634
|
* `h'...'`, `b64'...'`, `b32'...'`, `h32'...'`, raw-backtick byte strings,
|
|
596
635
|
* and single-quoted byte strings — including a `h'xx...yy'`-family elided
|
|
597
|
-
* literal (§
|
|
636
|
+
* literal (§5.2), whose spelling is kept independently of
|
|
598
637
|
* `preserveConcatenation` when it has no `+` of its own (see that
|
|
599
638
|
* option). Byte strings produced by `+` concatenation are normalised as
|
|
600
639
|
* usual; combine with `preserveConcatenation` to keep both the part
|
|
@@ -651,6 +690,13 @@ export interface ToCDNOptions {
|
|
|
651
690
|
* In single-line output (no `indent`), a spelling that spans multiple
|
|
652
691
|
* lines falls back to normal escaping; single-line spellings are kept.
|
|
653
692
|
*
|
|
693
|
+
* @deprecated Verbatim spelling and `splitCdn` / `splitNewline` reflow
|
|
694
|
+
* are mutually exclusive for a given literal — enabling this option
|
|
695
|
+
* silently defeats both for any non-concatenated double-quoted string.
|
|
696
|
+
* It still works when set explicitly, but no longer participates in
|
|
697
|
+
* `preserveAll` and has been removed from the playground's preserve
|
|
698
|
+
* options.
|
|
699
|
+
*
|
|
654
700
|
* @default false
|
|
655
701
|
*/
|
|
656
702
|
preserveTextString?: boolean;
|
|
@@ -703,16 +749,29 @@ export interface ToCDNOptions {
|
|
|
703
749
|
*/
|
|
704
750
|
sqstr?: 'printable-string' | 'string' | 'none';
|
|
705
751
|
/**
|
|
706
|
-
* Whether to use
|
|
707
|
-
*
|
|
752
|
+
* Whether to use app-prefix notation — app-string (`dt'...'`, `` dt`...` ``)
|
|
753
|
+
* or app-sequence (`dt<<...>>`) — for built-in extensions.
|
|
708
754
|
* - `true`: emit extension notation (`DT'2023-01-01T12:00:00Z'`)
|
|
709
755
|
* - `false`: emit raw CBOR notation (`1(-14159024)`, `52(h'c000022a')`)
|
|
756
|
+
*
|
|
757
|
+
* Named after `app-prefix` (§6.1 of draft-ietf-cbor-edn-literals-27), the
|
|
758
|
+
* identifier both notations are built from — not just the app-string form,
|
|
759
|
+
* despite the old `appStrings` name (`false` also falls back to raw tag
|
|
760
|
+
* notation for a preserved app-sequence spelling; see `preserveAppPrefix`).
|
|
761
|
+
*
|
|
710
762
|
* @default true
|
|
711
763
|
*/
|
|
764
|
+
appPrefix?: boolean;
|
|
765
|
+
/**
|
|
766
|
+
* @deprecated Renamed to `appPrefix` — the old name only described the
|
|
767
|
+
* app-string form even though this option also gates app-sequence
|
|
768
|
+
* (`<<...>>`) notation. Still honoured when `appPrefix` is left unset,
|
|
769
|
+
* but `appPrefix` wins if both are set.
|
|
770
|
+
*/
|
|
712
771
|
appStrings?: boolean;
|
|
713
772
|
/**
|
|
714
|
-
* For built-in extensions that support
|
|
715
|
-
* (`prefix'...'` or `` prefix`...` ``),
|
|
773
|
+
* For built-in extensions that support app-string notation
|
|
774
|
+
* (`prefix'...'` or `` prefix`...` ``), app-sequence notation
|
|
716
775
|
* (`prefix<<...>>`), and/or a raw tag literal (`N(...)`), re-emit a value
|
|
717
776
|
* using its exact original spelling instead of normalizing it to the
|
|
718
777
|
* regenerated `prefix'...'` form.
|
|
@@ -722,10 +781,10 @@ export interface ToCDNOptions {
|
|
|
722
781
|
* `` DT`1969-07-21T02:56:16Z` ``, `DT<<'1969-07-21T02:56:16Z'>>`, and even
|
|
723
782
|
* the raw tag form `1(1749772800)` all become
|
|
724
783
|
* `DT'2025-06-13T00:00:00Z'`-style `prefix'...'` notation, even though all
|
|
725
|
-
* of these denote the same value. `
|
|
784
|
+
* of these denote the same value. `preserveAppPrefix` keeps the
|
|
726
785
|
* original spelling instead — whichever quoting (`'...'` vs `` `...` ``),
|
|
727
786
|
* bracketing (`<<...>>`), or raw tag form was used. Has no effect when
|
|
728
|
-
* `
|
|
787
|
+
* `appPrefix` is `false` (raw tag notation is used either way regardless
|
|
729
788
|
* of the original spelling), or on values not parsed from one of these
|
|
730
789
|
* forms.
|
|
731
790
|
*
|
|
@@ -733,13 +792,34 @@ export interface ToCDNOptions {
|
|
|
733
792
|
* lines falls back to normal (regenerated) notation; single-line
|
|
734
793
|
* spellings are kept.
|
|
735
794
|
*
|
|
736
|
-
* An explicit `preserveComments` setting is still applied
|
|
737
|
-
* inside a preserved
|
|
738
|
-
* normalised without changing the notation family, and
|
|
739
|
-
*
|
|
795
|
+
* An explicit `preserveComments`/`comments` setting is still applied
|
|
796
|
+
* to comments inside a preserved app-sequence spelling: marker styles are
|
|
797
|
+
* normalised without changing the notation family, and stripping comments
|
|
798
|
+
* (`preserveComments: false` with `comments` unset or `'strip'`)
|
|
799
|
+
* removes them while retaining the surrounding source spelling. Leaving
|
|
800
|
+
* *both* unset keeps the spelling's comments exactly as originally
|
|
801
|
+
* written, since nothing was explicitly requested.
|
|
802
|
+
*
|
|
803
|
+
* Named after `app-prefix` (§6.1 of draft-ietf-cbor-edn-literals-27; e.g.
|
|
804
|
+
* `dt`, `DT`, `ip`, `IP`), the identifier that `app-string`/`app-sequence`
|
|
805
|
+
* notation is built from. The raw tag literal case is still covered: it's
|
|
806
|
+
* the source spelling that used *no* app-prefix at all, and this option
|
|
807
|
+
* preserves that choice too, not just spellings that did use one.
|
|
808
|
+
* `preserveAppSequence` was the old, narrower name for this same option,
|
|
809
|
+
* since it also preserves app-string and raw-tag spellings, not just
|
|
810
|
+
* `<<...>>` sequences.
|
|
740
811
|
*
|
|
741
812
|
* @default false
|
|
742
813
|
*/
|
|
814
|
+
preserveAppPrefix?: boolean;
|
|
815
|
+
/**
|
|
816
|
+
* @deprecated Renamed to `preserveAppPrefix` — the old name only
|
|
817
|
+
* described the `<<...>>` form even though this option also preserves
|
|
818
|
+
* `prefix'...'` / `` prefix`...` `` and raw tag (`N(...)`) spellings.
|
|
819
|
+
* Still honoured when `preserveAppPrefix` is left unset, but
|
|
820
|
+
* `preserveAppPrefix` wins if both are set, and it no longer
|
|
821
|
+
* participates in `preserveAll` (use `preserveAppPrefix` for that).
|
|
822
|
+
*/
|
|
743
823
|
preserveAppSequence?: boolean;
|
|
744
824
|
/**
|
|
745
825
|
* Numeric format for integer values in CDN output.
|
|
@@ -754,9 +834,25 @@ export interface ToCDNOptions {
|
|
|
754
834
|
* Numeric format for floating-point values in CDN output.
|
|
755
835
|
* - `'decimal'`: standard decimal notation (e.g. `1.5`, `145544.0_3`)
|
|
756
836
|
* - `'hex'`: C99-style hex float notation (e.g. `0x1.8p+0`, `0x1.1c54p+17_3`)
|
|
837
|
+
* - `'app-extension'`: `float'...'` app-string notation carrying the
|
|
838
|
+
* value's exact IEEE 754 bit pattern (e.g. `float'3fc00000'`), per §3.8
|
|
839
|
+
* of draft-ietf-cbor-edn-literals-27. Unlike `'decimal'`/`'hex'`, this
|
|
840
|
+
* is derived from the value's actual encoded bytes rather than its
|
|
841
|
+
* numeric text, so it losslessly represents NaN payloads and
|
|
842
|
+
* ±Infinity too (not just finite values). Falls back to `'decimal'`
|
|
843
|
+
* when `appPrefix` is `false`, matching how other built-in extensions
|
|
844
|
+
* fall back to raw notation.
|
|
845
|
+
*
|
|
846
|
+
* A value originally parsed from a `float'...'`/`float<<...>>` literal
|
|
847
|
+
* normally re-emits that exact source spelling regardless of this option
|
|
848
|
+
* (so its own encoding-width choice, or a non-canonical bit pattern, isn't
|
|
849
|
+
* silently normalized away) — leaving `floatFormat` unset, or setting it
|
|
850
|
+
* to `'app-extension'`, keeps that round-trip. Explicitly requesting
|
|
851
|
+
* `'decimal'` or `'hex'` opts out of it and reformats the value like any
|
|
852
|
+
* other float, since that's the point of asking for a different format.
|
|
757
853
|
* @default 'decimal'
|
|
758
854
|
*/
|
|
759
|
-
floatFormat?: 'decimal' | 'hex';
|
|
855
|
+
floatFormat?: 'decimal' | 'hex' | 'app-extension';
|
|
760
856
|
/**
|
|
761
857
|
* Split long text strings using CDN string concatenation syntax (`"a" + "b"`).
|
|
762
858
|
* Only effective when `indent` enables pretty-printing.
|
|
@@ -783,6 +879,11 @@ export interface ToCDNOptions {
|
|
|
783
879
|
* `preserveConcatenation`; when it does not, the original concatenation
|
|
784
880
|
* is preserved as usual.
|
|
785
881
|
*
|
|
882
|
+
* `inlineLeafContainers` applies to the embedded CDN structure too: an
|
|
883
|
+
* array/map/`<<...>>` in the string content that would stay on one line
|
|
884
|
+
* as a real value keeps its split points collapsed here as well (e.g.
|
|
885
|
+
* `"[1, 2, 3]"` stays a single literal instead of splitting per element).
|
|
886
|
+
*
|
|
786
887
|
* Replaces the deprecated `textStringFormat: ['cdn']`.
|
|
787
888
|
*
|
|
788
889
|
* @default false
|
|
@@ -818,8 +919,8 @@ export interface ToCDNOptions {
|
|
|
818
919
|
* concatenation, and only takes effect when `indent` enables
|
|
819
920
|
* pretty-printing (single-line output joins the parts into one literal).
|
|
820
921
|
*
|
|
821
|
-
* Also applies within an elision (`...`, §
|
|
822
|
-
* draft-ietf-cbor-edn-literals-
|
|
922
|
+
* Also applies within an elision (`...`, §5.2 of
|
|
923
|
+
* draft-ietf-cbor-edn-literals-27): a `+`-joined fragment on either side of
|
|
823
924
|
* an ellipsis keeps its own part boundaries too (e.g. `'test' +
|
|
824
925
|
* h'1234...abcd' + ...` stays exactly as written instead of merging
|
|
825
926
|
* `'test'` into the byte fragment before it), and byte-string elision
|
|
@@ -835,17 +936,100 @@ export interface ToCDNOptions {
|
|
|
835
936
|
*/
|
|
836
937
|
preserveConcatenation?: boolean;
|
|
837
938
|
/**
|
|
838
|
-
*
|
|
839
|
-
*
|
|
840
|
-
*
|
|
841
|
-
*
|
|
842
|
-
*
|
|
939
|
+
* Render preserved `+` string concatenation (see `preserveConcatenation`)
|
|
940
|
+
* or an elision chain (`...`, §5.2) using `t1<<...>>` / `b1<<...>>`
|
|
941
|
+
* app-sequence notation (draft-ietf-cbor-edn-literals-27 §3.5)
|
|
942
|
+
* instead of the legacy `+` operator.
|
|
943
|
+
*
|
|
944
|
+
* - `false` (default): `"a" + "b"` / `'test' + h'1234...abcd' + ...`.
|
|
945
|
+
* - `true`: `t1<<"a", "b">>` / `b1<<h'1234', h'..abcd'>>`. Falls back to
|
|
946
|
+
* `false`'s rendering when `appPrefix` is `false`, since this notation
|
|
947
|
+
* is itself an app-string form.
|
|
948
|
+
*
|
|
949
|
+
* For a plain (non-elision) concatenation, only changes the spelling used
|
|
950
|
+
* where `preserveConcatenation` already causes multi-part rendering; has
|
|
951
|
+
* no effect when concatenation collapses into a single merged literal
|
|
952
|
+
* (e.g. `preserveConcatenation` unset, or a text string whose content is
|
|
953
|
+
* reflowed by `splitCdn` instead). An elision chain is different: `...`
|
|
954
|
+
* denotes genuinely unknown content, so it always renders as multiple
|
|
955
|
+
* parts regardless of `preserveConcatenation` — `modernConcat` therefore
|
|
956
|
+
* also applies to it unconditionally (`preserveConcatenation` there only
|
|
957
|
+
* controls how much of a fragment's *own* internal boundary is shown, not
|
|
958
|
+
* whether the chain itself is shown as multiple parts).
|
|
959
|
+
*
|
|
960
|
+
* Has no effect on a value that was itself parsed from `t1<<...>>` /
|
|
961
|
+
* `b1<<...>>` source: when `appPrefix` is not `false`, `encodingIndicators`
|
|
962
|
+
* is `'auto'` (both defaults), and the source is either single-line or
|
|
963
|
+
* being rendered with `indent` enabled, that spelling is kept verbatim
|
|
964
|
+
* regardless of `modernConcat` (see `t1`/`b1` in
|
|
965
|
+
* [String Concatenation and Indefinite-Length Strings](../README.md#string-concatenation-and-indefinite-length-strings)).
|
|
966
|
+
* A multi-line source falls back to normalized (collapsed) output in
|
|
967
|
+
* single-line mode, since that layout can't be reproduced without
|
|
968
|
+
* `indent`. `modernConcat` only affects values reconstructed from a `+`
|
|
969
|
+
* chain.
|
|
843
970
|
*
|
|
844
|
-
*
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
*
|
|
971
|
+
* @default false
|
|
972
|
+
*/
|
|
973
|
+
modernConcat?: boolean;
|
|
974
|
+
/**
|
|
975
|
+
* Render an indefinite-length string using `ilts<<...>>` / `ilbs<<...>>`
|
|
976
|
+
* app-sequence notation (draft-ietf-cbor-edn-literals-27 §3.6)
|
|
977
|
+
* instead of the legacy `(_ "a", "b")` streamstring form.
|
|
978
|
+
*
|
|
979
|
+
* - `false` (default): `(_ "a", "b")`.
|
|
980
|
+
* - `true`: `ilts<<"a", "b">>` / `ilbs<<h'..', h'..'>>`. Falls back to
|
|
981
|
+
* `false`'s rendering when `appPrefix` is `false`, since this notation
|
|
982
|
+
* is itself an app-string form.
|
|
983
|
+
*
|
|
984
|
+
* Applies whenever an indefinite-length string is rendered as chunks;
|
|
985
|
+
* unaffected by `encodingIndicators: 'never'`, which merges the chunks
|
|
986
|
+
* into a single definite-length literal regardless of this option.
|
|
987
|
+
*
|
|
988
|
+
* Has no effect on a value that was itself parsed from `ilts<<...>>` /
|
|
989
|
+
* `ilbs<<...>>` source: when `appPrefix` is not `false`, `encodingIndicators`
|
|
990
|
+
* is `'auto'` (both defaults), and the source is either single-line or
|
|
991
|
+
* being rendered with `indent` enabled, that spelling is kept verbatim
|
|
992
|
+
* regardless of `modernStreamSyntax`. A multi-line source falls back to
|
|
993
|
+
* normalized (collapsed) output in single-line mode, since that layout
|
|
994
|
+
* can't be reproduced without `indent`. `modernStreamSyntax` only affects
|
|
995
|
+
* values reconstructed from a legacy `(_ ...)` chunk list.
|
|
996
|
+
*
|
|
997
|
+
* @default false
|
|
998
|
+
*/
|
|
999
|
+
modernStreamSyntax?: boolean;
|
|
1000
|
+
/**
|
|
1001
|
+
* When pretty-printing with `indent`, keep an array, map, or
|
|
1002
|
+
* indefinite-length string group (`(_ "a", "b")`) on a single line when
|
|
1003
|
+
* none of its entries contains an array or map (even wrapped in a tag),
|
|
1004
|
+
* none of its entries is a text string with two or more words (also even
|
|
1005
|
+
* wrapped in a tag), and every entry serializes without a line break
|
|
1006
|
+
* (e.g. `[1, 2, 3]`, `{"a": 1}`, `(_ "a", "b")`). Word boundaries follow
|
|
1007
|
+
* `Intl.Segmenter`'s word-break rules, so `["hello", "world"]` still
|
|
1008
|
+
* collapses to one line (each entry is a single word) while `["Hello,
|
|
1009
|
+
* World!", "This is the CBOR library."]` renders one entry per line (each
|
|
1010
|
+
* has two or more) — space-less scripts (Japanese, Chinese, ...) are still
|
|
1011
|
+
* split on their own dictionary-based word boundaries. Nested leaf
|
|
1012
|
+
* containers still collapse individually: `[[1, 2], [3, 4]]` renders with
|
|
1013
|
+
* one inner array per line.
|
|
1014
|
+
*
|
|
1015
|
+
* `<<...>>` (CBOR Sequence Literal / embedded CBOR) is not governed by
|
|
1016
|
+
* this option at all: its own parens never require an additional line
|
|
1017
|
+
* break by themselves, regardless of `inlineLeafContainers`'s value,
|
|
1018
|
+
* since (unlike an array, map, or indefinite-length string group) it has
|
|
1019
|
+
* no nested-structure display of its own to spread out — it's a flat
|
|
1020
|
+
* sequence of encoded items. Instead it stays on one line exactly when
|
|
1021
|
+
* every entry's own actual rendering already does — an entry that is
|
|
1022
|
+
* itself an array/map is not disqualified just for being one, unlike in
|
|
1023
|
+
* an outer array/map. Concretely: `<<{1: -7}>>` renders as `<<{1: -7}>>`
|
|
1024
|
+
* when `inlineLeafContainers` lets the inner map collapse to one line,
|
|
1025
|
+
* but as `<<\n {\n 1: -7\n }\n>>` when it doesn't (the map itself
|
|
1026
|
+
* still spreads one entry per line without the option, same as it would
|
|
1027
|
+
* anywhere else — `<<...>>` just doesn't add a break of its own on top
|
|
1028
|
+
* of that). `[{1: -7}]`, by contrast, always spreads its `{1: -7}` entry
|
|
1029
|
+
* onto its own line regardless of whether the map itself collapses,
|
|
1030
|
+
* since a nested array/map always disqualifies an outer array/map's
|
|
1031
|
+
* entry. A two-or-more-word text entry still forces a break inside
|
|
1032
|
+
* `<<...>>` either way, irrespective of `inlineLeafContainers`.
|
|
849
1033
|
*
|
|
850
1034
|
* Containers with preserved comments are always emitted in multi-line
|
|
851
1035
|
* form. Has no effect when `indent` is omitted.
|
|
@@ -916,12 +1100,12 @@ export interface ValidateOptions {
|
|
|
916
1100
|
*/
|
|
917
1101
|
extensions?: CborExtension[];
|
|
918
1102
|
/**
|
|
919
|
-
* Override the default set of bundled
|
|
1103
|
+
* Override the default set of bundled app-extensions.
|
|
920
1104
|
* Mirrors `FromCBOROptions.builtinExtensions`.
|
|
921
1105
|
*/
|
|
922
1106
|
builtinExtensions?: CborExtension[] | false;
|
|
923
1107
|
/**
|
|
924
|
-
* How to handle unrecognised
|
|
1108
|
+
* How to handle unrecognised app-extension identifiers.
|
|
925
1109
|
* Only applies when `type` is `'cdn'`; mirrors `FromCDNOptions.unresolvedExtension`.
|
|
926
1110
|
* @default 'cpa999'
|
|
927
1111
|
*/
|
|
@@ -996,9 +1180,9 @@ export interface ValidateResult {
|
|
|
996
1180
|
*/
|
|
997
1181
|
cddlWarnings?: CddlValidationWarning[];
|
|
998
1182
|
}
|
|
999
|
-
/** `fromCBORSeq()`
|
|
1183
|
+
/** Options for `fromCBORSeq()` (`offset`/`allowTrailing` are excluded — the generator manages them). */
|
|
1000
1184
|
export type FromCBORSeqOptions = Omit<FromCBOROptions, 'offset' | 'allowTrailing'>;
|
|
1001
|
-
/** `fromCDNSeq()`
|
|
1185
|
+
/** Options for `fromCDNSeq()` (`offset`/`allowTrailing` are excluded — the generator manages them). */
|
|
1002
1186
|
export type FromCDNSeqOptions = Omit<FromCDNOptions, 'offset' | 'allowTrailing'>;
|
|
1003
1187
|
/**
|
|
1004
1188
|
* Combined options for the `CBOR` constructor.
|
package/dist/utils/base64.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Decode base64 text (classic or URL-safe alphabet, padding optional) into
|
|
3
3
|
* bytes, with strict RFC 4648 validation.
|
|
4
4
|
*
|
|
5
|
-
* Used by the CDN parser (b64'…' literals, §
|
|
5
|
+
* Used by the CDN parser (b64'…' literals, §6.2.2) and the CDDL tokenizer
|
|
6
6
|
* (b64'…' byte strings, RFC 8610 §3.1).
|
|
7
7
|
*
|
|
8
8
|
* Recoverable deviations (padding-count mismatches, non-zero trailing bits)
|
package/dist/utils/hexfloat.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Hex float format:
|
|
5
5
|
* [-] 0x [hex digits] [. [hex digits]] p [+-] [decimal exponent]
|
|
6
6
|
*
|
|
7
|
-
* This notation appears in CDN (draft-ietf-cbor-edn-literals-
|
|
7
|
+
* This notation appears in CDN (draft-ietf-cbor-edn-literals-27) as an
|
|
8
8
|
* alternative representation for floating-point values (major type 7).
|
|
9
9
|
*/
|
|
10
10
|
/**
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cbortech/cbor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Convert between CBOR, CDN (CBOR-EDN), and JavaScript values with CDDL validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cbor",
|
|
7
7
|
"cdn",
|
|
8
8
|
"cddl",
|
|
9
9
|
"cddl-validation",
|
|
10
|
-
"rfc8610",
|
|
11
10
|
"cbor-edn",
|
|
12
11
|
"diagnostic-notation",
|
|
13
12
|
"json",
|
|
@@ -90,12 +89,13 @@
|
|
|
90
89
|
"build": "vite build",
|
|
91
90
|
"prepack": "npm run build",
|
|
92
91
|
"watch": "vite build --watch",
|
|
93
|
-
"typecheck": "tsc --noEmit",
|
|
92
|
+
"typecheck": "node ./node_modules/typescript/bin/tsc --noEmit",
|
|
94
93
|
"start": "node dist/index.js",
|
|
95
94
|
"dev": "npm run build && npm start",
|
|
96
95
|
"clean": "node -e \"['dist','coverage'].forEach(d=>require('fs').rmSync(d,{recursive:true,force:true}))\"",
|
|
97
96
|
"test": "vitest run --exclude src/cdn/edn-test-vectors.test.ts --exclude src/cdn/edn-abnf-vectors.test.ts --exclude src/cddl/cddl-corpus.test.ts --exclude src/cddl/cddl-validation-vectors.test.ts --exclude site/src/playground.browser.test.ts",
|
|
98
97
|
"test:exports": "npm run build && node scripts/check-package-exports.mjs",
|
|
98
|
+
"fetch-test-vectors": "node scripts/fetch-test-vectors.mjs",
|
|
99
99
|
"test:node": "vitest run --exclude src/cdn/edn-test-vectors.test.ts --exclude src/cdn/edn-abnf-vectors.test.ts --exclude src/cddl/cddl-corpus.test.ts --exclude src/cddl/cddl-validation-vectors.test.ts --exclude site/src/playground.browser.test.ts",
|
|
100
100
|
"test:edn-vectors": "vitest run src/cdn/edn-test-vectors.test.ts",
|
|
101
101
|
"test:edn-abnf": "vitest run src/cdn/edn-abnf-vectors.test.ts",
|
|
@@ -120,16 +120,17 @@
|
|
|
120
120
|
"devDependencies": {
|
|
121
121
|
"@cbortech/hash-extension": "^0.2.3",
|
|
122
122
|
"@types/node": "^24.13.3",
|
|
123
|
+
"@typescript/typescript6": "^6.0.2",
|
|
123
124
|
"@vitest/browser": "^4.1.10",
|
|
124
125
|
"@vitest/browser-playwright": "^4.1.10",
|
|
125
126
|
"@vitest/coverage-v8": "^4.1.10",
|
|
126
127
|
"@vitest/ui": "^4.1.10",
|
|
127
128
|
"cross-env": "^10.1.0",
|
|
128
|
-
"playwright": "^1.
|
|
129
|
+
"playwright": "^1.62.1",
|
|
129
130
|
"prettier": "^3.9.6",
|
|
130
|
-
"typescript": "^
|
|
131
|
-
"vite": "^8.1
|
|
132
|
-
"vite-plugin-dts": "^
|
|
131
|
+
"typescript": "^7.0.2",
|
|
132
|
+
"vite": "^8.2.1",
|
|
133
|
+
"vite-plugin-dts": "^5.0.3",
|
|
133
134
|
"vitest": "^4.1.10"
|
|
134
135
|
}
|
|
135
136
|
}
|