cborg 4.5.0 → 4.5.2
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/decode.js +4 -3
- package/lib/is.js +12 -31
- package/package.json +1 -1
- package/types/lib/decode.d.ts.map +1 -1
- package/types/lib/is.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
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/lib/is.js
CHANGED
|
@@ -3,24 +3,10 @@
|
|
|
3
3
|
// check is expensive, and unnecessary for our purposes. The values returned
|
|
4
4
|
// are compatible with @sindresorhus/is, however.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'number',
|
|
9
|
-
'bigint',
|
|
10
|
-
'symbol'
|
|
11
|
-
]
|
|
12
|
-
|
|
6
|
+
// Types that reach getObjectType() - excludes types with fast-paths above:
|
|
7
|
+
// primitives (typeof), Array (isArray), Uint8Array (instanceof), plain Object (constructor)
|
|
13
8
|
const objectTypeNames = [
|
|
14
|
-
'
|
|
15
|
-
'Generator',
|
|
16
|
-
'AsyncGenerator',
|
|
17
|
-
'GeneratorFunction',
|
|
18
|
-
'AsyncGeneratorFunction',
|
|
19
|
-
'AsyncFunction',
|
|
20
|
-
'Observable',
|
|
21
|
-
'Array',
|
|
22
|
-
'Buffer',
|
|
23
|
-
'Object',
|
|
9
|
+
'Object', // for Object.create(null) and other non-plain objects
|
|
24
10
|
'RegExp',
|
|
25
11
|
'Date',
|
|
26
12
|
'Error',
|
|
@@ -35,7 +21,6 @@ const objectTypeNames = [
|
|
|
35
21
|
'URL',
|
|
36
22
|
'HTMLElement',
|
|
37
23
|
'Int8Array',
|
|
38
|
-
'Uint8Array',
|
|
39
24
|
'Uint8ClampedArray',
|
|
40
25
|
'Int16Array',
|
|
41
26
|
'Uint16Array',
|
|
@@ -62,19 +47,23 @@ export function is (value) {
|
|
|
62
47
|
return 'boolean'
|
|
63
48
|
}
|
|
64
49
|
const typeOf = typeof value
|
|
65
|
-
if (
|
|
50
|
+
if (typeOf === 'string' || typeOf === 'number' || typeOf === 'bigint' || typeOf === 'symbol') {
|
|
66
51
|
return typeOf
|
|
67
52
|
}
|
|
68
|
-
/* c8 ignore next
|
|
69
|
-
// not going to bother testing this, it's not going to be valid anyway
|
|
53
|
+
/* c8 ignore next 3 */
|
|
70
54
|
if (typeOf === 'function') {
|
|
71
55
|
return 'Function'
|
|
72
56
|
}
|
|
73
57
|
if (Array.isArray(value)) {
|
|
74
58
|
return 'Array'
|
|
75
59
|
}
|
|
76
|
-
|
|
77
|
-
|
|
60
|
+
// Also catches Node.js Buffer which extends Uint8Array
|
|
61
|
+
if (value instanceof Uint8Array) {
|
|
62
|
+
return 'Uint8Array'
|
|
63
|
+
}
|
|
64
|
+
// Fast path for plain objects (most common case after primitives/arrays/bytes)
|
|
65
|
+
if (value.constructor === Object) {
|
|
66
|
+
return 'Object'
|
|
78
67
|
}
|
|
79
68
|
const objectType = getObjectType(value)
|
|
80
69
|
if (objectType) {
|
|
@@ -84,14 +73,6 @@ export function is (value) {
|
|
|
84
73
|
return 'Object'
|
|
85
74
|
}
|
|
86
75
|
|
|
87
|
-
/**
|
|
88
|
-
* @param {any} value
|
|
89
|
-
* @returns {boolean}
|
|
90
|
-
*/
|
|
91
|
-
function isBuffer (value) {
|
|
92
|
-
return value && value.constructor && value.constructor.isBuffer && value.constructor.isBuffer.call(null, value)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
76
|
/**
|
|
96
77
|
* @param {any} value
|
|
97
78
|
* @returns {string|undefined}
|
package/package.json
CHANGED
|
@@ -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"}
|
package/types/lib/is.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../lib/is.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../lib/is.js"],"names":[],"mappings":"AAkCA;;;GAGG;AACH,0BAHW,GAAG,GACD,MAAM,CAqClB"}
|