cborg 4.5.1 → 4.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/CHANGELOG.md +4 -0
- package/lib/byte-utils.js +6 -2
- package/lib/decode.js +4 -3
- package/package.json +1 -1
- package/types/lib/byte-utils.d.ts.map +1 -1
- package/types/lib/decode.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## [4.5.3](https://github.com/rvagg/cborg/compare/v4.5.2...v4.5.3) (2026-01-20)
|
|
2
|
+
|
|
3
|
+
## [4.5.2](https://github.com/rvagg/cborg/compare/v4.5.1...v4.5.2) (2026-01-20)
|
|
4
|
+
|
|
1
5
|
## [4.5.1](https://github.com/rvagg/cborg/compare/v4.5.0...v4.5.1) (2026-01-20)
|
|
2
6
|
|
|
3
7
|
## [4.5.0](https://github.com/rvagg/cborg/compare/v4.4.1...v4.5.0) (2026-01-20)
|
package/lib/byte-utils.js
CHANGED
|
@@ -34,6 +34,10 @@ export function asU8A (buf) {
|
|
|
34
34
|
return isBuffer(buf) ? new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength) : buf
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
// Threshold for switching between manual utf8Slice and native TextDecoder/Buffer
|
|
38
|
+
// Manual decoding has overhead from array building; native is fast for strings > 32 bytes
|
|
39
|
+
const UTF8_THRESHOLD = 32
|
|
40
|
+
|
|
37
41
|
export const toString = useBuffer
|
|
38
42
|
? // eslint-disable-line operator-linebreak
|
|
39
43
|
/**
|
|
@@ -42,7 +46,7 @@ export const toString = useBuffer
|
|
|
42
46
|
* @param {number} end
|
|
43
47
|
*/
|
|
44
48
|
(bytes, start, end) => {
|
|
45
|
-
return end - start >
|
|
49
|
+
return end - start > UTF8_THRESHOLD
|
|
46
50
|
? // eslint-disable-line operator-linebreak
|
|
47
51
|
// @ts-ignore
|
|
48
52
|
globalThis.Buffer.from(bytes.subarray(start, end)).toString('utf8')
|
|
@@ -56,7 +60,7 @@ export const toString = useBuffer
|
|
|
56
60
|
* @param {number} end
|
|
57
61
|
*/
|
|
58
62
|
(bytes, start, end) => {
|
|
59
|
-
return end - start >
|
|
63
|
+
return end - start > UTF8_THRESHOLD
|
|
60
64
|
? textDecoder.decode(bytes.subarray(start, end))
|
|
61
65
|
: utf8Slice(bytes, start, end)
|
|
62
66
|
}
|
package/lib/decode.js
CHANGED
|
@@ -92,6 +92,7 @@ function tokenToArray (token, tokeniser, options) {
|
|
|
92
92
|
*/
|
|
93
93
|
function tokenToMap (token, tokeniser, options) {
|
|
94
94
|
const useMaps = options.useMaps === true
|
|
95
|
+
const rejectDuplicateMapKeys = options.rejectDuplicateMapKeys === true
|
|
95
96
|
const obj = useMaps ? undefined : {}
|
|
96
97
|
const m = useMaps ? new Map() : undefined
|
|
97
98
|
for (let i = 0; i < token.value; i++) {
|
|
@@ -106,12 +107,12 @@ function tokenToMap (token, tokeniser, options) {
|
|
|
106
107
|
if (key === DONE) {
|
|
107
108
|
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no key], expected ${token.value})`)
|
|
108
109
|
}
|
|
109
|
-
if (useMaps
|
|
110
|
+
if (!useMaps && typeof key !== 'string') {
|
|
110
111
|
throw new Error(`${decodeErrPrefix} non-string keys not supported (got ${typeof key})`)
|
|
111
112
|
}
|
|
112
|
-
if (
|
|
113
|
+
if (rejectDuplicateMapKeys) {
|
|
113
114
|
// @ts-ignore
|
|
114
|
-
if ((useMaps && m.has(key)) || (!useMaps && (key
|
|
115
|
+
if ((useMaps && m.has(key)) || (!useMaps && Object.hasOwn(obj, key))) {
|
|
115
116
|
throw new Error(`${decodeErrPrefix} found repeat map key "${key}"`)
|
|
116
117
|
}
|
|
117
118
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"byte-utils.d.ts","sourceRoot":"","sources":["../../lib/byte-utils.js"],"names":[],"mappings":"AAwBA;;;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":"AAwBA;;;GAGG;AACH,2BAHW,UAAU,GAAC,MAAM,EAAE,GACjB,UAAU,CAQtB;AAkOD;;;;GAIG;AACH,4BAJW,UAAU,MACV,UAAU,GACR,MAAM,CAgBlB;AA4HD;;;GAGG;AACH,kDAHW,MAAM,EAAE,GACN,MAAM,CAkBlB;AAnaD,gCAMkD;AAgC9C;;;;GAIG;AACH,gCAJW,UAAU,SACV,MAAM,OACN,MAAM,UAQhB;AAcL,mCAGe,MAAM,iDAYN,MAAM,yCAIhB;AAOE,+BAHI,MAAM,EAAE,GACN,UAAU,CAItB;AAIG;;;;GAIG;AACH,6BAJW,UAAU,SACV,MAAM,OACN,MAAM,2BAOhB;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":"decode.d.ts","sourceRoot":"","sources":["../../lib/decode.js"],"names":[],"mappings":"oBAKa,OAAO,YAAY,EAAE,KAAK;4BAC1B,OAAO,cAAc,EAAE,aAAa;8BACpC,OAAO,cAAc,EAAE,eAAe;AAUnD;;GAEG;AACH,kCAFgB,eAAe;IAG7B;;;OAGG;IACH,kBAHW,UAAU,YACV,aAAa,EAMvB;IAHC,aAAa;IACb,kCAAgB;IAChB,8CAAsB;IAGxB,cAEC;IAED,gBAEC;IAED,mCAgBC;CACF;
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../lib/decode.js"],"names":[],"mappings":"oBAKa,OAAO,YAAY,EAAE,KAAK;4BAC1B,OAAO,cAAc,EAAE,aAAa;8BACpC,OAAO,cAAc,EAAE,eAAe;AAUnD;;GAEG;AACH,kCAFgB,eAAe;IAG7B;;;OAGG;IACH,kBAHW,UAAU,YACV,aAAa,EAMvB;IAHC,aAAa;IACb,kCAAgB;IAChB,8CAAsB;IAGxB,cAEC;IAED,gBAEC;IAED,mCAgBC;CACF;AA8ED;;;;GAIG;AACH,0CAJW,eAAe,WACf,aAAa,GACX,GAAG,6BAAW,CAoC1B;AAuBD;;;;GAIG;AACH,6BAJW,UAAU,YACV,aAAa,GACX,GAAG,CAQf;AAhCD;;;;GAIG;AACH,kCAJW,UAAU,YACV,aAAa,GACX,CAAC,GAAG,EAAE,UAAU,CAAC,CAgB7B;AAvID,mCAAiC;AADjC,kCAA+B"}
|