@cbortech/cbor 0.24.0 → 0.25.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 +35 -37
- package/README.md +35 -37
- package/dist/ast/CborArray.d.ts +3 -3
- package/dist/ast/CborBignum.d.ts +5 -5
- package/dist/ast/CborByteString.d.ts +2 -2
- package/dist/ast/CborEllipsis.d.ts +2 -2
- package/dist/ast/CborEmbeddedCBOR.d.ts +3 -3
- package/dist/ast/CborFloat.d.ts +2 -2
- package/dist/ast/CborIndefiniteByteString.d.ts +3 -3
- package/dist/ast/CborIndefiniteTextString.d.ts +3 -3
- package/dist/ast/CborItem.d.ts +16 -10
- package/dist/ast/CborMap.d.ts +3 -3
- package/dist/ast/CborNint.d.ts +2 -2
- package/dist/ast/CborSimple.d.ts +2 -2
- package/dist/ast/CborTag.d.ts +3 -3
- package/dist/ast/CborTextString.d.ts +2 -2
- package/dist/ast/CborUint.d.ts +2 -2
- package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cbor.d.ts +44 -26
- package/dist/cdn/parser.d.ts +7 -0
- package/dist/{edn → cdn}/serialize-utils.d.ts +4 -4
- package/dist/cdn/serializer.d.ts +7 -0
- package/dist/{edn → cdn}/tokenizer.d.ts +3 -3
- package/dist/extensions/cri.d.ts +7 -7
- package/dist/extensions/dt.d.ts +9 -9
- package/dist/extensions/ip.d.ts +8 -8
- package/dist/extensions/types.d.ts +4 -4
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -18
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-CNxwMt7o.cjs +31 -0
- package/dist/mapEntries-CNxwMt7o.cjs.map +1 -0
- package/dist/{mapEntries-D5MWtXqq.js → mapEntries-Da-2HMRf.js} +467 -461
- package/dist/mapEntries-Da-2HMRf.js.map +1 -0
- package/dist/simple.d.ts +2 -2
- package/dist/tag.d.ts +1 -1
- package/dist/types.d.ts +40 -24
- package/dist/utils/hexfloat.d.ts +2 -2
- package/package.json +9 -9
- package/dist/edn/parser.d.ts +0 -7
- package/dist/edn/serializer.d.ts +0 -7
- package/dist/mapEntries-D5MWtXqq.js.map +0 -1
- package/dist/mapEntries-bihZ3yks.cjs +0 -31
- package/dist/mapEntries-bihZ3yks.cjs.map +0 -1
package/dist/ast/CborItem.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CBOROptions,
|
|
1
|
+
import { CBOROptions, ToCDNOptions, ToJSOptions, ToHexDumpOptions, ToCBOROptions, CborComments } from '../types';
|
|
2
2
|
/** @internal One line of an annotated hex dump. */
|
|
3
3
|
export interface AnnotatedLine {
|
|
4
4
|
depth: number;
|
|
@@ -8,7 +8,7 @@ export interface AnnotatedLine {
|
|
|
8
8
|
/**
|
|
9
9
|
* Abstract base class for all CBOR AST nodes.
|
|
10
10
|
*
|
|
11
|
-
* Every node can serialize itself to CBOR binary,
|
|
11
|
+
* Every node can serialize itself to CBOR binary, CDN text, and a
|
|
12
12
|
* plain JavaScript value. Concrete implementations are provided in each
|
|
13
13
|
* subclass (added in later phases).
|
|
14
14
|
*/
|
|
@@ -26,7 +26,7 @@ export declare abstract class CborItem {
|
|
|
26
26
|
*/
|
|
27
27
|
end?: number;
|
|
28
28
|
/**
|
|
29
|
-
* Comments captured from
|
|
29
|
+
* Comments captured from CDN source when `preserveComments` is enabled.
|
|
30
30
|
* They do not affect CBOR bytes or JS conversion.
|
|
31
31
|
*/
|
|
32
32
|
comments?: CborComments;
|
|
@@ -38,8 +38,14 @@ export declare abstract class CborItem {
|
|
|
38
38
|
_defaults?: CBOROptions;
|
|
39
39
|
/** Serialize this node to CBOR binary. */
|
|
40
40
|
toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
41
|
-
/** Serialize this node to a
|
|
42
|
-
|
|
41
|
+
/** Serialize this node to a CDN text string. */
|
|
42
|
+
toCDN(options?: ToCDNOptions): string;
|
|
43
|
+
/**
|
|
44
|
+
* Serialize this node to a CDN text string.
|
|
45
|
+
*
|
|
46
|
+
* @deprecated Use `toCDN()` instead.
|
|
47
|
+
*/
|
|
48
|
+
toEDN(options?: ToCDNOptions): string;
|
|
43
49
|
/**
|
|
44
50
|
* Convert this CBOR AST node to a plain JavaScript value.
|
|
45
51
|
*
|
|
@@ -53,7 +59,7 @@ export declare abstract class CborItem {
|
|
|
53
59
|
* Generate an RFC 8949 §3 style annotated hex dump of this value.
|
|
54
60
|
*
|
|
55
61
|
* @example
|
|
56
|
-
* const cbor = CBOR.
|
|
62
|
+
* const cbor = CBOR.fromCDN('[_ 1, [2, 3]]');
|
|
57
63
|
* console.log(cbor.toHexDump());
|
|
58
64
|
* // 9F -- Start indefinite-length array
|
|
59
65
|
* // 01 -- 1
|
|
@@ -68,12 +74,12 @@ export declare abstract class CborItem {
|
|
|
68
74
|
abstract _toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
69
75
|
/**
|
|
70
76
|
* @internal
|
|
71
|
-
* Depth-aware
|
|
77
|
+
* Depth-aware CDN serialization.
|
|
72
78
|
* Leaf nodes receive `depth` but may ignore it.
|
|
73
79
|
* Container nodes use `depth` for indentation and call
|
|
74
|
-
* `child.
|
|
80
|
+
* `child._toCDN(options, depth + 1)` when recursing.
|
|
75
81
|
*/
|
|
76
|
-
abstract
|
|
82
|
+
abstract _toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
77
83
|
/**
|
|
78
84
|
* @internal
|
|
79
85
|
* Core conversion logic implemented by each subclass.
|
|
@@ -87,5 +93,5 @@ export declare abstract class CborItem {
|
|
|
87
93
|
* Leaf nodes emit a single line; container nodes override to emit
|
|
88
94
|
* open/close lines with recursively collected children.
|
|
89
95
|
*/
|
|
90
|
-
_toHexDump(depth: number, options?:
|
|
96
|
+
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
91
97
|
}
|
package/dist/ast/CborMap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
3
|
import { EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 5 — map (definite- or indefinite-length). */
|
|
@@ -11,7 +11,7 @@ export declare class CborMap extends CborItem {
|
|
|
11
11
|
encodingWidth?: EncodingWidth;
|
|
12
12
|
});
|
|
13
13
|
_toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
14
|
-
|
|
15
|
-
_toHexDump(depth: number, options?:
|
|
14
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
15
|
+
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
16
16
|
_toJS(options?: ToJSOptions): unknown;
|
|
17
17
|
}
|
package/dist/ast/CborNint.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
3
|
import { EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/**
|
|
@@ -22,6 +22,6 @@ export declare class CborNint extends CborItem {
|
|
|
22
22
|
/** The actual decoded negative value (−1 − argument). */
|
|
23
23
|
get value(): bigint;
|
|
24
24
|
_toCBOR(_options?: ToCBOROptions): Uint8Array;
|
|
25
|
-
|
|
25
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
26
26
|
_toJS(options?: ToJSOptions): unknown;
|
|
27
27
|
}
|
package/dist/ast/CborSimple.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
3
|
/**
|
|
4
4
|
* CBOR Major Type 7 — simple value (0–255).
|
|
@@ -17,6 +17,6 @@ export declare class CborSimple extends CborItem {
|
|
|
17
17
|
static readonly NULL: CborSimple;
|
|
18
18
|
static readonly UNDEFINED: CborSimple;
|
|
19
19
|
_toCBOR(_options?: ToCBOROptions): Uint8Array;
|
|
20
|
-
|
|
20
|
+
_toCDN(_options: ToCDNOptions | undefined, _depth: number): string;
|
|
21
21
|
_toJS(_options?: ToJSOptions): unknown;
|
|
22
22
|
}
|
package/dist/ast/CborTag.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
3
|
import { EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 6 — tagged data item. */
|
|
@@ -10,7 +10,7 @@ export declare class CborTag extends CborItem {
|
|
|
10
10
|
encodingWidth?: EncodingWidth;
|
|
11
11
|
});
|
|
12
12
|
_toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
13
|
-
|
|
14
|
-
_toHexDump(depth: number, options?:
|
|
13
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
14
|
+
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
15
15
|
_toJS(options?: ToJSOptions): unknown;
|
|
16
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
3
|
import { EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 3 — definite-length UTF-8 text string. */
|
|
@@ -10,6 +10,6 @@ export declare class CborTextString extends CborItem {
|
|
|
10
10
|
encodingWidth?: EncodingWidth;
|
|
11
11
|
});
|
|
12
12
|
_toCBOR(_options?: ToCBOROptions): Uint8Array;
|
|
13
|
-
|
|
13
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
14
14
|
_toJS(_options?: ToJSOptions): unknown;
|
|
15
15
|
}
|
package/dist/ast/CborUint.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
3
|
import { EncodingWidth } from '../cbor/encode';
|
|
4
4
|
/** CBOR Major Type 0 — unsigned integer (0 … 2^64−1). */
|
|
@@ -9,6 +9,6 @@ export declare class CborUint extends CborItem {
|
|
|
9
9
|
encodingWidth?: EncodingWidth;
|
|
10
10
|
});
|
|
11
11
|
_toCBOR(_options?: ToCBOROptions): Uint8Array;
|
|
12
|
-
|
|
12
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
13
13
|
_toJS(options?: ToJSOptions): unknown;
|
|
14
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions } from '../types';
|
|
2
2
|
import { CborTag } from './CborTag';
|
|
3
3
|
import { CborItem } from './CborItem';
|
|
4
4
|
/** Provisional tag number for the Unresolved Application-Extension stand-in. */
|
|
@@ -12,5 +12,5 @@ export declare const CPA999_TAG = 999n;
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class CborUnresolvedAppExt extends CborTag {
|
|
14
14
|
constructor(prefix: string, items: CborItem[]);
|
|
15
|
-
|
|
15
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
16
16
|
}
|
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-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;
|
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-Da-2HMRf.js";
|
|
2
2
|
export { u as CborArray, n as CborBigNint, s as CborBigUint, a as CborByteString, d as CborEmbeddedCBOR, f as CborFloat, o as CborIndefiniteByteString, c as CborIndefiniteTextString, p as CborItem, i as CborMap, m as CborNint, r as CborSimple, e as CborTag, l as CborTextString, t as CborUint };
|
package/dist/cbor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CborItem } from './ast/CborItem';
|
|
2
|
-
import { CBOROptions, FromCBOROptions,
|
|
2
|
+
import { CBOROptions, FromCBOROptions, FromCDNOptions, FromHexDumpOptions, FromJSOptions, ToCBOROptions, ToCDNOptions, ToJSOptions, CBOR_OMIT } from './types';
|
|
3
3
|
import { dt_as_Date as _dt_as_Date } from './extensions/dt';
|
|
4
4
|
import { MapEntries as _MapEntries } from './mapEntries';
|
|
5
5
|
import { Simple as _Simple } from './simple';
|
|
@@ -40,7 +40,7 @@ export declare class CBOR {
|
|
|
40
40
|
static readonly Simple: typeof _Simple;
|
|
41
41
|
/** Array subclass used to preserve CBOR map entries, including duplicates. */
|
|
42
42
|
static readonly MapEntries: typeof _MapEntries;
|
|
43
|
-
/** Extension that maps
|
|
43
|
+
/** Extension that maps CDN dt/DT values to JavaScript Date objects. */
|
|
44
44
|
static readonly dt_as_Date: typeof _dt_as_Date;
|
|
45
45
|
/**
|
|
46
46
|
* Create a reusable instance with default options applied to every method call.
|
|
@@ -53,30 +53,40 @@ export declare class CBOR {
|
|
|
53
53
|
*/
|
|
54
54
|
constructor(defaults?: CBOROptions);
|
|
55
55
|
fromCBOR(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions): CborItem;
|
|
56
|
-
|
|
56
|
+
fromCDN(text: string, options?: FromCDNOptions): CborItem;
|
|
57
|
+
/** @deprecated Use `fromCDN()` instead. */
|
|
58
|
+
fromEDN(text: string, options?: FromCDNOptions): CborItem;
|
|
57
59
|
fromJS(value: unknown, options?: FromJSOptions): CborItem;
|
|
58
60
|
fromHexDump(text: string, options?: FromHexDumpOptions): CborItem;
|
|
59
61
|
decode(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToJSOptions): unknown;
|
|
60
62
|
encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array;
|
|
61
63
|
/**
|
|
62
|
-
* @deprecated Use `fromCBOR(input, options).
|
|
64
|
+
* @deprecated Use `cborToCdn()` or `fromCBOR(input, options).toCDN(options)` instead.
|
|
63
65
|
*/
|
|
64
|
-
cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions &
|
|
66
|
+
cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
67
|
+
cborToCdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
65
68
|
/**
|
|
66
|
-
* @deprecated Use `
|
|
69
|
+
* @deprecated Use `cdnToCbor()` or `fromCDN(text, options).toCBOR(options)` instead.
|
|
67
70
|
*/
|
|
68
|
-
cborEdnToCbor(text: string, options?:
|
|
71
|
+
cborEdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
72
|
+
cdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
69
73
|
parse(text: string): unknown;
|
|
70
74
|
parse(text: string, reviver: (this: unknown, key: unknown, value: unknown) => unknown): unknown;
|
|
71
|
-
parse(text: string, options:
|
|
75
|
+
parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;
|
|
72
76
|
stringify(value: unknown): string;
|
|
73
77
|
stringify(value: unknown, replacer: ((this: unknown, key: unknown, value: unknown) => unknown) | (string | number)[] | null, space?: string | number): string;
|
|
74
|
-
stringify(value: unknown, options: FromJSOptions &
|
|
75
|
-
format(text: string, options?:
|
|
78
|
+
stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;
|
|
79
|
+
format(text: string, options?: FromCDNOptions & ToCDNOptions): string;
|
|
76
80
|
/** Decode CBOR binary data into an AST node. */
|
|
77
81
|
static fromCBOR(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions): CborItem;
|
|
78
|
-
/** Parse a
|
|
79
|
-
static
|
|
82
|
+
/** Parse a CDN text string into an AST node. */
|
|
83
|
+
static fromCDN(text: string, options?: FromCDNOptions): CborItem;
|
|
84
|
+
/**
|
|
85
|
+
* Parse a CDN text string into an AST node.
|
|
86
|
+
*
|
|
87
|
+
* @deprecated Use `fromCDN()` instead.
|
|
88
|
+
*/
|
|
89
|
+
static fromEDN(text: string, options?: FromCDNOptions): CborItem;
|
|
80
90
|
/** Convert a JavaScript value into an AST node. */
|
|
81
91
|
static fromJS(value: unknown, options?: FromJSOptions): CborItem;
|
|
82
92
|
/**
|
|
@@ -96,24 +106,32 @@ export declare class CBOR {
|
|
|
96
106
|
/** Encode a JavaScript value directly to CBOR binary data. */
|
|
97
107
|
static encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array;
|
|
98
108
|
/**
|
|
99
|
-
* Convert CBOR binary data directly to a
|
|
109
|
+
* Convert CBOR binary data directly to a CDN text string.
|
|
110
|
+
*/
|
|
111
|
+
static cborToCdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
112
|
+
/**
|
|
113
|
+
* Convert CBOR binary data directly to a CDN text string.
|
|
100
114
|
*
|
|
101
|
-
* @deprecated Use `CBOR.fromCBOR(input, options).
|
|
115
|
+
* @deprecated Use `CBOR.cborToCdn()` or `CBOR.fromCBOR(input, options).toCDN(options)` instead.
|
|
116
|
+
*/
|
|
117
|
+
static cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToCDNOptions): string;
|
|
118
|
+
/**
|
|
119
|
+
* Convert a CDN text string directly to CBOR binary data.
|
|
102
120
|
*/
|
|
103
|
-
static
|
|
121
|
+
static cdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
104
122
|
/**
|
|
105
|
-
* Convert a
|
|
123
|
+
* Convert a CDN text string directly to CBOR binary data.
|
|
106
124
|
*
|
|
107
|
-
* @deprecated Use `CBOR.
|
|
125
|
+
* @deprecated Use `CBOR.cdnToCbor()` or `CBOR.fromCDN(text, options).toCBOR(options)` instead.
|
|
108
126
|
*/
|
|
109
|
-
static cborEdnToCbor(text: string, options?:
|
|
127
|
+
static cborEdnToCbor(text: string, options?: FromCDNOptions & ToCBOROptions): Uint8Array;
|
|
110
128
|
/**
|
|
111
|
-
* Parse a
|
|
129
|
+
* Parse a CDN text string directly to a JavaScript value.
|
|
112
130
|
*
|
|
113
131
|
* Accepts either a JSON-compatible `reviver` function as the second argument,
|
|
114
132
|
* or a plain options object (existing API).
|
|
115
133
|
*
|
|
116
|
-
* When a `reviver` is supplied it is applied bottom-up after the
|
|
134
|
+
* When a `reviver` is supplied it is applied bottom-up after the CDN text has
|
|
117
135
|
* been parsed and converted to a JS value, matching the semantics of
|
|
118
136
|
* `JSON.parse(text, reviver)`.
|
|
119
137
|
*
|
|
@@ -122,9 +140,9 @@ export declare class CBOR {
|
|
|
122
140
|
*/
|
|
123
141
|
static parse(text: string): unknown;
|
|
124
142
|
static parse(text: string, reviver: (this: unknown, key: unknown, value: unknown) => unknown): unknown;
|
|
125
|
-
static parse(text: string, options:
|
|
143
|
+
static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;
|
|
126
144
|
/**
|
|
127
|
-
* Serialize a JavaScript value directly to a
|
|
145
|
+
* Serialize a JavaScript value directly to a CDN text string.
|
|
128
146
|
*
|
|
129
147
|
* Accepts either JSON-compatible `replacer` + `space` arguments, or a plain
|
|
130
148
|
* options object (existing API).
|
|
@@ -132,12 +150,12 @@ export declare class CBOR {
|
|
|
132
150
|
* - `replacer` may be a function (transforms each key/value before encoding)
|
|
133
151
|
* or an array of strings/numbers (allowlist of object keys to include).
|
|
134
152
|
* Pass `null` to skip filtering.
|
|
135
|
-
* - `space` controls indentation, mapping to `
|
|
153
|
+
* - `space` controls indentation, mapping to `ToCDNOptions.indent`.
|
|
136
154
|
* Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.
|
|
137
155
|
*/
|
|
138
156
|
static stringify(value: unknown): string;
|
|
139
157
|
static stringify(value: unknown, replacer: ((this: unknown, key: unknown, value: unknown) => unknown) | (string | number)[] | null, space?: string | number): string;
|
|
140
|
-
static stringify(value: unknown, options: FromJSOptions &
|
|
141
|
-
/** Normalize a
|
|
142
|
-
static format(text: string, options?:
|
|
158
|
+
static stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;
|
|
159
|
+
/** Normalize a CDN text string by parsing and re-serializing it. */
|
|
160
|
+
static format(text: string, options?: FromCDNOptions & ToCDNOptions): string;
|
|
143
161
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CborItem } from '../ast/CborItem';
|
|
2
|
+
import { FromCDNOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Parse a CDN text string into a CborItem AST node.
|
|
5
|
+
* Throws SyntaxError on invalid input.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseCDN(text: string, options?: FromCDNOptions): CborItem;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CborComments,
|
|
1
|
+
import { CborComments, ToCDNOptions } from '../types';
|
|
2
2
|
/** Resolve indent option to a string, or null for single-line output. */
|
|
3
|
-
export declare function resolveIndent(options:
|
|
3
|
+
export declare function resolveIndent(options: ToCDNOptions | undefined): string | null;
|
|
4
4
|
/** Build the indent prefix for a given depth. */
|
|
5
5
|
export declare function indentOf(indentStr: string, depth: number): string;
|
|
6
6
|
export interface Commented {
|
|
@@ -23,7 +23,7 @@ export declare function formatDanglingComments(item: Commented, indent: string):
|
|
|
23
23
|
* - `trailSep` – appended after the last item (empty string or `,`)
|
|
24
24
|
* - `colSep` – between map key and value (`': '` or `':'`)
|
|
25
25
|
*/
|
|
26
|
-
export declare function resolveSeparators(options:
|
|
26
|
+
export declare function resolveSeparators(options: ToCDNOptions | undefined, compact?: boolean): {
|
|
27
27
|
inlineSep: string;
|
|
28
28
|
multilineSep: string;
|
|
29
29
|
trailSep: string;
|
|
@@ -32,7 +32,7 @@ export declare function resolveSeparators(options: ToEDNOptions | undefined, com
|
|
|
32
32
|
export declare function serializeBytes(bytes: Uint8Array, encoding?: 'hex' | 'base64' | 'base64url' | 'base32' | 'base32hex', sqstr?: 'printable-string' | 'string' | 'none'): string;
|
|
33
33
|
/**
|
|
34
34
|
* Produce a single-quoted EDN app-string content `'...'` from a string value.
|
|
35
|
-
* Exported for use by app-extension `
|
|
35
|
+
* Exported for use by app-extension `_toCDN` implementations.
|
|
36
36
|
*/
|
|
37
37
|
export declare function escapeAppString(s: string): string;
|
|
38
38
|
/**
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CborItem } from '../ast/CborItem';
|
|
2
|
+
import { ToCDNOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Serialize a CborItem AST node to CDN text.
|
|
5
|
+
* Equivalent to calling value.toCDN(options) directly.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toCDN(value: CborItem, options?: ToCDNOptions): string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* CDN lexer (internal).
|
|
3
3
|
*
|
|
4
4
|
* Used by parser.ts for parsing and by CborTextString serialization to collect
|
|
5
|
-
* source offsets after
|
|
5
|
+
* source offsets after parseCDN() has already validated embedded CDN.
|
|
6
6
|
*/
|
|
7
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';
|
|
8
8
|
export interface Token {
|
|
@@ -69,7 +69,7 @@ export declare class Tokenizer {
|
|
|
69
69
|
* `context` is used in unterminated-comment error messages.
|
|
70
70
|
*/
|
|
71
71
|
private _skipRawComment;
|
|
72
|
-
/** Skip content until a closing `/` (
|
|
72
|
+
/** Skip content until a closing `/` (CDN block comment). */
|
|
73
73
|
private _skipBlockCommentSlash;
|
|
74
74
|
/** Skip content until a closing `*\/` (JSONC block comment). */
|
|
75
75
|
private _skipBlockCommentStar;
|
package/dist/extensions/cri.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions } from '../types';
|
|
2
2
|
import { CborExtension } from './types';
|
|
3
3
|
import { CborArray } from '../ast/CborArray';
|
|
4
4
|
import { CborTag } from '../ast/CborTag';
|
|
5
5
|
/**
|
|
6
|
-
* CBOR tag number for the tagged CRI variant (
|
|
6
|
+
* CBOR tag number for the tagged CRI variant (§3.4 and §5.2.5 of draft-ietf-cbor-edn-literals-25).
|
|
7
7
|
*/
|
|
8
8
|
export declare const TAG_CRI = 99n;
|
|
9
9
|
/**
|
|
10
|
-
* Bare CRI array whose
|
|
10
|
+
* Bare CRI array whose toCDN() emits cri'…' notation.
|
|
11
11
|
* Falls back to generic array notation if the content cannot be expressed as a URI.
|
|
12
12
|
*/
|
|
13
13
|
export declare class CborCriExt extends CborArray {
|
|
14
|
-
|
|
14
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* tag(99, CRI array) whose
|
|
17
|
+
* tag(99, CRI array) whose toCDN() emits CRI'…' notation.
|
|
18
18
|
* Falls back to generic tag notation if the content cannot be expressed as a URI.
|
|
19
19
|
*/
|
|
20
20
|
export declare class CborTaggedCriExt extends CborTag {
|
|
21
21
|
constructor(content: CborArray);
|
|
22
|
-
|
|
22
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Create the cri/CRI CborExtension (§5.2.5 draft-ietf-cbor-edn-literals-
|
|
25
|
+
* Create the cri/CRI CborExtension (§3.4 and §5.2.5 of draft-ietf-cbor-edn-literals-25).
|
|
26
26
|
*
|
|
27
27
|
* - `cri'uri'` → CborCriExt (bare CRI array, no CBOR tag)
|
|
28
28
|
* - `CRI'uri'` → CborTaggedCriExt tag(99, CRI array)
|
package/dist/extensions/dt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions } from '../types';
|
|
2
2
|
import { CborExtension } from './types';
|
|
3
3
|
import { CborUint } from '../ast/CborUint';
|
|
4
4
|
import { CborNint } from '../ast/CborNint';
|
|
@@ -33,44 +33,44 @@ export declare const PREFIX_DT = "dt";
|
|
|
33
33
|
export declare const PREFIX_DT_TAGGED = "DT";
|
|
34
34
|
export declare const TAG_EPOCH = 1n;
|
|
35
35
|
/**
|
|
36
|
-
* Unsigned epoch timestamp whose
|
|
36
|
+
* Unsigned epoch timestamp whose toCDN() emits dt'…' notation.
|
|
37
37
|
* The RFC 3339 string is re-derived from the numeric value on each call.
|
|
38
38
|
*/
|
|
39
39
|
export declare class CborEpochDtExtUint extends CborUint {
|
|
40
40
|
constructor(value: number | bigint, options?: {
|
|
41
41
|
encodingWidth?: EncodingWidth;
|
|
42
42
|
});
|
|
43
|
-
|
|
43
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
|
-
* Negative epoch timestamp whose
|
|
46
|
+
* Negative epoch timestamp whose toCDN() emits dt'…' notation.
|
|
47
47
|
* The RFC 3339 string is re-derived from the numeric value on each call.
|
|
48
48
|
*/
|
|
49
49
|
export declare class CborEpochDtExtNint extends CborNint {
|
|
50
50
|
constructor(value: number | bigint, options?: {
|
|
51
51
|
encodingWidth?: EncodingWidth;
|
|
52
52
|
});
|
|
53
|
-
|
|
53
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
* Float epoch timestamp whose
|
|
56
|
+
* Float epoch timestamp whose toCDN() emits dt'…' notation.
|
|
57
57
|
* The RFC 3339 string is re-derived from the numeric value on each call.
|
|
58
58
|
*/
|
|
59
59
|
export declare class CborEpochDtExtFloat extends CborFloat {
|
|
60
60
|
constructor(value: number, options?: {
|
|
61
61
|
precision?: 'half' | 'single' | 'double';
|
|
62
62
|
});
|
|
63
|
-
|
|
63
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* CBOR tag(1, epoch) whose
|
|
66
|
+
* CBOR tag(1, epoch) whose toCDN() emits DT'…' notation.
|
|
67
67
|
* The RFC 3339 string is re-derived from the numeric content on each call.
|
|
68
68
|
*/
|
|
69
69
|
export declare class CborTaggedEpochDtExt extends CborTag {
|
|
70
70
|
constructor(datetime: string, options?: {
|
|
71
71
|
encodingWidth?: EncodingWidth;
|
|
72
72
|
});
|
|
73
|
-
|
|
73
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* CBOR tag(1, epoch) whose toJS() returns a plain Date object.
|
package/dist/extensions/ip.d.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions } from '../types';
|
|
2
2
|
import { CborExtension } from './types';
|
|
3
3
|
import { CborItem } from '../ast/CborItem';
|
|
4
4
|
import { CborByteString } from '../ast/CborByteString';
|
|
5
5
|
import { CborTag } from '../ast/CborTag';
|
|
6
6
|
import { CborArray } from '../ast/CborArray';
|
|
7
7
|
/**
|
|
8
|
-
* Bare IP address byte string whose
|
|
8
|
+
* Bare IP address byte string whose toCDN() emits ip'…' notation.
|
|
9
9
|
*/
|
|
10
10
|
export declare class CborIpExt extends CborByteString {
|
|
11
|
-
|
|
11
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Bare IP address prefix (CIDR) whose
|
|
14
|
+
* Bare IP address prefix (CIDR) whose toCDN() emits ip'…/prefix' notation.
|
|
15
15
|
* Encoded as [prefixLen, truncatedBytes] per RFC 9164 §2.3, without a tag.
|
|
16
16
|
*/
|
|
17
17
|
export declare class CborIpPrefixExt extends CborArray {
|
|
18
18
|
private readonly _isV4;
|
|
19
19
|
constructor(prefixLen: number, truncated: Uint8Array, isV4: boolean);
|
|
20
|
-
|
|
20
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* CBOR tag(52/54, …) IP address whose
|
|
23
|
+
* CBOR tag(52/54, …) IP address whose toCDN() emits IP'…' notation.
|
|
24
24
|
* Content may be a byte string (plain address) or an array [prefix, bytes]
|
|
25
25
|
* (CIDR prefix per RFC 9164).
|
|
26
26
|
*/
|
|
27
27
|
export declare class CborTaggedIpExt extends CborTag {
|
|
28
28
|
constructor(tag: bigint, content: CborItem);
|
|
29
|
-
|
|
29
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* Create an ip/IP CborExtension (RFC 9164 / §3.
|
|
32
|
+
* Create an ip/IP CborExtension (RFC 9164 / §3.2 of draft-ietf-cbor-edn-literals-25).
|
|
33
33
|
*
|
|
34
34
|
* - `ip'addr'` → CborIpExt (bare byte string, 4 or 16 bytes)
|
|
35
35
|
* - `IP'addr'` → CborTaggedIpExt tag(52 or 54, bytes)
|
|
@@ -4,7 +4,7 @@ import { FromJSOptions } from '../types';
|
|
|
4
4
|
* Plugin that extends EDN parsing, CBOR decoding, and `fromJS()` for specific
|
|
5
5
|
* application-string prefixes or CBOR tag numbers.
|
|
6
6
|
*
|
|
7
|
-
* Pass instances via `
|
|
7
|
+
* Pass instances via `FromCDNOptions.extensions`, `FromCBOROptions.extensions`,
|
|
8
8
|
* or `FromJSOptions.extensions`.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
@@ -15,7 +15,7 @@ import { FromJSOptions } from '../types';
|
|
|
15
15
|
* return new CborByteString(parseIPv4(content));
|
|
16
16
|
* },
|
|
17
17
|
* };
|
|
18
|
-
*
|
|
18
|
+
* parseCDN("ip'192.0.2.1'", { extensions: [ipExtension] });
|
|
19
19
|
*/
|
|
20
20
|
export interface CborExtension {
|
|
21
21
|
/**
|
|
@@ -26,7 +26,7 @@ export interface CborExtension {
|
|
|
26
26
|
/**
|
|
27
27
|
* CBOR tag numbers this extension handles (e.g. `[0n, 1n]`).
|
|
28
28
|
* Extensions with `parseTag()` are invoked for these tag numbers during
|
|
29
|
-
* `fromCBOR()` and integer-tagged EDN items (`1(…)`) in `
|
|
29
|
+
* `fromCBOR()` and integer-tagged EDN items (`1(…)`) in `fromCDN()`.
|
|
30
30
|
*/
|
|
31
31
|
readonly tagNumbers?: readonly bigint[];
|
|
32
32
|
/**
|
|
@@ -43,7 +43,7 @@ export interface CborExtension {
|
|
|
43
43
|
parseAppSequence?(prefix: string, items: CborItem[]): CborItem;
|
|
44
44
|
/**
|
|
45
45
|
* Called when a `CborTag` is encountered during CBOR decode (`fromCBOR`)
|
|
46
|
-
* or EDN integer-tag parsing (`
|
|
46
|
+
* or EDN integer-tag parsing (`fromCDN`).
|
|
47
47
|
* Return `undefined` to fall back to the default `CborTag` representation.
|
|
48
48
|
*/
|
|
49
49
|
parseTag?(tag: bigint, value: CborItem): CborItem | undefined;
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./mapEntries-
|
|
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
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;
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|