@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/simple.d.ts
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* Also serves as a namespace for simple-value utilities.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* const v = CBOR.
|
|
9
|
+
* const v = CBOR.fromCDN('simple(19)').toJS();
|
|
10
10
|
* Simple.is(v); // true
|
|
11
11
|
* Simple.get(v); // 19
|
|
12
12
|
*
|
|
13
13
|
* const node = CBOR.fromJS(new Simple(19));
|
|
14
|
-
* node.
|
|
14
|
+
* node.toCDN(); // "simple(19)"
|
|
15
15
|
*/
|
|
16
16
|
export declare class Simple {
|
|
17
17
|
readonly value: number;
|
package/dist/tag.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare function getCborTaggedValue(value: unknown): unknown;
|
|
|
19
19
|
* Namespace for CBOR tag annotation utilities.
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
|
-
* const v = CBOR.
|
|
22
|
+
* const v = CBOR.fromCDN('42("hello")').toJS();
|
|
23
23
|
* Tag.get(v); // 42n
|
|
24
24
|
* Tag.getValue(v); // "hello"
|
|
25
25
|
*
|
package/dist/types.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface ToJSOptions {
|
|
|
40
40
|
* - `'object'`: always `Record<string, unknown>` — non-string keys are
|
|
41
41
|
* converted via `String()`. Duplicate keys are overwritten (last wins).
|
|
42
42
|
* - `'entries'`: always `MapEntries` (a typed `Array` subclass) — preserves all
|
|
43
|
-
* entries including duplicate keys (§2.6.
|
|
43
|
+
* entries including duplicate keys (§2.6.3 of draft-ietf-cbor-edn-literals-25).
|
|
44
44
|
* `fromJS()` recognises `MapEntries` instances and converts them back to `CborMap`.
|
|
45
45
|
* @default 'auto'
|
|
46
46
|
*/
|
|
@@ -122,9 +122,9 @@ export interface FromHexDumpOptions {
|
|
|
122
122
|
*/
|
|
123
123
|
extensions?: CborExtension[];
|
|
124
124
|
}
|
|
125
|
-
export interface
|
|
125
|
+
export interface FromCDNOptions {
|
|
126
126
|
/**
|
|
127
|
-
* Character offset within the supplied text at which
|
|
127
|
+
* Character offset within the supplied text at which CDN parsing starts.
|
|
128
128
|
* Leading whitespace/comments at or after this offset are skipped as usual.
|
|
129
129
|
*
|
|
130
130
|
* @default 0
|
|
@@ -135,22 +135,22 @@ export interface FromEDNOptions {
|
|
|
135
135
|
*
|
|
136
136
|
* When `false`, parsing still requires the item to consume the remaining
|
|
137
137
|
* input, preserving the historical single-item behaviour. Set this to `true`
|
|
138
|
-
* when using `CborItem.end` to continue parsing a
|
|
139
|
-
* Top-level comma separators are not skipped by `
|
|
138
|
+
* when using `CborItem.end` to continue parsing a CDN sequence.
|
|
139
|
+
* Top-level comma separators are not skipped by `fromCDN()` itself; handle
|
|
140
140
|
* them in sequence-level code before passing the next `offset`. For example,
|
|
141
141
|
* after parsing `1, 2`, the first item's `end` points just before the comma;
|
|
142
142
|
* advance past that comma before parsing the next item.
|
|
143
143
|
*
|
|
144
144
|
* @example
|
|
145
145
|
* // Read two whitespace-separated items, validating that the second is last.
|
|
146
|
-
* const first = CBOR.
|
|
147
|
-
* const second = CBOR.
|
|
146
|
+
* const first = CBOR.fromCDN(text, { allowTrailing: true });
|
|
147
|
+
* const second = CBOR.fromCDN(text, { offset: first.end });
|
|
148
148
|
*
|
|
149
149
|
* @default false
|
|
150
150
|
*/
|
|
151
151
|
allowTrailing?: boolean;
|
|
152
152
|
/**
|
|
153
|
-
* Extension plugins for
|
|
153
|
+
* Extension plugins for CDN parsing.
|
|
154
154
|
* Each extension declares which app-string prefixes (and, in future, tag
|
|
155
155
|
* numbers) it handles via `appStringPrefixes` / `tagNumbers`, and provides
|
|
156
156
|
* callback methods that return `CborItem`-subclassed objects controlling
|
|
@@ -162,11 +162,11 @@ export interface FromEDNOptions {
|
|
|
162
162
|
extensions?: CborExtension[];
|
|
163
163
|
/**
|
|
164
164
|
* How to handle unrecognised application-extension identifiers
|
|
165
|
-
* (§4.1 draft-ietf-cbor-edn-literals-
|
|
165
|
+
* (§4.1 of draft-ietf-cbor-edn-literals-25).
|
|
166
166
|
*
|
|
167
167
|
* - `'cpa999'`: wrap the literal in a `CPA999` tag
|
|
168
168
|
* (`CborUnresolvedAppExt`) instead of failing. The resulting node
|
|
169
|
-
* round-trips through `
|
|
169
|
+
* round-trips through `toCDN()` back to the original notation.
|
|
170
170
|
* - `'error'`: throw `SyntaxError` for unknown prefixes.
|
|
171
171
|
* @default 'cpa999'
|
|
172
172
|
*/
|
|
@@ -184,16 +184,22 @@ export interface FromEDNOptions {
|
|
|
184
184
|
*/
|
|
185
185
|
allowInvalidUtf8?: boolean;
|
|
186
186
|
/**
|
|
187
|
-
* Preserve comments found between
|
|
187
|
+
* Preserve comments found between CDN values and attach them to the AST.
|
|
188
188
|
*
|
|
189
189
|
* Comments are metadata only: they are ignored by CBOR binary encoding and
|
|
190
|
-
* JavaScript conversion. Use together with `
|
|
191
|
-
* to include them when formatting back to
|
|
190
|
+
* JavaScript conversion. Use together with `ToCDNOptions.preserveComments`
|
|
191
|
+
* to include them when formatting back to CDN.
|
|
192
192
|
*
|
|
193
193
|
* @default false
|
|
194
194
|
*/
|
|
195
195
|
preserveComments?: boolean;
|
|
196
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Options for parsing Concise Diagnostic Notation (CDN).
|
|
199
|
+
*
|
|
200
|
+
* @deprecated Use `FromCDNOptions` instead.
|
|
201
|
+
*/
|
|
202
|
+
export type FromEDNOptions = FromCDNOptions;
|
|
197
203
|
export interface FromJSOptions {
|
|
198
204
|
/**
|
|
199
205
|
* Extension plugins applied during `fromJS()`.
|
|
@@ -238,7 +244,7 @@ export interface FromJSOptions {
|
|
|
238
244
|
*/
|
|
239
245
|
undefinedOmits?: boolean;
|
|
240
246
|
}
|
|
241
|
-
export interface
|
|
247
|
+
export interface ToCDNOptions {
|
|
242
248
|
/**
|
|
243
249
|
* Indentation for pretty-printing.
|
|
244
250
|
* - `number`: number of spaces
|
|
@@ -247,7 +253,7 @@ export interface ToEDNOptions {
|
|
|
247
253
|
*/
|
|
248
254
|
indent?: number | string;
|
|
249
255
|
/**
|
|
250
|
-
* Emit comments previously captured by `
|
|
256
|
+
* Emit comments previously captured by `FromCDNOptions.preserveComments`.
|
|
251
257
|
*
|
|
252
258
|
* When enabled for containers, comment-bearing arrays/maps are emitted in
|
|
253
259
|
* multi-line form even if `indent` is omitted.
|
|
@@ -256,7 +262,7 @@ export interface ToEDNOptions {
|
|
|
256
262
|
*/
|
|
257
263
|
preserveComments?: boolean;
|
|
258
264
|
/**
|
|
259
|
-
* Re-emit byte string literals parsed from
|
|
265
|
+
* Re-emit byte string literals parsed from CDN using their original source
|
|
260
266
|
* text when available.
|
|
261
267
|
*
|
|
262
268
|
* This preserves the spelling and interior layout of non-concatenated
|
|
@@ -308,7 +314,7 @@ export interface ToEDNOptions {
|
|
|
308
314
|
*/
|
|
309
315
|
appStrings?: boolean;
|
|
310
316
|
/**
|
|
311
|
-
* Numeric format for integer values in
|
|
317
|
+
* Numeric format for integer values in CDN output.
|
|
312
318
|
* - `'decimal'`: standard decimal notation (e.g. `42`, `-14159024`)
|
|
313
319
|
* - `'hex'`: hexadecimal notation (e.g. `0x2a`, `-0xd83130`)
|
|
314
320
|
* - `'octal'`: octal notation (e.g. `0o52`, `-0o67061560`)
|
|
@@ -317,25 +323,35 @@ export interface ToEDNOptions {
|
|
|
317
323
|
*/
|
|
318
324
|
intFormat?: 'decimal' | 'hex' | 'octal' | 'binary';
|
|
319
325
|
/**
|
|
320
|
-
* Numeric format for floating-point values in
|
|
326
|
+
* Numeric format for floating-point values in CDN output.
|
|
321
327
|
* - `'decimal'`: standard decimal notation (e.g. `1.5`, `145544.0_3`)
|
|
322
328
|
* - `'hex'`: C99-style hex float notation (e.g. `0x1.8p+0`, `0x1.1c54p+17_3`)
|
|
323
329
|
* @default 'decimal'
|
|
324
330
|
*/
|
|
325
331
|
floatFormat?: 'decimal' | 'hex';
|
|
326
332
|
/**
|
|
327
|
-
* Split long text strings using
|
|
333
|
+
* Split long text strings using CDN string concatenation syntax (`"a" + "b"`).
|
|
328
334
|
* Only effective when `indent` is specified.
|
|
329
335
|
*
|
|
330
336
|
* - `'newline'`: split at newline characters
|
|
331
|
-
* - `'
|
|
332
|
-
* is parseable as
|
|
337
|
+
* - `'cdn'`: split according to CDN structure when the string content
|
|
338
|
+
* is parseable as CDN (JSON superset)
|
|
339
|
+
* - `'cboredn'`: deprecated alias for `'cdn'`
|
|
333
340
|
*
|
|
334
|
-
* When both are specified,
|
|
341
|
+
* When both are specified, CDN structure split points are combined with
|
|
335
342
|
* newline split points.
|
|
336
343
|
*/
|
|
337
|
-
textStringFormat?:
|
|
344
|
+
textStringFormat?: TextStringFormat[];
|
|
338
345
|
}
|
|
346
|
+
export type TextStringFormat = 'newline' | 'cdn' | DeprecatedTextStringFormat;
|
|
347
|
+
/** @deprecated Use `'cdn'` instead. */
|
|
348
|
+
export type DeprecatedTextStringFormat = 'cboredn';
|
|
349
|
+
/**
|
|
350
|
+
* Options for serializing Concise Diagnostic Notation (CDN).
|
|
351
|
+
*
|
|
352
|
+
* @deprecated Use `ToCDNOptions` instead.
|
|
353
|
+
*/
|
|
354
|
+
export type ToEDNOptions = ToCDNOptions;
|
|
339
355
|
export interface CborComment {
|
|
340
356
|
kind: 'line' | 'block';
|
|
341
357
|
marker: '#' | '//' | '/*' | '/';
|
|
@@ -359,4 +375,4 @@ export interface CborComments {
|
|
|
359
375
|
* Note: `encodeIntegerAs` (from {@link FromJSOptions}) and `integerAs` (from
|
|
360
376
|
* {@link ToJSOptions}) are distinct fields and do not conflict.
|
|
361
377
|
*/
|
|
362
|
-
export type CBOROptions =
|
|
378
|
+
export type CBOROptions = FromCDNOptions & FromJSOptions & ToCBOROptions & ToCDNOptions & ToJSOptions & ToHexDumpOptions;
|
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
|
|
7
|
+
* This notation appears in CDN (draft-ietf-cbor-edn-literals-25) as an
|
|
8
8
|
* alternative representation for floating-point values (major type 7).
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
export declare function parseHexFloat(s: string): number;
|
|
18
18
|
/**
|
|
19
19
|
* Convert a JS number to a normalized hex float string compatible with
|
|
20
|
-
*
|
|
20
|
+
* CDN diagnostic notation.
|
|
21
21
|
*
|
|
22
22
|
* - Normal values: `0x1.[hex fraction]p[+-][exp]` (e.g. `0x1.8p+0` for 1.5)
|
|
23
23
|
* - Subnormal values: `0x0.[hex fraction]p-1022`
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cbortech/cbor",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Convert between CBOR,
|
|
3
|
+
"version": "0.25.0",
|
|
4
|
+
"description": "Convert between CBOR, CDN, and JavaScript values",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cbor",
|
|
7
|
+
"cdn",
|
|
7
8
|
"cbor-edn",
|
|
8
|
-
"edn",
|
|
9
9
|
"diagnostic-notation",
|
|
10
10
|
"json",
|
|
11
11
|
"jsonc",
|
|
@@ -82,16 +82,16 @@
|
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@types/node": "^24.12.4",
|
|
85
|
-
"@vitest/browser": "^4.1.
|
|
86
|
-
"@vitest/browser-playwright": "^4.1.
|
|
87
|
-
"@vitest/coverage-v8": "^4.1.
|
|
88
|
-
"@vitest/ui": "^4.1.
|
|
85
|
+
"@vitest/browser": "^4.1.7",
|
|
86
|
+
"@vitest/browser-playwright": "^4.1.7",
|
|
87
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
88
|
+
"@vitest/ui": "^4.1.7",
|
|
89
89
|
"cross-env": "^10.1.0",
|
|
90
90
|
"playwright": "^1.60.0",
|
|
91
91
|
"prettier": "^3.8.3",
|
|
92
92
|
"typescript": "^5.9.3",
|
|
93
|
-
"vite": "^8.0.
|
|
93
|
+
"vite": "^8.0.13",
|
|
94
94
|
"vite-plugin-dts": "^4.5.4",
|
|
95
|
-
"vitest": "^4.1.
|
|
95
|
+
"vitest": "^4.1.7"
|
|
96
96
|
}
|
|
97
97
|
}
|
package/dist/edn/parser.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CborItem } from '../ast/CborItem';
|
|
2
|
-
import { FromEDNOptions } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Parse a CBOR-EDN diagnostic notation string into a CborItem AST node.
|
|
5
|
-
* Throws SyntaxError on invalid input.
|
|
6
|
-
*/
|
|
7
|
-
export declare function parseEDN(text: string, options?: FromEDNOptions): CborItem;
|
package/dist/edn/serializer.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CborItem } from '../ast/CborItem';
|
|
2
|
-
import { ToEDNOptions } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Serialize a CborItem AST node to CBOR-EDN diagnostic notation.
|
|
5
|
-
* Equivalent to calling value.toEDN(options) directly.
|
|
6
|
-
*/
|
|
7
|
-
export declare function toEDN(value: CborItem, options?: ToEDNOptions): string;
|