cborg 1.6.1 → 1.8.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.
@@ -4,12 +4,63 @@ import chai from 'chai'
4
4
  import { exec } from 'child_process'
5
5
  import process from 'process'
6
6
  import path from 'path'
7
+ import { platform } from 'os'
7
8
  import { fileURLToPath } from 'url'
8
9
  // included here for ipjs compile tree
9
10
  import bin from '../lib/bin.js' // eslint-disable-line
10
11
 
11
12
  const { assert } = chai
12
13
 
14
+ const fixture1JsonString = '{"a":1,"b":[2,3],"smile":"😀"}'
15
+ const fixture1JsonPrettyString =
16
+ `{
17
+ "a": 1,
18
+ "b": [
19
+ 2,
20
+ 3
21
+ ],
22
+ "smile": "😀"
23
+ }
24
+ `
25
+ const fixture1HexString = 'a3616101616282020365736d696c6564f09f9880'
26
+ const fixture1Bin = fromHex(fixture1HexString)
27
+ const fixture1BinString = new TextDecoder().decode(fixture1Bin)
28
+ const fixture1DiagnosticString =
29
+ `a3 # map(3)
30
+ 61 # string(1)
31
+ 61 # "a"
32
+ 01 # uint(1)
33
+ 61 # string(1)
34
+ 62 # "b"
35
+ 82 # array(2)
36
+ 02 # uint(2)
37
+ 03 # uint(3)
38
+ 65 # string(5)
39
+ 736d696c65 # "smile"
40
+ 64 # string(2)
41
+ f09f9880 # "😀"
42
+ `
43
+ const fixture2HexString = 'a4616101616282020363627566440102036165736d696c6564f09f9880'
44
+ const fixture2DiagnosticString =
45
+ `a4 # map(4)
46
+ 61 # string(1)
47
+ 61 # "a"
48
+ 01 # uint(1)
49
+ 61 # string(1)
50
+ 62 # "b"
51
+ 82 # array(2)
52
+ 02 # uint(2)
53
+ 03 # uint(3)
54
+ 63 # string(3)
55
+ 627566 # "buf"
56
+ 44 # bytes(4)
57
+ 01020361 # "\\x01\\x02\\x03a"
58
+ 65 # string(5)
59
+ 736d696c65 # "smile"
60
+ 64 # string(2)
61
+ f09f9880 # "😀"
62
+ `
63
+
13
64
  const binPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '../lib/bin.js')
14
65
 
15
66
  function fromHex (hex) {
@@ -48,15 +99,18 @@ describe('Bin', () => {
48
99
  assert.strictEqual(e.stderr,
49
100
  `Usage: cborg <command> <args>
50
101
  Valid commands:
51
- \thex2diag [hex input]
52
- \thex2bin [hex input]
53
- \thex2json [--pretty] [hex input]
54
- \tbin2hex [binary input]
55
102
  \tbin2diag [binary input]
103
+ \tbin2hex [binary input]
56
104
  \tbin2json [--pretty] [binary input]
57
- \tjson2hex '[json input]'
58
- \tjson2diag '[json input]'
105
+ \tdiag2bin [diagnostic input]
106
+ \tdiag2hex [diagnostic input]
107
+ \tdiag2json [--pretty] [diagnostic input]
108
+ \thex2bin [hex input]
109
+ \thex2diag [hex input]
110
+ \thex2json [--pretty] [hex input]
59
111
  \tjson2bin '[json input]'
112
+ \tjson2diag '[json input]'
113
+ \tjson2hex '[json input]'
60
114
  Input may either be supplied as an argument or piped via stdin
61
115
  `)
62
116
  }
@@ -72,15 +126,18 @@ Input may either be supplied as an argument or piped via stdin
72
126
  `Unknown command: 'blip'
73
127
  Usage: cborg <command> <args>
74
128
  Valid commands:
75
- \thex2diag [hex input]
76
- \thex2bin [hex input]
77
- \thex2json [--pretty] [hex input]
78
- \tbin2hex [binary input]
79
129
  \tbin2diag [binary input]
130
+ \tbin2hex [binary input]
80
131
  \tbin2json [--pretty] [binary input]
81
- \tjson2hex '[json input]'
82
- \tjson2diag '[json input]'
132
+ \tdiag2bin [diagnostic input]
133
+ \tdiag2hex [diagnostic input]
134
+ \tdiag2json [--pretty] [diagnostic input]
135
+ \thex2bin [hex input]
136
+ \thex2diag [hex input]
137
+ \thex2json [--pretty] [hex input]
83
138
  \tjson2bin '[json input]'
139
+ \tjson2diag '[json input]'
140
+ \tjson2hex '[json input]'
84
141
  Input may either be supplied as an argument or piped via stdin
85
142
  `)
86
143
  }
@@ -92,162 +149,256 @@ Input may either be supplied as an argument or piped via stdin
92
149
  assert.strictEqual(stderr,
93
150
  `Usage: cborg <command> <args>
94
151
  Valid commands:
95
- \thex2diag [hex input]
96
- \thex2bin [hex input]
97
- \thex2json [--pretty] [hex input]
98
- \tbin2hex [binary input]
99
152
  \tbin2diag [binary input]
153
+ \tbin2hex [binary input]
100
154
  \tbin2json [--pretty] [binary input]
101
- \tjson2hex '[json input]'
102
- \tjson2diag '[json input]'
155
+ \tdiag2bin [diagnostic input]
156
+ \tdiag2hex [diagnostic input]
157
+ \tdiag2json [--pretty] [diagnostic input]
158
+ \thex2bin [hex input]
159
+ \thex2diag [hex input]
160
+ \thex2json [--pretty] [hex input]
103
161
  \tjson2bin '[json input]'
162
+ \tjson2diag '[json input]'
163
+ \tjson2hex '[json input]'
104
164
  Input may either be supplied as an argument or piped via stdin
105
165
  `)
106
166
  })
107
167
 
168
+ it('bin2diag (stdin)', async () => {
169
+ const { stdout, stderr } = await execBin('bin2diag', fixture1Bin)
170
+ assert.strictEqual(stderr, '')
171
+ assert.strictEqual(stdout, fixture1DiagnosticString)
172
+ })
173
+
174
+ it('bin2hex (stdin)', async () => {
175
+ const { stdout, stderr } = await execBin('bin2hex', fixture1Bin)
176
+ assert.strictEqual(stderr, '')
177
+ assert.strictEqual(stdout, `${fixture1HexString}\n`)
178
+ })
179
+
180
+ it('bin2json (stdin)', async () => {
181
+ const { stdout, stderr } = await execBin('bin2json', fixture1Bin)
182
+ assert.strictEqual(stderr, '')
183
+ assert.strictEqual(stdout, `${fixture1JsonString}\n`)
184
+ })
185
+
186
+ it('bin2json pretty (stdin)', async () => {
187
+ const { stdout, stderr } = await execBin('bin2json --pretty', fixture1Bin)
188
+ assert.strictEqual(stderr, '')
189
+ assert.strictEqual(stdout, fixture1JsonPrettyString)
190
+ })
191
+
108
192
  for (const stdin of [true, false]) {
109
- it(`hex2json${stdin ? ' (stdin)' : ''}`, async () => {
110
- const { stdout, stderr } = stdin
111
- ? await execBin('hex2json a3616101616282020365736d696c6564f09f9880')
112
- : await execBin('hex2json', 'a3616101616282020365736d696c6564f09f9880')
113
- assert.strictEqual(stderr, '')
114
- assert.strictEqual(stdout, '{"a":1,"b":[2,3],"smile":"😀"}\n')
115
- })
193
+ if (platform() !== 'win32' || stdin) { // multiline CLI input is hard (impossible?) on Windows
194
+ it(`diag2bin${stdin ? ' (stdin)' : ''}`, async () => {
195
+ const { stdout, stderr } = !stdin
196
+ ? await execBin(`diag2bin '${fixture1DiagnosticString}'`)
197
+ : await execBin('diag2bin', fixture1DiagnosticString)
198
+ assert.strictEqual(stderr, '')
199
+ assert.strictEqual(stdout, fixture1BinString)
200
+ })
116
201
 
117
- it(`hex2json pretty${stdin ? ' (stdin)' : ''}`, async () => {
118
- const { stdout, stderr } = stdin
119
- ? await execBin('hex2json --pretty a3616101616282020365736d696c6564f09f9880')
120
- : await execBin('hex2json --pretty', 'a3616101616282020365736d696c6564f09f9880')
202
+ it(`diag2hex${stdin ? ' (stdin)' : ''}`, async () => {
203
+ const { stdout, stderr } = !stdin
204
+ ? await execBin(`diag2hex '${fixture1DiagnosticString}'`)
205
+ : await execBin('diag2hex', fixture1DiagnosticString)
206
+ assert.strictEqual(stderr, '')
207
+ assert.strictEqual(stdout, `${fixture1HexString}\n`)
208
+ })
209
+
210
+ it(`diag2json${stdin ? ' (stdin)' : ''}`, async () => {
211
+ const { stdout, stderr } = !stdin
212
+ ? await execBin(`diag2json '${fixture1DiagnosticString}'`)
213
+ : await execBin('diag2json', fixture1DiagnosticString)
214
+ assert.strictEqual(stderr, '')
215
+ assert.strictEqual(stdout, `${fixture1JsonString}\n`)
216
+ })
217
+
218
+ it(`diag2json pretty${stdin ? ' (stdin)' : ''}`, async () => {
219
+ const { stdout, stderr } = !stdin
220
+ ? await execBin(`diag2json --pretty '${fixture1DiagnosticString}'`)
221
+ : await execBin('diag2json --pretty', fixture1DiagnosticString)
222
+ assert.strictEqual(stderr, '')
223
+ assert.strictEqual(stdout, fixture1JsonPrettyString)
224
+ })
225
+ }
226
+
227
+ it(`hex2bin${stdin ? ' (stdin)' : ''}`, async () => {
228
+ const { stdout, stderr } = !stdin
229
+ ? await execBin(`hex2bin ${fixture1HexString}`)
230
+ : await execBin('hex2bin', fixture1HexString)
121
231
  assert.strictEqual(stderr, '')
122
- assert.strictEqual(stdout,
123
- `{
124
- "a": 1,
125
- "b": [
126
- 2,
127
- 3
128
- ],
129
- "smile": "😀"
130
- }
131
- `)
232
+ assert.strictEqual(stdout, fixture1BinString)
132
233
  })
133
234
 
134
235
  it(`hex2diag${stdin ? ' (stdin)' : ''}`, async () => {
135
- const { stdout, stderr } = stdin
136
- ? await execBin('hex2diag a4616101616282020363627566440102036165736d696c6564f09f9880')
137
- : await execBin('hex2diag', 'a4616101616282020363627566440102036165736d696c6564f09f9880')
236
+ const { stdout, stderr } = !stdin
237
+ ? await execBin(`hex2diag ${fixture2HexString}`)
238
+ : await execBin('hex2diag', fixture2HexString)
138
239
  assert.strictEqual(stderr, '')
139
- assert.strictEqual(stdout,
140
- `a4 # map(4)
141
- 61 # string(1)
142
- 61 # "a"
143
- 01 # uint(1)
144
- 61 # string(1)
145
- 62 # "b"
146
- 82 # array(2)
147
- 02 # uint(2)
148
- 03 # uint(3)
149
- 63 # string(3)
150
- 627566 # "buf"
151
- 44 # bytes(4)
152
- 01020361 # "\\x01\\x02\\x03a"
153
- 65 # string(5)
154
- 736d696c65 # "smile"
155
- 64 f09f # string(2)
156
- f09f9880 # "😀"
157
- `)
240
+ assert.strictEqual(stdout, fixture2DiagnosticString)
158
241
  })
159
242
 
160
- it(`hex2bin${stdin ? ' (stdin)' : ''}`, async () => {
161
- const { stdout, stderr } = stdin
162
- ? await execBin('hex2bin a3616101616282020365736d696c6564f09f9880')
163
- : await execBin('hex2bin', 'a3616101616282020365736d696c6564f09f9880')
243
+ it(`hex2json${stdin ? ' (stdin)' : ''}`, async () => {
244
+ const { stdout, stderr } = !stdin
245
+ ? await execBin(`hex2json ${fixture1HexString}`)
246
+ : await execBin('hex2json', fixture1HexString)
164
247
  assert.strictEqual(stderr, '')
165
- assert.strictEqual(stdout, new TextDecoder().decode(fromHex('a3616101616282020365736d696c6564f09f9880')))
248
+ assert.strictEqual(stdout, `${fixture1JsonString}\n`)
166
249
  })
167
250
 
168
- it(`json2hex${stdin ? ' (stdin)' : ''}`, async () => {
169
- const { stdout, stderr } = stdin
170
- ? await execBin('json2hex "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"😀\\"}"')
171
- : await execBin('json2hex', '{"a":1,"b":[2,3],"smile":"😀"}')
251
+ it(`hex2json pretty${stdin ? ' (stdin)' : ''}`, async () => {
252
+ const { stdout, stderr } = !stdin
253
+ ? await execBin(`hex2json --pretty ${fixture1HexString}`)
254
+ : await execBin('hex2json --pretty', fixture1HexString)
172
255
  assert.strictEqual(stderr, '')
173
- assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n')
256
+ assert.strictEqual(stdout, fixture1JsonPrettyString)
174
257
  })
175
258
 
176
259
  it(`json2bin${stdin ? ' (stdin)' : ''}`, async () => {
177
- const { stdout, stderr } = stdin
260
+ const { stdout, stderr } = !stdin
178
261
  ? await execBin('json2bin "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"😀\\"}"')
179
- : await execBin('json2bin', '{"a":1,"b":[2,3],"smile":"😀"}')
262
+ : await execBin('json2bin', fixture1JsonString)
180
263
  assert.strictEqual(stderr, '')
181
- assert.strictEqual(stdout, new TextDecoder().decode(fromHex('a3616101616282020365736d696c6564f09f9880')))
264
+ assert.strictEqual(stdout, fixture1BinString)
182
265
  })
183
266
 
184
267
  it(`json2diag${stdin ? ' (stdin)' : ''}`, async () => {
185
- const { stdout, stderr } = stdin
268
+ const { stdout, stderr } = !stdin
186
269
  ? await execBin('json2diag "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"😀\\"}"')
187
- : await execBin('json2diag', '{"a":1,"b":[2,3],"smile":"😀"}')
270
+ : await execBin('json2diag', fixture1JsonString)
188
271
  assert.strictEqual(stderr, '')
189
- assert.strictEqual(stdout,
190
- `a3 # map(3)
191
- 61 # string(1)
192
- 61 # "a"
193
- 01 # uint(1)
194
- 61 # string(1)
195
- 62 # "b"
196
- 82 # array(2)
197
- 02 # uint(2)
198
- 03 # uint(3)
199
- 65 # string(5)
200
- 736d696c65 # "smile"
201
- 64 f09f # string(2)
202
- f09f9880 # "😀"
203
- `)
272
+ assert.strictEqual(stdout, fixture1DiagnosticString)
273
+ })
274
+
275
+ it(`json2hex${stdin ? ' (stdin)' : ''}`, async () => {
276
+ const { stdout, stderr } = !stdin
277
+ ? await execBin(`json2hex "${fixture1JsonString.replace(/"/g, '\\"')}"`)
278
+ : await execBin('json2hex', fixture1JsonString)
279
+ assert.strictEqual(stderr, '')
280
+ assert.strictEqual(stdout, `${fixture1HexString}\n`)
204
281
  })
205
282
  }
206
283
 
207
- it('bin2diag (stdin)', async () => {
208
- const { stdout, stderr } = await execBin('bin2diag', fromHex('a3616101616282020365736d696c6564f09f9880'))
284
+ // complicated nesting to test indenting algorithm
285
+ it('diag indenting', async () => {
286
+ const { stdout, stderr } = await execBin('json2diag', '{"a":[],"b":{},"c":{"a":1,"b":{"a":{"a":{}}}},"d":{"a":{"a":{"a":1},"b":2,"c":[]}},"e":[[[[{"a":{}}]]]],"f":1}')
209
287
  assert.strictEqual(stderr, '')
210
288
  assert.strictEqual(stdout,
211
- `a3 # map(3)
289
+ `a6 # map(6)
212
290
  61 # string(1)
213
291
  61 # "a"
214
- 01 # uint(1)
292
+ 80 # array(0)
215
293
  61 # string(1)
216
294
  62 # "b"
217
- 82 # array(2)
218
- 02 # uint(2)
219
- 03 # uint(3)
220
- 65 # string(5)
221
- 736d696c65 # "smile"
222
- 64 f09f # string(2)
223
- f09f9880 # "😀"
295
+ a0 # map(0)
296
+ 61 # string(1)
297
+ 63 # "c"
298
+ a2 # map(2)
299
+ 61 # string(1)
300
+ 61 # "a"
301
+ 01 # uint(1)
302
+ 61 # string(1)
303
+ 62 # "b"
304
+ a1 # map(1)
305
+ 61 # string(1)
306
+ 61 # "a"
307
+ a1 # map(1)
308
+ 61 # string(1)
309
+ 61 # "a"
310
+ a0 # map(0)
311
+ 61 # string(1)
312
+ 64 # "d"
313
+ a1 # map(1)
314
+ 61 # string(1)
315
+ 61 # "a"
316
+ a3 # map(3)
317
+ 61 # string(1)
318
+ 61 # "a"
319
+ a1 # map(1)
320
+ 61 # string(1)
321
+ 61 # "a"
322
+ 01 # uint(1)
323
+ 61 # string(1)
324
+ 62 # "b"
325
+ 02 # uint(2)
326
+ 61 # string(1)
327
+ 63 # "c"
328
+ 80 # array(0)
329
+ 61 # string(1)
330
+ 65 # "e"
331
+ 81 # array(1)
332
+ 81 # array(1)
333
+ 81 # array(1)
334
+ 81 # array(1)
335
+ a1 # map(1)
336
+ 61 # string(1)
337
+ 61 # "a"
338
+ a0 # map(0)
339
+ 61 # string(1)
340
+ 66 # "f"
341
+ 01 # uint(1)
224
342
  `)
225
343
  })
226
344
 
227
- it('bin2json (stdin)', async () => {
228
- const { stdout, stderr } = await execBin('bin2json', fromHex('a3616101616282020365736d696c6564f09f9880'))
229
- assert.strictEqual(stderr, '')
230
- assert.strictEqual(stdout, '{"a":1,"b":[2,3],"smile":"😀"}\n')
345
+ describe('diag length bytes', () => {
346
+ it('compact', async () => {
347
+ const { stdout, stderr } = await execBin('json2diag', '"aaaaaaaaaaaaaaaaaaaaaaa"')
348
+ assert.strictEqual(stderr, '')
349
+ assert.strictEqual(stdout,
350
+ `77 # string(23)
351
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
352
+ `)
353
+ })
354
+
355
+ it('1-byte', async () => {
356
+ const { stdout, stderr } = await execBin('json2diag', '"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"')
357
+ assert.strictEqual(stderr, '')
358
+ assert.strictEqual(stdout,
359
+ `78 23 # string(35)
360
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
361
+ 616161616161616161616161 # "aaaaaaaaaaaa"
362
+ `)
363
+ })
364
+
365
+ it('2-byte', async () => {
366
+ const { stdout, stderr } = await execBin('json2diag', '"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"')
367
+ assert.strictEqual(stderr, '')
368
+ assert.strictEqual(stdout,
369
+ `79 0100 # string(256)
370
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
371
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
372
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
373
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
374
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
375
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
376
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
377
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
378
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
379
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
380
+ 6161616161616161616161616161616161616161616161 # "aaaaaaaaaaaaaaaaaaaaaaa"
381
+ 616161 # "aaa"
382
+ `)
383
+ })
231
384
  })
232
385
 
233
- it('bin2json pretty (stdin)', async () => {
234
- const { stdout, stderr } = await execBin('bin2json --pretty', fromHex('a3616101616282020365736d696c6564f09f9880'))
386
+ it('diag non-utf8 and non-printable ascii', async () => {
387
+ const input = '7864f55ff8f12508b63ef2bfeca7557ae90df6311a5ec1631b4a1fa843310bd9c3a710eaace5a1bdd72ad0bfe049771c11e756338bd93865e645f1adec9b9c99ef407fbd4fc6859e7904c5ad7dc9bd10a5cc16973d5b28ec1a6dd43d9f82f9f18c3d03418e35'
388
+ let { stdout, stderr } = await execBin(`hex2diag ${input}`)
235
389
  assert.strictEqual(stderr, '')
236
390
  assert.strictEqual(stdout,
237
- `{
238
- "a": 1,
239
- "b": [
240
- 2,
241
- 3
242
- ],
243
- "smile": "😀"
244
- }
391
+ `78 64 # string(86)
392
+ f55ff8f12508b63ef2bfeca7557ae90df6311a5ec1631b # "õ_øñ%\\x08¶>ò¿ì§Uzé\\x0dö1\\x1a^Ác\\x1b"
393
+ 4a1fa843310bd9c3a710eaace5a1bdd72ad0bfe049771c # "J\\x1f¨C1\\x0bÙç\\x10ê¬å¡½×*пàIw\\x1c"
394
+ 11e756338bd93865e645f1adec9b9c99ef407fbd4fc685 # "\\x11çV3\\x8bÙ8eæEñ\\xadì\\x9b\\x9c\\x99ï@\\x7f½OÆ\\x85"
395
+ 9e7904c5ad7dc9bd10a5cc16973d5b28ec1a6dd43d9f82 # "\\x9ey\\x04Å\\xad}ɽ\\x10¥Ì\\x16\\x97=[(ì\\x1amÔ=\\x9f\\x82"
396
+ f9f18c3d03418e35 # "ùñ\\x8c=\\x03A\\x8e5"
245
397
  `)
246
- })
247
398
 
248
- it('bin2hex (stdin)', async () => {
249
- const { stdout, stderr } = await execBin('bin2hex', fromHex('a3616101616282020365736d696c6564f09f9880'))
399
+ // round-trip
400
+ ;({ stdout, stderr } = await execBin('diag2hex', stdout))
250
401
  assert.strictEqual(stderr, '')
251
- assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n')
402
+ assert.strictEqual(stdout, `${input}\n`)
252
403
  })
253
404
  })
@@ -29,6 +29,7 @@ export interface DecodeOptions {
29
29
  allowBigInt?: boolean;
30
30
  strict?: boolean;
31
31
  useMaps?: boolean;
32
+ retainStringBytes?: boolean;
32
33
  tags?: TagDecoder[];
33
34
  tokenizer?: DecodeTokenizer;
34
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAE7B,oBAAY,mBAAmB,GAAG,KAAK,GAAG,KAAK,EAAE,GAAG,mBAAmB,EAAE,CAAA;AAEzE,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,SAAS,GAAG,SAAS,CAAA;IAC7B,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,CAAA;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,GAAG,OAAO,CAAA;CACvC;AAED,oBAAY,mBAAmB,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,SAAS,KAAK,mBAAmB,GAAG,IAAI,CAAA;AAEtI,oBAAY,iBAAiB,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,SAAS,KAAK,mBAAmB,CAAA;AAE7H,oBAAY,gBAAgB,GAAG;IAC7B,CAAC,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IACvD,aAAa,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,GAAG,MAAM,CAAC;IAC5C,WAAW,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;CAC7D,CAAA;AAED,oBAAY,SAAS,GA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AED,oBAAY,UAAU,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAA;AAE5C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,IAAI,CAAC,EAAE,UAAU,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,eAAe,CAAA;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,YAAY,CAAC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,CAAA;KAAE,CAAA;CAC3D"}
@@ -2,10 +2,10 @@
2
2
  * @param {Uint8Array} data
3
3
  * @param {number} pos
4
4
  * @param {number} minor
5
- * @param {DecodeOptions} _options
5
+ * @param {DecodeOptions} options
6
6
  * @returns {Token}
7
7
  */
8
- export function decodeStringCompact(data: Uint8Array, pos: number, minor: number, _options: DecodeOptions): Token;
8
+ export function decodeStringCompact(data: Uint8Array, pos: number, minor: number, options: DecodeOptions): Token;
9
9
  /**
10
10
  * @param {Uint8Array} data
11
11
  * @param {number} pos
@@ -1 +1 @@
1
- {"version":3,"file":"3string.d.ts","sourceRoot":"","sources":["../../lib/3string.js"],"names":[],"mappings":"AAwBA;;;;;;GAMG;AACH,0CANW,UAAU,OACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED,8CAAuC;iBA7E1B,OAAO,SAAS,EAAE,EAAE;4BACpB,OAAO,cAAc,EAAE,aAAa"}
1
+ {"version":3,"file":"3string.d.ts","sourceRoot":"","sources":["../../lib/3string.js"],"names":[],"mappings":"AA6BA;;;;;;GAMG;AACH,0CANW,UAAU,OACV,MAAM,SACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED,8CAAuC;iBAlF1B,OAAO,SAAS,EAAE,EAAE;4BACpB,OAAO,cAAc,EAAE,aAAa"}
@@ -3,4 +3,10 @@
3
3
  * @param {number} [width]
4
4
  */
5
5
  export function tokensToDiagnostic(inp: Uint8Array, width?: number | undefined): Generator<string, void, unknown>;
6
+ /**
7
+ * Convert an input string formatted as CBOR diagnostic output into binary CBOR form.
8
+ * @param {string} input
9
+ * @returns {Uint8Array}
10
+ */
11
+ export function fromDiag(input: string): Uint8Array;
6
12
  //# sourceMappingURL=diagnostic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../lib/diagnostic.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wCAHW,UAAU,gEAgGpB"}
1
+ {"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../lib/diagnostic.js"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wCAHW,UAAU,gEA6HpB;AAED;;;;GAIG;AACH,gCAHW,MAAM,GACJ,UAAU,CAatB"}
@@ -47,6 +47,8 @@ export class Token {
47
47
  encodedLength: number | undefined;
48
48
  /** @type {Uint8Array|undefined} */
49
49
  encodedBytes: Uint8Array | undefined;
50
+ /** @type {Uint8Array|undefined} */
51
+ byteValue: Uint8Array | undefined;
50
52
  toString(): string;
51
53
  }
52
54
  //# sourceMappingURL=token.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../lib/token.js"],"names":[],"mappings":"AAAA;IACE;;;;OAIG;IACH,mBAJW,MAAM,QACN,MAAM,YACN,OAAO,EAOjB;IAJC,cAAkB;IAClB,qBAA8B;IAC9B,aAAgB;IAChB,kBAAwB;IAI1B,mBAEC;IAED;;;OAGG;IACH,aAHW,IAAI,GACF,MAAM,CAKlB;CACF;;;;;;;;;;;;;;;;;;;;AAkBD;IACE;;;;OAIG;IACH,kBAJW,IAAI,UACJ,GAAG,sCASb;IALC,WAAgB;IAChB,WAAkB;IAClB,kCAAkC;IAClC,mCAAmC;IACnC,cADW,UAAU,GAAC,SAAS,CACF;IAI/B,mBAEC;CACF"}
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../lib/token.js"],"names":[],"mappings":"AAAA;IACE;;;;OAIG;IACH,mBAJW,MAAM,QACN,MAAM,YACN,OAAO,EAOjB;IAJC,cAAkB;IAClB,qBAA8B;IAC9B,aAAgB;IAChB,kBAAwB;IAI1B,mBAEC;IAED;;;OAGG;IACH,aAHW,IAAI,GACF,MAAM,CAKlB;CACF;;;;;;;;;;;;;;;;;;;;AAkBD;IACE;;;;OAIG;IACH,kBAJW,IAAI,UACJ,GAAG,sCAWb;IAPC,WAAgB;IAChB,WAAkB;IAClB,kCAAkC;IAClC,mCAAmC;IACnC,cADW,UAAU,GAAC,SAAS,CACF;IAC7B,mCAAmC;IACnC,WADW,UAAU,GAAC,SAAS,CACL;IAI5B,mBAEC;CACF"}