@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/README.ja.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @cbortech/cbor
|
|
2
2
|
|
|
3
|
-
[CBOR](#準拠している仕様)、[
|
|
3
|
+
[CBOR](#準拠している仕様)、[CDN](#準拠している仕様)、JavaScript 値を相互変換するための TypeScript ライブラリです。
|
|
4
4
|
|
|
5
5
|
このパッケージは `CBOR` ファサードに加えて、extension の実装に必要な CBOR AST ノードクラス用の entrypoint を公開します。
|
|
6
6
|
低レベルのパーサー、エンコーダー内部は、ドキュメント上の公開 API には含めていません。
|
|
@@ -52,31 +52,29 @@ console.log(value);
|
|
|
52
52
|
// { hello: 'world', n: 42 }
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
### CBOR バイト列から
|
|
55
|
+
### CBOR バイト列から CDN へ
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
58
|
import { CBOR } from '@cbortech/cbor';
|
|
59
59
|
|
|
60
|
-
const text = CBOR.fromCBOR(
|
|
61
|
-
new Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
62
|
-
).toEDN();
|
|
60
|
+
const text = CBOR.fromCBOR(new Uint8Array([0x83, 0x01, 0x02, 0x03])).toCDN();
|
|
63
61
|
|
|
64
62
|
console.log(text);
|
|
65
63
|
// [1,2,3]
|
|
66
64
|
```
|
|
67
65
|
|
|
68
|
-
###
|
|
66
|
+
### CDN から CBOR バイト列へ
|
|
69
67
|
|
|
70
68
|
```ts
|
|
71
69
|
import { CBOR } from '@cbortech/cbor';
|
|
72
70
|
|
|
73
|
-
const bytes = CBOR.
|
|
71
|
+
const bytes = CBOR.fromCDN('[1, 2, 3]').toCBOR();
|
|
74
72
|
|
|
75
73
|
console.log(bytes);
|
|
76
74
|
// Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
77
75
|
```
|
|
78
76
|
|
|
79
|
-
### JavaScript から
|
|
77
|
+
### JavaScript から CDN へ
|
|
80
78
|
|
|
81
79
|
```ts
|
|
82
80
|
import { CBOR } from '@cbortech/cbor';
|
|
@@ -87,7 +85,7 @@ console.log(text);
|
|
|
87
85
|
// {"a":1,"b":true,"c":null}
|
|
88
86
|
```
|
|
89
87
|
|
|
90
|
-
### 読みやすい
|
|
88
|
+
### 読みやすい CDN を出力する
|
|
91
89
|
|
|
92
90
|
```ts
|
|
93
91
|
import { CBOR } from '@cbortech/cbor';
|
|
@@ -105,7 +103,7 @@ console.log(text);
|
|
|
105
103
|
// }
|
|
106
104
|
```
|
|
107
105
|
|
|
108
|
-
###
|
|
106
|
+
### CDN から JavaScript へ
|
|
109
107
|
|
|
110
108
|
```ts
|
|
111
109
|
import { CBOR } from '@cbortech/cbor';
|
|
@@ -116,7 +114,7 @@ console.log(value);
|
|
|
116
114
|
// [1, Uint8Array(...), true, null]
|
|
117
115
|
```
|
|
118
116
|
|
|
119
|
-
###
|
|
117
|
+
### CDN を正規化する
|
|
120
118
|
|
|
121
119
|
```ts
|
|
122
120
|
import { CBOR } from '@cbortech/cbor';
|
|
@@ -135,7 +133,7 @@ console.log(text);
|
|
|
135
133
|
|
|
136
134
|
### テキスト文字列を分割して整形する
|
|
137
135
|
|
|
138
|
-
`textStringFormat` を使うと、長いテキスト文字列を
|
|
136
|
+
`textStringFormat` を使うと、長いテキスト文字列を CDN の文字列連結として分割できます。
|
|
139
137
|
このオプションは `indent` を指定したときに適用されます。
|
|
140
138
|
|
|
141
139
|
```ts
|
|
@@ -154,19 +152,19 @@ console.log(text);
|
|
|
154
152
|
// }
|
|
155
153
|
```
|
|
156
154
|
|
|
157
|
-
文字列の中身が
|
|
155
|
+
文字列の中身が CDN や JSON 風の内容なら、`cdn` を使えます。
|
|
158
156
|
|
|
159
157
|
```ts
|
|
160
158
|
import { CBOR } from '@cbortech/cbor';
|
|
161
159
|
|
|
162
|
-
const text = CBOR.format('{"
|
|
160
|
+
const text = CBOR.format('{"cdn": "[1,2,3]"}', {
|
|
163
161
|
indent: 2,
|
|
164
|
-
textStringFormat: ['
|
|
162
|
+
textStringFormat: ['cdn'],
|
|
165
163
|
});
|
|
166
164
|
|
|
167
165
|
console.log(text);
|
|
168
166
|
// {
|
|
169
|
-
// "
|
|
167
|
+
// "cdn": "[" +
|
|
170
168
|
// "1," +
|
|
171
169
|
// "2," +
|
|
172
170
|
// "3" +
|
|
@@ -176,7 +174,7 @@ console.log(text);
|
|
|
176
174
|
|
|
177
175
|
## AST を扱う
|
|
178
176
|
|
|
179
|
-
`CBOR.fromCBOR()`、`CBOR.
|
|
177
|
+
`CBOR.fromCBOR()`、`CBOR.fromCDN()`、`CBOR.fromJS()` は CBOR item を返します。
|
|
180
178
|
`CborTextString`、`CborByteString`、`CborArray`、`CborTag` などの具体的なノードクラスは、
|
|
181
179
|
extension 向けに `@cbortech/cbor/ast` から export されています。すべての item は次のメソッドを持ちます。
|
|
182
180
|
|
|
@@ -184,11 +182,11 @@ extension 向けに `@cbortech/cbor/ast` から export されています。す
|
|
|
184
182
|
import { CBOR } from '@cbortech/cbor';
|
|
185
183
|
import { CborItem } from '@cbortech/cbor/ast';
|
|
186
184
|
|
|
187
|
-
const item = CBOR.
|
|
185
|
+
const item = CBOR.fromCDN('{ "x": 1 }');
|
|
188
186
|
item satisfies CborItem;
|
|
189
187
|
|
|
190
188
|
const bytes = item.toCBOR();
|
|
191
|
-
const text = item.
|
|
189
|
+
const text = item.toCDN();
|
|
192
190
|
const value = item.toJS();
|
|
193
191
|
```
|
|
194
192
|
|
|
@@ -197,23 +195,23 @@ const value = item.toJS();
|
|
|
197
195
|
```ts
|
|
198
196
|
import { CBOR } from '@cbortech/cbor';
|
|
199
197
|
|
|
200
|
-
const item = CBOR.
|
|
198
|
+
const item = CBOR.fromCDN('[_ 1, 2, 3]');
|
|
201
199
|
|
|
202
|
-
console.log(item.
|
|
200
|
+
console.log(item.toCDN());
|
|
203
201
|
// [_ 1,2,3]
|
|
204
202
|
|
|
205
203
|
console.log(item.toCBOR());
|
|
206
204
|
// Uint8Array(...)
|
|
207
205
|
```
|
|
208
206
|
|
|
209
|
-
### CBOR を AST としてデコードし、
|
|
207
|
+
### CBOR を AST としてデコードし、CDN として確認する
|
|
210
208
|
|
|
211
209
|
```ts
|
|
212
210
|
import { CBOR } from '@cbortech/cbor';
|
|
213
211
|
|
|
214
212
|
const item = CBOR.fromCBOR(new Uint8Array([0x83, 0x01, 0x02, 0x03]));
|
|
215
213
|
|
|
216
|
-
console.log(item.
|
|
214
|
+
console.log(item.toCDN());
|
|
217
215
|
// [1,2,3]
|
|
218
216
|
|
|
219
217
|
console.log(item.toJS());
|
|
@@ -301,7 +299,7 @@ console.log(cbor.stringify({ value }));
|
|
|
301
299
|
|
|
302
300
|
## 日時
|
|
303
301
|
|
|
304
|
-
|
|
302
|
+
CDN の `dt'...'` と `DT'...'` リテラルは、デフォルトでパースできます。
|
|
305
303
|
JavaScript の `Date` オブジェクトとして扱いたい場合は `CBOR.dt_as_Date` を追加します。
|
|
306
304
|
|
|
307
305
|
```ts
|
|
@@ -331,11 +329,11 @@ console.log(text);
|
|
|
331
329
|
追加の application extension は別パッケージとして公開されています。必要なものを
|
|
332
330
|
インストールし、`extensions` オプションに渡して使います。
|
|
333
331
|
|
|
334
|
-
`hash` は
|
|
332
|
+
`hash` は CDN の仕様に含まれる application extension ですが、利用には
|
|
335
333
|
外部パッケージが必要です。そのため、このパッケージ本体には含めず、
|
|
336
334
|
`@cbortech/hash-extension` として提供しています。
|
|
337
335
|
|
|
338
|
-
`uuid` は
|
|
336
|
+
`uuid` は CDN の仕様には定められていない、このライブラリ独自の
|
|
339
337
|
application extension です。仕様上の標準機能と区別するため、
|
|
340
338
|
`@cbortech/uuid-extension` として別パッケージで提供しています。
|
|
341
339
|
|
|
@@ -352,12 +350,12 @@ const cbor = new CBOR({
|
|
|
352
350
|
extensions: [hashExtension, uuidExtension],
|
|
353
351
|
});
|
|
354
352
|
|
|
355
|
-
const digest = cbor.
|
|
356
|
-
console.log(digest.
|
|
353
|
+
const digest = cbor.fromCDN("hash'foo'");
|
|
354
|
+
console.log(digest.toCDN());
|
|
357
355
|
// hash'foo'
|
|
358
356
|
|
|
359
|
-
const id = cbor.
|
|
360
|
-
console.log(id.
|
|
357
|
+
const id = cbor.fromCDN("uuid'550e8400-e29b-41d4-a716-446655440000'");
|
|
358
|
+
console.log(id.toCDN());
|
|
361
359
|
// uuid'550e8400-e29b-41d4-a716-446655440000'
|
|
362
360
|
```
|
|
363
361
|
|
|
@@ -471,7 +469,7 @@ CBOR item は注釈付き hex dump の生成とパースに対応しています
|
|
|
471
469
|
```ts
|
|
472
470
|
import { CBOR } from '@cbortech/cbor';
|
|
473
471
|
|
|
474
|
-
const item = CBOR.
|
|
472
|
+
const item = CBOR.fromCDN('[_ 1, [2, 3]]');
|
|
475
473
|
const dump = item.toHexDump();
|
|
476
474
|
|
|
477
475
|
console.log(dump);
|
|
@@ -489,7 +487,7 @@ const item = CBOR.fromHexDump(`
|
|
|
489
487
|
03 -- 3
|
|
490
488
|
`);
|
|
491
489
|
|
|
492
|
-
console.log(item.
|
|
490
|
+
console.log(item.toCDN());
|
|
493
491
|
// [1,2,3]
|
|
494
492
|
```
|
|
495
493
|
|
|
@@ -512,19 +510,19 @@ console.log(item.toEDN());
|
|
|
512
510
|
このライブラリは次の仕様を対象にしています。
|
|
513
511
|
|
|
514
512
|
- [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
|
|
515
|
-
- [
|
|
513
|
+
- [Concise Diagnostic Notation (CDN), draft-ietf-cbor-edn-literals-25](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/)
|
|
516
514
|
|
|
517
|
-
|
|
515
|
+
CDN は、CBOR データを人間が読み書きしやすいテキストとして表現するための記法です。
|
|
518
516
|
サンプル、テストベクター、デバッグ、fixture、設定ファイルに近い用途など、CBOR のバイト列をそのまま扱うと読みにくい場面で役立ちます。
|
|
519
517
|
|
|
520
518
|
通常の配列、マップ、文字列、数値、真偽値、null は JSON に近い見た目で書けます。
|
|
521
519
|
一方で、CBOR 固有の byte string、tag、simple value、不定長 item、文字列以外の map key、
|
|
522
520
|
`dt'2026-05-06T00:00:00Z'` のような application literal も表現できます。
|
|
523
521
|
|
|
524
|
-
|
|
525
|
-
特別な変換なしに
|
|
522
|
+
CDN は JSON / JSONC の上位互換なので、通常の JSON データやコメント付きの JSON 風データも、
|
|
523
|
+
特別な変換なしに CDN としてパース・整形できます。
|
|
526
524
|
|
|
527
|
-
|
|
525
|
+
CDN はまだ広く普及した RFC ではなく、Internet-Draft として策定中の仕様です。
|
|
528
526
|
|
|
529
527
|
## ライセンス
|
|
530
528
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @cbortech/cbor
|
|
2
2
|
|
|
3
3
|
TypeScript library for converting between [CBOR](#specifications),
|
|
4
|
-
[
|
|
4
|
+
[CDN](#specifications), and JavaScript values.
|
|
5
5
|
|
|
6
6
|
This package exposes the `CBOR` facade plus a separate AST entrypoint for the
|
|
7
7
|
CBOR node classes needed by extensions. Lower-level parser and encoder internals
|
|
@@ -54,31 +54,29 @@ console.log(value);
|
|
|
54
54
|
// { hello: 'world', n: 42 }
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
### CBOR bytes to
|
|
57
|
+
### CBOR bytes to CDN
|
|
58
58
|
|
|
59
59
|
```ts
|
|
60
60
|
import { CBOR } from '@cbortech/cbor';
|
|
61
61
|
|
|
62
|
-
const text = CBOR.fromCBOR(
|
|
63
|
-
new Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
64
|
-
).toEDN();
|
|
62
|
+
const text = CBOR.fromCBOR(new Uint8Array([0x83, 0x01, 0x02, 0x03])).toCDN();
|
|
65
63
|
|
|
66
64
|
console.log(text);
|
|
67
65
|
// [1,2,3]
|
|
68
66
|
```
|
|
69
67
|
|
|
70
|
-
###
|
|
68
|
+
### CDN to CBOR bytes
|
|
71
69
|
|
|
72
70
|
```ts
|
|
73
71
|
import { CBOR } from '@cbortech/cbor';
|
|
74
72
|
|
|
75
|
-
const bytes = CBOR.
|
|
73
|
+
const bytes = CBOR.fromCDN('[1, 2, 3]').toCBOR();
|
|
76
74
|
|
|
77
75
|
console.log(bytes);
|
|
78
76
|
// Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
79
77
|
```
|
|
80
78
|
|
|
81
|
-
### JavaScript to
|
|
79
|
+
### JavaScript to CDN
|
|
82
80
|
|
|
83
81
|
```ts
|
|
84
82
|
import { CBOR } from '@cbortech/cbor';
|
|
@@ -89,7 +87,7 @@ console.log(text);
|
|
|
89
87
|
// {"a":1,"b":true,"c":null}
|
|
90
88
|
```
|
|
91
89
|
|
|
92
|
-
### Pretty
|
|
90
|
+
### Pretty CDN
|
|
93
91
|
|
|
94
92
|
```ts
|
|
95
93
|
import { CBOR } from '@cbortech/cbor';
|
|
@@ -107,7 +105,7 @@ console.log(text);
|
|
|
107
105
|
// }
|
|
108
106
|
```
|
|
109
107
|
|
|
110
|
-
###
|
|
108
|
+
### CDN to JavaScript
|
|
111
109
|
|
|
112
110
|
```ts
|
|
113
111
|
import { CBOR } from '@cbortech/cbor';
|
|
@@ -118,7 +116,7 @@ console.log(value);
|
|
|
118
116
|
// [1, Uint8Array(...), true, null]
|
|
119
117
|
```
|
|
120
118
|
|
|
121
|
-
### Normalize
|
|
119
|
+
### Normalize CDN
|
|
122
120
|
|
|
123
121
|
```ts
|
|
124
122
|
import { CBOR } from '@cbortech/cbor';
|
|
@@ -137,7 +135,7 @@ console.log(text);
|
|
|
137
135
|
|
|
138
136
|
### Split text strings while formatting
|
|
139
137
|
|
|
140
|
-
`textStringFormat` can split long text strings with
|
|
138
|
+
`textStringFormat` can split long text strings with CDN string concatenation.
|
|
141
139
|
It is applied when `indent` is specified.
|
|
142
140
|
|
|
143
141
|
```ts
|
|
@@ -156,19 +154,19 @@ console.log(text);
|
|
|
156
154
|
// }
|
|
157
155
|
```
|
|
158
156
|
|
|
159
|
-
For strings that contain
|
|
157
|
+
For strings that contain CDN or JSON-like content, use `cdn`.
|
|
160
158
|
|
|
161
159
|
```ts
|
|
162
160
|
import { CBOR } from '@cbortech/cbor';
|
|
163
161
|
|
|
164
|
-
const text = CBOR.format('{"
|
|
162
|
+
const text = CBOR.format('{"cdn": "[1,2,3]"}', {
|
|
165
163
|
indent: 2,
|
|
166
|
-
textStringFormat: ['
|
|
164
|
+
textStringFormat: ['cdn'],
|
|
167
165
|
});
|
|
168
166
|
|
|
169
167
|
console.log(text);
|
|
170
168
|
// {
|
|
171
|
-
// "
|
|
169
|
+
// "cdn": "[" +
|
|
172
170
|
// "1," +
|
|
173
171
|
// "2," +
|
|
174
172
|
// "3" +
|
|
@@ -178,7 +176,7 @@ console.log(text);
|
|
|
178
176
|
|
|
179
177
|
## Working With The AST
|
|
180
178
|
|
|
181
|
-
`CBOR.fromCBOR()`, `CBOR.
|
|
179
|
+
`CBOR.fromCBOR()`, `CBOR.fromCDN()`, and `CBOR.fromJS()` return a CBOR item.
|
|
182
180
|
Concrete node classes such as `CborTextString`, `CborByteString`, `CborArray`,
|
|
183
181
|
and `CborTag` are exported from `@cbortech/cbor/ast` for extensions. Every item
|
|
184
182
|
supports these methods:
|
|
@@ -187,11 +185,11 @@ supports these methods:
|
|
|
187
185
|
import { CBOR } from '@cbortech/cbor';
|
|
188
186
|
import { CborItem } from '@cbortech/cbor/ast';
|
|
189
187
|
|
|
190
|
-
const item = CBOR.
|
|
188
|
+
const item = CBOR.fromCDN('{ "x": 1 }');
|
|
191
189
|
item satisfies CborItem;
|
|
192
190
|
|
|
193
191
|
const bytes = item.toCBOR();
|
|
194
|
-
const text = item.
|
|
192
|
+
const text = item.toCDN();
|
|
195
193
|
const value = item.toJS();
|
|
196
194
|
```
|
|
197
195
|
|
|
@@ -200,23 +198,23 @@ const value = item.toJS();
|
|
|
200
198
|
```ts
|
|
201
199
|
import { CBOR } from '@cbortech/cbor';
|
|
202
200
|
|
|
203
|
-
const item = CBOR.
|
|
201
|
+
const item = CBOR.fromCDN('[_ 1, 2, 3]');
|
|
204
202
|
|
|
205
|
-
console.log(item.
|
|
203
|
+
console.log(item.toCDN());
|
|
206
204
|
// [_ 1,2,3]
|
|
207
205
|
|
|
208
206
|
console.log(item.toCBOR());
|
|
209
207
|
// Uint8Array(...)
|
|
210
208
|
```
|
|
211
209
|
|
|
212
|
-
### Decode to AST, then inspect as
|
|
210
|
+
### Decode to AST, then inspect as CDN
|
|
213
211
|
|
|
214
212
|
```ts
|
|
215
213
|
import { CBOR } from '@cbortech/cbor';
|
|
216
214
|
|
|
217
215
|
const item = CBOR.fromCBOR(new Uint8Array([0x83, 0x01, 0x02, 0x03]));
|
|
218
216
|
|
|
219
|
-
console.log(item.
|
|
217
|
+
console.log(item.toCDN());
|
|
220
218
|
// [1,2,3]
|
|
221
219
|
|
|
222
220
|
console.log(item.toJS());
|
|
@@ -305,7 +303,7 @@ console.log(cbor.stringify({ value }));
|
|
|
305
303
|
|
|
306
304
|
## Dates
|
|
307
305
|
|
|
308
|
-
|
|
306
|
+
CDN `dt'...'` and `DT'...'` literals are parsed by default. Add `CBOR.dt_as_Date`
|
|
309
307
|
when you want JavaScript `Date` objects.
|
|
310
308
|
|
|
311
309
|
```ts
|
|
@@ -335,12 +333,12 @@ console.log(text);
|
|
|
335
333
|
Additional application extensions are published as separate packages. Install
|
|
336
334
|
the ones you need and pass them through the `extensions` option.
|
|
337
335
|
|
|
338
|
-
`hash` is an application extension defined by the
|
|
336
|
+
`hash` is an application extension defined by the CDN specification, but
|
|
339
337
|
it requires an external package. For that reason, it is not bundled with this
|
|
340
338
|
package and is provided separately as `@cbortech/hash-extension`.
|
|
341
339
|
|
|
342
340
|
`uuid` is a library-specific application extension that is not defined by the
|
|
343
|
-
|
|
341
|
+
CDN specification. To keep it distinct from standard CDN features, it
|
|
344
342
|
is provided separately as `@cbortech/uuid-extension`.
|
|
345
343
|
|
|
346
344
|
```bash
|
|
@@ -356,12 +354,12 @@ const cbor = new CBOR({
|
|
|
356
354
|
extensions: [hashExtension, uuidExtension],
|
|
357
355
|
});
|
|
358
356
|
|
|
359
|
-
const digest = cbor.
|
|
360
|
-
console.log(digest.
|
|
357
|
+
const digest = cbor.fromCDN("hash'foo'");
|
|
358
|
+
console.log(digest.toCDN());
|
|
361
359
|
// hash'foo'
|
|
362
360
|
|
|
363
|
-
const id = cbor.
|
|
364
|
-
console.log(id.
|
|
361
|
+
const id = cbor.fromCDN("uuid'550e8400-e29b-41d4-a716-446655440000'");
|
|
362
|
+
console.log(id.toCDN());
|
|
365
363
|
// uuid'550e8400-e29b-41d4-a716-446655440000'
|
|
366
364
|
```
|
|
367
365
|
|
|
@@ -477,7 +475,7 @@ CBOR items can produce and parse annotated hex dumps.
|
|
|
477
475
|
```ts
|
|
478
476
|
import { CBOR } from '@cbortech/cbor';
|
|
479
477
|
|
|
480
|
-
const item = CBOR.
|
|
478
|
+
const item = CBOR.fromCDN('[_ 1, [2, 3]]');
|
|
481
479
|
const dump = item.toHexDump();
|
|
482
480
|
|
|
483
481
|
console.log(dump);
|
|
@@ -495,7 +493,7 @@ const item = CBOR.fromHexDump(`
|
|
|
495
493
|
03 -- 3
|
|
496
494
|
`);
|
|
497
495
|
|
|
498
|
-
console.log(item.
|
|
496
|
+
console.log(item.toCDN());
|
|
499
497
|
// [1,2,3]
|
|
500
498
|
```
|
|
501
499
|
|
|
@@ -518,9 +516,9 @@ The `CBOR` facade also exposes:
|
|
|
518
516
|
This library targets:
|
|
519
517
|
|
|
520
518
|
- [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
|
|
521
|
-
- [
|
|
519
|
+
- [Concise Diagnostic Notation (CDN), draft-ietf-cbor-edn-literals-25](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/25/)
|
|
522
520
|
|
|
523
|
-
|
|
521
|
+
CDN is a human-readable text notation for CBOR data. It is useful for
|
|
524
522
|
examples, test vectors, debugging, fixtures, and configuration-like files where
|
|
525
523
|
raw CBOR bytes would be hard to read.
|
|
526
524
|
|
|
@@ -529,11 +527,11 @@ and null values, but it can also represent CBOR-specific features such as byte
|
|
|
529
527
|
strings, tags, simple values, indefinite-length items, non-string map keys, and
|
|
530
528
|
application literals like `dt'2026-05-06T00:00:00Z'`.
|
|
531
529
|
|
|
532
|
-
|
|
533
|
-
commented JSON-style data can be parsed and formatted as
|
|
530
|
+
CDN is a superset of JSON and JSONC, so ordinary JSON data and
|
|
531
|
+
commented JSON-style data can be parsed and formatted as CDN without
|
|
534
532
|
special handling.
|
|
535
533
|
|
|
536
|
-
|
|
534
|
+
CDN is still an Internet-Draft rather than a widely deployed RFC.
|
|
537
535
|
|
|
538
536
|
## License
|
|
539
537
|
|
package/dist/ast/CborArray.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 4 — array (definite- or indefinite-length). */
|
|
@@ -11,7 +11,7 @@ export declare class CborArray 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/CborBignum.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions } from '../types';
|
|
2
2
|
import { CborTag } from './CborTag';
|
|
3
3
|
export declare const BIGNUM_UINT_TAG = 2n;
|
|
4
4
|
export declare const BIGNUM_NINT_TAG = 3n;
|
|
@@ -15,22 +15,22 @@ export declare function bytesToBigint(bytes: Uint8Array): bigint;
|
|
|
15
15
|
/**
|
|
16
16
|
* Unsigned bignum — integers ≥ 2^64.
|
|
17
17
|
* Wire format: tag(2, big-endian byte string).
|
|
18
|
-
*
|
|
18
|
+
* toCDN() emits the plain decimal integer.
|
|
19
19
|
*/
|
|
20
20
|
export declare class CborBigUint extends CborTag {
|
|
21
21
|
readonly bigValue: bigint;
|
|
22
22
|
constructor(value: bigint);
|
|
23
|
-
|
|
23
|
+
_toCDN(_options: ToCDNOptions | undefined, _depth: number): string;
|
|
24
24
|
_toJS(_options?: ToJSOptions): bigint;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Negative bignum — integers ≤ -(2^64 + 1).
|
|
28
28
|
* Wire format: tag(3, big-endian byte string of (-1 - value)).
|
|
29
|
-
*
|
|
29
|
+
* toCDN() emits the plain decimal integer.
|
|
30
30
|
*/
|
|
31
31
|
export declare class CborBigNint extends CborTag {
|
|
32
32
|
readonly bigValue: bigint;
|
|
33
33
|
constructor(value: bigint);
|
|
34
|
-
|
|
34
|
+
_toCDN(_options: ToCDNOptions | undefined, _depth: number): string;
|
|
35
35
|
_toJS(_options?: ToJSOptions): bigint;
|
|
36
36
|
}
|
|
@@ -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 2 — definite-length byte string. */
|
|
@@ -15,6 +15,6 @@ export declare class CborByteString extends CborItem {
|
|
|
15
15
|
ednSource?: string;
|
|
16
16
|
});
|
|
17
17
|
_toCBOR(_options?: ToCBOROptions): Uint8Array;
|
|
18
|
-
|
|
18
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
19
19
|
_toJS(_options?: ToJSOptions): unknown;
|
|
20
20
|
}
|
|
@@ -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
|
export declare const CPA888_TAG = 888n;
|
|
@@ -7,5 +7,5 @@ export declare class CborEllipsis extends CborTag {
|
|
|
7
7
|
constructor();
|
|
8
8
|
/** String/bytes elision: 888([items...]) */
|
|
9
9
|
constructor(items: CborItem[]);
|
|
10
|
-
|
|
10
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
11
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
3
|
/**
|
|
4
4
|
* CBOR Sequence Literal (§2.5.6) — `<<item, item, ...>>`.
|
|
@@ -16,7 +16,7 @@ export declare class CborEmbeddedCBOR extends CborItem {
|
|
|
16
16
|
/** The raw concatenated CBOR bytes of all contained items. */
|
|
17
17
|
private _content;
|
|
18
18
|
_toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
19
|
-
|
|
20
|
-
_toHexDump(depth: number, options?:
|
|
19
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number): string;
|
|
20
|
+
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
21
21
|
_toJS(_options?: ToJSOptions): unknown;
|
|
22
22
|
}
|
package/dist/ast/CborFloat.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem } from './CborItem';
|
|
3
3
|
export type FloatPrecision = 'half' | 'single' | 'double';
|
|
4
4
|
/**
|
|
@@ -22,6 +22,6 @@ export declare class CborFloat extends CborItem {
|
|
|
22
22
|
precision?: FloatPrecision;
|
|
23
23
|
});
|
|
24
24
|
_toCBOR(_options?: ToCBOROptions): Uint8Array;
|
|
25
|
-
|
|
25
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
26
26
|
_toJS(_options?: ToJSOptions): unknown;
|
|
27
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
3
|
import { CborByteString } from './CborByteString';
|
|
4
4
|
/** CBOR Major Type 2 — indefinite-length byte string (chunked). */
|
|
@@ -7,7 +7,7 @@ export declare class CborIndefiniteByteString extends CborItem {
|
|
|
7
7
|
readonly chunks: CborByteString[];
|
|
8
8
|
constructor(chunks: CborByteString[]);
|
|
9
9
|
_toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
10
|
-
|
|
11
|
-
_toHexDump(depth: number, options?:
|
|
10
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
11
|
+
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
12
12
|
_toJS(_options?: ToJSOptions): unknown;
|
|
13
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToCDNOptions, ToJSOptions, ToCBOROptions } from '../types';
|
|
2
2
|
import { CborItem, AnnotatedLine } from './CborItem';
|
|
3
3
|
import { CborTextString } from './CborTextString';
|
|
4
4
|
/** CBOR Major Type 3 — indefinite-length UTF-8 text string (chunked). */
|
|
@@ -7,7 +7,7 @@ export declare class CborIndefiniteTextString extends CborItem {
|
|
|
7
7
|
readonly chunks: CborTextString[];
|
|
8
8
|
constructor(chunks: CborTextString[]);
|
|
9
9
|
_toCBOR(options?: ToCBOROptions): Uint8Array;
|
|
10
|
-
|
|
11
|
-
_toHexDump(depth: number, options?:
|
|
10
|
+
_toCDN(options: ToCDNOptions | undefined, _depth: number): string;
|
|
11
|
+
_toHexDump(depth: number, options?: ToCDNOptions): AnnotatedLine[];
|
|
12
12
|
_toJS(_options?: ToJSOptions): unknown;
|
|
13
13
|
}
|