cborg 1.4.2 → 1.5.3
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/cjs/browser-test/node-test-bin.js +133 -50
- package/cjs/browser-test/test-0uint.js +1 -1
- package/cjs/browser-test/test-1negint.js +1 -1
- package/cjs/browser-test/test-2bytes.js +1 -1
- package/cjs/browser-test/test-3string.js +1 -1
- package/cjs/browser-test/test-4array.js +1 -1
- package/cjs/browser-test/test-5map.js +1 -1
- package/cjs/browser-test/test-6tag.js +1 -1
- package/cjs/browser-test/test-7float.js +1 -1
- package/cjs/browser-test/test-bl.js +1 -1
- package/cjs/browser-test/test-cbor-vectors.js +1 -1
- package/cjs/browser-test/test-decode-errors.js +1 -1
- package/cjs/browser-test/test-fuzz.js +1 -1
- package/cjs/lib/bin.js +100 -37
- package/cjs/node-test/node-test-bin.js +133 -50
- package/cjs/node-test/test-0uint.js +1 -1
- package/cjs/node-test/test-1negint.js +1 -1
- package/cjs/node-test/test-2bytes.js +1 -1
- package/cjs/node-test/test-3string.js +1 -1
- package/cjs/node-test/test-4array.js +1 -1
- package/cjs/node-test/test-5map.js +1 -1
- package/cjs/node-test/test-6tag.js +1 -1
- package/cjs/node-test/test-7float.js +1 -1
- package/cjs/node-test/test-bl.js +1 -1
- package/cjs/node-test/test-cbor-vectors.js +1 -1
- package/cjs/node-test/test-decode-errors.js +1 -1
- package/cjs/node-test/test-fuzz.js +1 -1
- package/esm/browser-test/node-test-bin.js +131 -48
- package/esm/lib/bin.js +99 -36
- package/esm/node-test/node-test-bin.js +131 -48
- package/lib/bin.js +125 -40
- package/package.json +1 -1
- package/test/node-test-bin.js +155 -50
- package/types/lib/common.d.ts +1 -1
- package/types/lib/common.d.ts.map +1 -1
package/test/node-test-bin.js
CHANGED
|
@@ -12,9 +12,16 @@ const { assert } = chai
|
|
|
12
12
|
|
|
13
13
|
const binPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '../lib/bin.js')
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
function fromHex (hex) {
|
|
16
|
+
return new Uint8Array(hex.split('')
|
|
17
|
+
.map((/** @type {string} */ c, /** @type {number} */ i, /** @type {string[]} */ d) => i % 2 === 0 ? `0x${c}${d[i + 1]}` : '')
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.map((/** @type {string} */ e) => parseInt(e, 16)))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function execBin (cmd, stdin) {
|
|
16
23
|
return new Promise((resolve, reject) => {
|
|
17
|
-
exec(`"${process.execPath}" "${binPath}" ${cmd}`, (err, stdout, stderr) => {
|
|
24
|
+
const cp = exec(`"${process.execPath}" "${binPath}" ${cmd}`, (err, stdout, stderr) => {
|
|
18
25
|
if (err) {
|
|
19
26
|
err.stdout = stdout
|
|
20
27
|
err.stderr = stderr
|
|
@@ -22,6 +29,12 @@ async function execBin (cmd) {
|
|
|
22
29
|
}
|
|
23
30
|
resolve({ stdout, stderr })
|
|
24
31
|
})
|
|
32
|
+
if (stdin != null) {
|
|
33
|
+
cp.on('spawn', () => {
|
|
34
|
+
cp.stdin.write(stdin)
|
|
35
|
+
cp.stdin.end()
|
|
36
|
+
})
|
|
37
|
+
}
|
|
25
38
|
})
|
|
26
39
|
}
|
|
27
40
|
|
|
@@ -35,9 +48,16 @@ describe('Bin', () => {
|
|
|
35
48
|
assert.strictEqual(e.stderr,
|
|
36
49
|
`Usage: cborg <command> <args>
|
|
37
50
|
Valid commands:
|
|
38
|
-
\thex2diag
|
|
39
|
-
\
|
|
40
|
-
\
|
|
51
|
+
\thex2diag [hex input]
|
|
52
|
+
\thex2bin [hex input]
|
|
53
|
+
\thex2json [--pretty] [hex input]
|
|
54
|
+
\tbin2hex [binary input]
|
|
55
|
+
\tbin2diag [binary input]
|
|
56
|
+
\tbin2json [--pretty] [binary input]
|
|
57
|
+
\tjson2hex '[json input]'
|
|
58
|
+
\tjson2diag '[json input]'
|
|
59
|
+
\tjson2bin '[json input]'
|
|
60
|
+
Input may either be supplied as an argument or piped via stdin
|
|
41
61
|
`)
|
|
42
62
|
}
|
|
43
63
|
})
|
|
@@ -52,9 +72,16 @@ Valid commands:
|
|
|
52
72
|
`Unknown command: 'blip'
|
|
53
73
|
Usage: cborg <command> <args>
|
|
54
74
|
Valid commands:
|
|
55
|
-
\thex2diag
|
|
56
|
-
\
|
|
57
|
-
\
|
|
75
|
+
\thex2diag [hex input]
|
|
76
|
+
\thex2bin [hex input]
|
|
77
|
+
\thex2json [--pretty] [hex input]
|
|
78
|
+
\tbin2hex [binary input]
|
|
79
|
+
\tbin2diag [binary input]
|
|
80
|
+
\tbin2json [--pretty] [binary input]
|
|
81
|
+
\tjson2hex '[json input]'
|
|
82
|
+
\tjson2diag '[json input]'
|
|
83
|
+
\tjson2bin '[json input]'
|
|
84
|
+
Input may either be supplied as an argument or piped via stdin
|
|
58
85
|
`)
|
|
59
86
|
}
|
|
60
87
|
})
|
|
@@ -65,30 +92,34 @@ Valid commands:
|
|
|
65
92
|
assert.strictEqual(stderr,
|
|
66
93
|
`Usage: cborg <command> <args>
|
|
67
94
|
Valid commands:
|
|
68
|
-
\thex2diag
|
|
69
|
-
\
|
|
70
|
-
\
|
|
95
|
+
\thex2diag [hex input]
|
|
96
|
+
\thex2bin [hex input]
|
|
97
|
+
\thex2json [--pretty] [hex input]
|
|
98
|
+
\tbin2hex [binary input]
|
|
99
|
+
\tbin2diag [binary input]
|
|
100
|
+
\tbin2json [--pretty] [binary input]
|
|
101
|
+
\tjson2hex '[json input]'
|
|
102
|
+
\tjson2diag '[json input]'
|
|
103
|
+
\tjson2bin '[json input]'
|
|
104
|
+
Input may either be supplied as an argument or piped via stdin
|
|
71
105
|
`)
|
|
72
106
|
})
|
|
73
107
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} catch (e) {
|
|
83
|
-
assert.strictEqual(e.stdout, '')
|
|
84
|
-
assert.isTrue(e.stderr.startsWith('hex2json requires a hexadecimal input string\nUsage: '))
|
|
85
|
-
}
|
|
86
|
-
})
|
|
108
|
+
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
|
+
})
|
|
87
116
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
117
|
+
it(`hex2json pretty${stdin ? ' (stdin)' : ''}`, async () => {
|
|
118
|
+
const { stdout, stderr } = stdin
|
|
119
|
+
? await execBin('hex2json --pretty a3616101616282020365736d696c6564f09f9880')
|
|
120
|
+
: await execBin('hex2json --pretty', 'a3616101616282020365736d696c6564f09f9880')
|
|
121
|
+
assert.strictEqual(stderr, '')
|
|
122
|
+
assert.strictEqual(stdout,
|
|
92
123
|
`{
|
|
93
124
|
"a": 1,
|
|
94
125
|
"b": [
|
|
@@ -98,12 +129,14 @@ Valid commands:
|
|
|
98
129
|
"smile": "😀"
|
|
99
130
|
}
|
|
100
131
|
`)
|
|
101
|
-
|
|
132
|
+
})
|
|
102
133
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
134
|
+
it(`hex2diag${stdin ? ' (stdin)' : ''}`, async () => {
|
|
135
|
+
const { stdout, stderr } = stdin
|
|
136
|
+
? await execBin('hex2diag a4616101616282020363627566440102036165736d696c6564f09f9880')
|
|
137
|
+
: await execBin('hex2diag', 'a4616101616282020363627566440102036165736d696c6564f09f9880')
|
|
138
|
+
assert.strictEqual(stderr, '')
|
|
139
|
+
assert.strictEqual(stdout,
|
|
107
140
|
`a4 # map(4)
|
|
108
141
|
61 # string(1)
|
|
109
142
|
61 # "a"
|
|
@@ -122,27 +155,99 @@ Valid commands:
|
|
|
122
155
|
64 f09f # string(2)
|
|
123
156
|
f09f9880 # "😀"
|
|
124
157
|
`)
|
|
158
|
+
})
|
|
125
159
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
assert.strictEqual(
|
|
131
|
-
assert.
|
|
132
|
-
}
|
|
160
|
+
it(`hex2bin${stdin ? ' (stdin)' : ''}`, async () => {
|
|
161
|
+
const { stdout, stderr } = stdin
|
|
162
|
+
? await execBin('hex2bin a3616101616282020365736d696c6564f09f9880')
|
|
163
|
+
: await execBin('hex2bin', 'a3616101616282020365736d696c6564f09f9880')
|
|
164
|
+
assert.strictEqual(stderr, '')
|
|
165
|
+
assert.strictEqual(stdout, new TextDecoder().decode(fromHex('a3616101616282020365736d696c6564f09f9880')))
|
|
166
|
+
})
|
|
167
|
+
|
|
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":"😀"}')
|
|
172
|
+
assert.strictEqual(stderr, '')
|
|
173
|
+
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n')
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it(`json2bin${stdin ? ' (stdin)' : ''}`, async () => {
|
|
177
|
+
const { stdout, stderr } = stdin
|
|
178
|
+
? await execBin('json2bin "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"😀\\"}"')
|
|
179
|
+
: await execBin('json2bin', '{"a":1,"b":[2,3],"smile":"😀"}')
|
|
180
|
+
assert.strictEqual(stderr, '')
|
|
181
|
+
assert.strictEqual(stdout, new TextDecoder().decode(fromHex('a3616101616282020365736d696c6564f09f9880')))
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it(`json2diag${stdin ? ' (stdin)' : ''}`, async () => {
|
|
185
|
+
const { stdout, stderr } = stdin
|
|
186
|
+
? await execBin('json2diag "{\\"a\\":1,\\"b\\":[2,3],\\"smile\\":\\"😀\\"}"')
|
|
187
|
+
: await execBin('json2diag', '{"a":1,"b":[2,3],"smile":"😀"}')
|
|
188
|
+
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
|
+
`)
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
it('bin2diag (stdin)', async () => {
|
|
208
|
+
const { stdout, stderr } = await execBin('bin2diag', fromHex('a3616101616282020365736d696c6564f09f9880'))
|
|
209
|
+
assert.strictEqual(stderr, '')
|
|
210
|
+
assert.strictEqual(stdout,
|
|
211
|
+
`a3 # map(3)
|
|
212
|
+
61 # string(1)
|
|
213
|
+
61 # "a"
|
|
214
|
+
01 # uint(1)
|
|
215
|
+
61 # string(1)
|
|
216
|
+
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 # "😀"
|
|
224
|
+
`)
|
|
133
225
|
})
|
|
134
226
|
|
|
135
|
-
it('
|
|
136
|
-
const { stdout, stderr } = await execBin('
|
|
227
|
+
it('bin2json (stdin)', async () => {
|
|
228
|
+
const { stdout, stderr } = await execBin('bin2json', fromHex('a3616101616282020365736d696c6564f09f9880'))
|
|
137
229
|
assert.strictEqual(stderr, '')
|
|
138
|
-
assert.strictEqual(stdout, '
|
|
230
|
+
assert.strictEqual(stdout, '{"a":1,"b":[2,3],"smile":"😀"}\n')
|
|
231
|
+
})
|
|
139
232
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
233
|
+
it('bin2json pretty (stdin)', async () => {
|
|
234
|
+
const { stdout, stderr } = await execBin('bin2json --pretty', fromHex('a3616101616282020365736d696c6564f09f9880'))
|
|
235
|
+
assert.strictEqual(stderr, '')
|
|
236
|
+
assert.strictEqual(stdout,
|
|
237
|
+
`{
|
|
238
|
+
"a": 1,
|
|
239
|
+
"b": [
|
|
240
|
+
2,
|
|
241
|
+
3
|
|
242
|
+
],
|
|
243
|
+
"smile": "😀"
|
|
244
|
+
}
|
|
245
|
+
`)
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('bin2hex (stdin)', async () => {
|
|
249
|
+
const { stdout, stderr } = await execBin('bin2hex', fromHex('a3616101616282020365736d696c6564f09f9880'))
|
|
250
|
+
assert.strictEqual(stderr, '')
|
|
251
|
+
assert.strictEqual(stdout, 'a3616101616282020365736d696c6564f09f9880\n')
|
|
147
252
|
})
|
|
148
253
|
})
|
package/types/lib/common.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../lib/common.js"],"names":[],"mappings":"AAAA,mDAA4C;AAC5C,mDAA4C;AAE5C,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../lib/common.js"],"names":[],"mappings":"AAAA,mDAA4C;AAC5C,mDAA4C;AAE5C,yCAA+B;AAO/B;;;;GAIG;AACH,uCAJW,UAAU,OACV,MAAM,QACN,MAAM,QAMhB"}
|