cborg 4.5.6 → 4.5.8
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/CHANGELOG.md +9 -0
- package/lib/byte-utils.js +8 -2
- package/lib/diagnostic.js +10 -3
- package/package.json +3 -2
- package/test/node-test-bin.js +26 -9
- package/types/lib/byte-utils.d.ts.map +1 -1
- package/types/lib/diagnostic.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [4.5.8](https://github.com/rvagg/cborg/compare/v4.5.7...v4.5.8) (2026-01-21)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **cli:** don't omit array length bytes in diagnostic output ([b8dacb6](https://github.com/rvagg/cborg/commit/b8dacb652c02566c7b64c2638b7bcb36bb519b6b))
|
|
6
|
+
* **test:** add CLI tests to `npm test` ([b19bc87](https://github.com/rvagg/cborg/commit/b19bc87ea04691f9173a5b13284e21192e0f1e3c))
|
|
7
|
+
|
|
8
|
+
## [4.5.7](https://github.com/rvagg/cborg/compare/v4.5.6...v4.5.7) (2026-01-21)
|
|
9
|
+
|
|
1
10
|
## [4.5.6](https://github.com/rvagg/cborg/compare/v4.5.5...v4.5.6) (2026-01-21)
|
|
2
11
|
|
|
3
12
|
## [4.5.5](https://github.com/rvagg/cborg/compare/v4.5.4...v4.5.5) (2026-01-20)
|
package/lib/byte-utils.js
CHANGED
|
@@ -33,13 +33,19 @@ export function asU8A (buf) {
|
|
|
33
33
|
return isBuffer(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// Threshold for manual UTF-8 encoding vs native methods.
|
|
37
|
+
// Node.js Buffer.from: crossover ~24 chars
|
|
38
|
+
// Browser TextEncoder: crossover ~200 chars
|
|
39
|
+
const FROM_STRING_THRESHOLD_BUFFER = 24
|
|
40
|
+
const FROM_STRING_THRESHOLD_TEXTENCODER = 200
|
|
41
|
+
|
|
36
42
|
export const fromString = useBuffer
|
|
37
43
|
? // eslint-disable-line operator-linebreak
|
|
38
44
|
/**
|
|
39
45
|
* @param {string} string
|
|
40
46
|
*/
|
|
41
47
|
(string) => {
|
|
42
|
-
return string.length
|
|
48
|
+
return string.length >= FROM_STRING_THRESHOLD_BUFFER
|
|
43
49
|
? // eslint-disable-line operator-linebreak
|
|
44
50
|
// @ts-ignore
|
|
45
51
|
globalThis.Buffer.from(string)
|
|
@@ -51,7 +57,7 @@ export const fromString = useBuffer
|
|
|
51
57
|
* @param {string} string
|
|
52
58
|
*/
|
|
53
59
|
(string) => {
|
|
54
|
-
return string.length
|
|
60
|
+
return string.length >= FROM_STRING_THRESHOLD_TEXTENCODER ? textEncoder.encode(string) : utf8ToBytes(string)
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
/**
|
package/lib/diagnostic.js
CHANGED
|
@@ -47,9 +47,16 @@ function * tokensToDiagnostic (inp, width = 100) {
|
|
|
47
47
|
case 'bytes':
|
|
48
48
|
case 'map':
|
|
49
49
|
case 'array':
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
|
|
50
|
+
// print the length bytes if they exist (length >= 24)
|
|
51
|
+
// for string/bytes, token.value is the content; for array/map, token.value IS the count
|
|
52
|
+
if (token.type.name === 'string') {
|
|
53
|
+
multilen = utf8Encoder.encode(token.value).length
|
|
54
|
+
} else if (token.type.name === 'bytes') {
|
|
55
|
+
multilen = token.value.length
|
|
56
|
+
} else {
|
|
57
|
+
// array or map - value is the count directly
|
|
58
|
+
multilen = token.value
|
|
59
|
+
}
|
|
53
60
|
if (multilen >= uintBoundaries[0]) {
|
|
54
61
|
if (multilen < uintBoundaries[1]) {
|
|
55
62
|
outp += ` ${slc(1, 1)}`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cborg",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.8",
|
|
4
4
|
"description": "Fast CBOR with a focus on strictness",
|
|
5
5
|
"main": "cborg.js",
|
|
6
6
|
"type": "module",
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
"build:types": "tsc --build",
|
|
14
14
|
"prepublishOnly": "npm run build",
|
|
15
15
|
"test:node": "c8 --check-coverage --exclude=test/** mocha test/test-*.js",
|
|
16
|
+
"test:node-bin": "mocha test/node-test-bin.js",
|
|
16
17
|
"test:browser": "polendina --cleanup test/test-*.js",
|
|
17
|
-
"test": "npm run lint && npm run build && npm run test:node && npm run test:browser",
|
|
18
|
+
"test": "npm run lint && npm run build && npm run test:node && npm run test:node-bin && npm run test:browser",
|
|
18
19
|
"test:ci": "npm run test",
|
|
19
20
|
"coverage": "c8 --reporter=html --reporter=text mocha test/test-*.js && npx st -d coverage -p 8888"
|
|
20
21
|
},
|
package/test/node-test-bin.js
CHANGED
|
@@ -97,17 +97,17 @@ describe('Bin', () => {
|
|
|
97
97
|
assert.strictEqual(e.stderr,
|
|
98
98
|
`Usage: cborg <command> <args>
|
|
99
99
|
Valid commands:
|
|
100
|
-
\tbin2diag [binary input]
|
|
100
|
+
\tbin2diag [--width <width>] [binary input]
|
|
101
101
|
\tbin2hex [binary input]
|
|
102
102
|
\tbin2json [--pretty] [binary input]
|
|
103
103
|
\tdiag2bin [diagnostic input]
|
|
104
104
|
\tdiag2hex [diagnostic input]
|
|
105
105
|
\tdiag2json [--pretty] [diagnostic input]
|
|
106
106
|
\thex2bin [hex input]
|
|
107
|
-
\thex2diag [hex input]
|
|
107
|
+
\thex2diag [--width <width>] [hex input]
|
|
108
108
|
\thex2json [--pretty] [hex input]
|
|
109
109
|
\tjson2bin '[json input]'
|
|
110
|
-
\tjson2diag '[json input]'
|
|
110
|
+
\tjson2diag [--width <width>] '[json input]'
|
|
111
111
|
\tjson2hex '[json input]'
|
|
112
112
|
Input may either be supplied as an argument or piped via stdin
|
|
113
113
|
`)
|
|
@@ -124,17 +124,17 @@ Input may either be supplied as an argument or piped via stdin
|
|
|
124
124
|
`Unknown command: 'blip'
|
|
125
125
|
Usage: cborg <command> <args>
|
|
126
126
|
Valid commands:
|
|
127
|
-
\tbin2diag [binary input]
|
|
127
|
+
\tbin2diag [--width <width>] [binary input]
|
|
128
128
|
\tbin2hex [binary input]
|
|
129
129
|
\tbin2json [--pretty] [binary input]
|
|
130
130
|
\tdiag2bin [diagnostic input]
|
|
131
131
|
\tdiag2hex [diagnostic input]
|
|
132
132
|
\tdiag2json [--pretty] [diagnostic input]
|
|
133
133
|
\thex2bin [hex input]
|
|
134
|
-
\thex2diag [hex input]
|
|
134
|
+
\thex2diag [--width <width>] [hex input]
|
|
135
135
|
\thex2json [--pretty] [hex input]
|
|
136
136
|
\tjson2bin '[json input]'
|
|
137
|
-
\tjson2diag '[json input]'
|
|
137
|
+
\tjson2diag [--width <width>] '[json input]'
|
|
138
138
|
\tjson2hex '[json input]'
|
|
139
139
|
Input may either be supplied as an argument or piped via stdin
|
|
140
140
|
`)
|
|
@@ -147,17 +147,17 @@ Input may either be supplied as an argument or piped via stdin
|
|
|
147
147
|
assert.strictEqual(stderr,
|
|
148
148
|
`Usage: cborg <command> <args>
|
|
149
149
|
Valid commands:
|
|
150
|
-
\tbin2diag [binary input]
|
|
150
|
+
\tbin2diag [--width <width>] [binary input]
|
|
151
151
|
\tbin2hex [binary input]
|
|
152
152
|
\tbin2json [--pretty] [binary input]
|
|
153
153
|
\tdiag2bin [diagnostic input]
|
|
154
154
|
\tdiag2hex [diagnostic input]
|
|
155
155
|
\tdiag2json [--pretty] [diagnostic input]
|
|
156
156
|
\thex2bin [hex input]
|
|
157
|
-
\thex2diag [hex input]
|
|
157
|
+
\thex2diag [--width <width>] [hex input]
|
|
158
158
|
\thex2json [--pretty] [hex input]
|
|
159
159
|
\tjson2bin '[json input]'
|
|
160
|
-
\tjson2diag '[json input]'
|
|
160
|
+
\tjson2diag [--width <width>] '[json input]'
|
|
161
161
|
\tjson2hex '[json input]'
|
|
162
162
|
Input may either be supplied as an argument or piped via stdin
|
|
163
163
|
`)
|
|
@@ -341,6 +341,23 @@ Input may either be supplied as an argument or piped via stdin
|
|
|
341
341
|
})
|
|
342
342
|
|
|
343
343
|
describe('diag length bytes', () => {
|
|
344
|
+
// issue #137 - array and map length bytes were missing for lengths >= 24
|
|
345
|
+
it('array with 24 elements', async () => {
|
|
346
|
+
// 98 18 = array(24), then 24 uint(1) values
|
|
347
|
+
const hex = '9818' + '01'.repeat(24)
|
|
348
|
+
const { stdout, stderr } = await execBin(`hex2diag ${hex}`)
|
|
349
|
+
assert.strictEqual(stderr, '')
|
|
350
|
+
assert.ok(stdout.startsWith('98 18 # array(24)\n'))
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
it('map with 24 entries', async () => {
|
|
354
|
+
// b8 18 = map(24), then 24 pairs of string('a')=uint(1)
|
|
355
|
+
const hex = 'b818' + '616101'.repeat(24)
|
|
356
|
+
const { stdout, stderr } = await execBin(`hex2diag ${hex}`)
|
|
357
|
+
assert.strictEqual(stderr, '')
|
|
358
|
+
assert.ok(stdout.startsWith('b8 18 # map(24)\n'))
|
|
359
|
+
})
|
|
360
|
+
|
|
344
361
|
it('compact', async () => {
|
|
345
362
|
const { stdout, stderr } = await execBin('json2diag', '"aaaaaaaaaaaaaaaaaaaaaaa"')
|
|
346
363
|
assert.strictEqual(stderr, '')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"byte-utils.d.ts","sourceRoot":"","sources":["../../lib/byte-utils.js"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,2BAHW,UAAU,GAAC,MAAM,EAAE,GACjB,UAAU,CAQtB;
|
|
1
|
+
{"version":3,"file":"byte-utils.d.ts","sourceRoot":"","sources":["../../lib/byte-utils.js"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,2BAHW,UAAU,GAAC,MAAM,EAAE,GACjB,UAAU,CAQtB;AA0MD;;;;GAIG;AACH,4BAJW,UAAU,MACV,UAAU,GACR,MAAM,CAgBlB;AA6CD;;;GAGG;AACH,kDAHW,MAAM,EAAE,GACN,MAAM,CAkBlB;AA3TD,gCAMkD;AA+BlD,mCAGe,MAAM,iDAYN,MAAM,yCAIhB;AAOE,+BAHI,MAAM,EAAE,GACN,UAAU,CAItB;AAIG;;;;GAIG;AAEH,6BALW,UAAU,SACV,MAAM,OACN,MAAM,2BAQhB;AAcD;;;;GAIG;AACH,+BAJW,UAAU,EAAE,UACZ,MAAM,GACJ,UAAU,CActB;AAwBD;;;GAGG;AACH,4BAHW,MAAM,GACJ,UAAU,CAMtB;AAaD;;;GAGG;AACH,yBAHW,UAAU,GACR,MAAM,CAQlB;AAiBH;;;GAGG;AACD,6BAHS,MAAM,GAAC,UAAU,GACf,UAAU,CAQpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../lib/diagnostic.js"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wCAHW,UAAU,UACV,MAAM,
|
|
1
|
+
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../lib/diagnostic.js"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wCAHW,UAAU,UACV,MAAM,oCAmIhB;AAED;;;;GAIG;AACH,gCAHW,MAAM,GACJ,UAAU,CAatB"}
|