msgpackr 1.9.3 → 1.9.4

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/index.d.cts CHANGED
@@ -7,13 +7,14 @@ export enum FLOAT32_OPTIONS {
7
7
 
8
8
  export interface Options {
9
9
  useFloat32?: FLOAT32_OPTIONS
10
- useRecords?: boolean | (value:any)=> boolean
10
+ useRecords?: boolean | ((value:any)=> boolean)
11
11
  structures?: {}[]
12
12
  moreTypes?: boolean
13
13
  sequential?: boolean
14
14
  structuredClone?: boolean
15
15
  mapsAsObjects?: boolean
16
16
  variableMapSize?: boolean
17
+ coercibleKeyAsNumber?: boolean
17
18
  copyBuffers?: boolean
18
19
  bundleStrings?: boolean
19
20
  useTimestamp32?: boolean
package/index.d.ts CHANGED
@@ -7,13 +7,14 @@ export enum FLOAT32_OPTIONS {
7
7
 
8
8
  export interface Options {
9
9
  useFloat32?: FLOAT32_OPTIONS
10
- useRecords?: boolean | (value:any)=> boolean
10
+ useRecords?: boolean | ((value:any)=> boolean)
11
11
  structures?: {}[]
12
12
  moreTypes?: boolean
13
13
  sequential?: boolean
14
14
  structuredClone?: boolean
15
15
  mapsAsObjects?: boolean
16
16
  variableMapSize?: boolean
17
+ coercibleKeyAsNumber?: boolean
17
18
  copyBuffers?: boolean
18
19
  bundleStrings?: boolean
19
20
  useTimestamp32?: boolean
package/pack.js CHANGED
@@ -534,7 +534,7 @@ export class Packr extends Unpackr {
534
534
  }
535
535
  }
536
536
 
537
- const writePlainObject = this.variableMapSize ? (object) => {
537
+ const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber) ? (object) => {
538
538
  // this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
539
539
  let keys = Object.keys(object)
540
540
  let length = keys.length
@@ -550,9 +550,19 @@ export class Packr extends Unpackr {
550
550
  position += 4
551
551
  }
552
552
  let key
553
- for (let i = 0; i < length; i++) {
554
- pack(key = keys[i])
555
- pack(object[key])
553
+ if (this.coercibleKeyAsNumber) {
554
+ for (let i = 0; i < length; i++) {
555
+ key = keys[i]
556
+ let num = Number(key)
557
+ pack(isNaN(num) ? key : num)
558
+ pack(object[key])
559
+ }
560
+
561
+ } else {
562
+ for (let i = 0; i < length; i++) {
563
+ pack(key = keys[i])
564
+ pack(object[key])
565
+ }
556
566
  }
557
567
  } :
558
568
  (object, safePrototype) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.9.3",
4
+ "version": "1.9.4",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",