msgpackr 1.10.2 → 1.11.0

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/dist/index.js CHANGED
@@ -1166,7 +1166,7 @@
1166
1166
  if (!this.structures && options.useRecords != false)
1167
1167
  this.structures = [];
1168
1168
  // two byte record ids for shared structures
1169
- let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
1169
+ let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
1170
1170
  let sharedLimitId = maxSharedStructures + 0x40;
1171
1171
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1172
1172
  if (maxStructureId > 8256) {
@@ -1184,7 +1184,7 @@
1184
1184
  }
1185
1185
  safeEnd = target.length - 10;
1186
1186
  if (safeEnd - position < 0x800) {
1187
- // don't start too close to the end,
1187
+ // don't start too close to the end,
1188
1188
  target = new ByteArrayAllocate(target.length);
1189
1189
  targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length));
1190
1190
  safeEnd = target.length - 10;
@@ -1527,7 +1527,7 @@
1527
1527
  targetView.setUint32(position, referee.id);
1528
1528
  position += 4;
1529
1529
  return
1530
- } else
1530
+ } else
1531
1531
  referenceMap.set(value, { offset: position - start });
1532
1532
  }
1533
1533
  let constructor = value.constructor;
@@ -1555,7 +1555,7 @@
1555
1555
  pack(entryValue);
1556
1556
  }
1557
1557
  }
1558
- } else {
1558
+ } else {
1559
1559
  for (let i = 0, l = extensions.length; i < l; i++) {
1560
1560
  let extensionClass = extensionClasses[i];
1561
1561
  if (value instanceof extensionClass) {
@@ -1623,11 +1623,11 @@
1623
1623
  if (json !== value)
1624
1624
  return pack(json)
1625
1625
  }
1626
-
1626
+
1627
1627
  // if there is a writeFunction, use it, otherwise just encode as undefined
1628
1628
  if (type === 'function')
1629
1629
  return pack(this.writeFunction && this.writeFunction(value));
1630
-
1630
+
1631
1631
  // no extension found, write as plain object
1632
1632
  writeObject(value);
1633
1633
  }
@@ -1685,9 +1685,19 @@
1685
1685
  }
1686
1686
  };
1687
1687
 
1688
- const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber) ? (object) => {
1688
+ const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber || this.skipValues) ? (object) => {
1689
1689
  // this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
1690
- let keys = Object.keys(object);
1690
+ let keys;
1691
+ if (this.skipValues) {
1692
+ keys = [];
1693
+ for (let key in object) {
1694
+ if ((typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) &&
1695
+ !this.skipValues.includes(object[key]))
1696
+ keys.push(key);
1697
+ }
1698
+ } else {
1699
+ keys = Object.keys(object);
1700
+ }
1691
1701
  let length = keys.length;
1692
1702
  if (length < 0x10) {
1693
1703
  target[position++] = 0x80 | length;
@@ -1806,9 +1816,9 @@
1806
1816
  }
1807
1817
  };
1808
1818
 
1809
- // craete reference to useRecords if useRecords is a function
1819
+ // create reference to useRecords if useRecords is a function
1810
1820
  const checkUseRecords = typeof this.useRecords == 'function' && this.useRecords;
1811
-
1821
+
1812
1822
  const writeObject = checkUseRecords ? (object) => {
1813
1823
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1814
1824
  } : writeRecord;
@@ -1936,9 +1946,15 @@
1936
1946
  useBuffer(buffer) {
1937
1947
  // this means we are finished using our own buffer and we can write over it safely
1938
1948
  target = buffer;
1939
- targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
1949
+ target.dataView || (target.dataView = new DataView(target.buffer, target.byteOffset, target.byteLength));
1940
1950
  position = 0;
1941
1951
  }
1952
+ set position (value) {
1953
+ position = value;
1954
+ }
1955
+ get position() {
1956
+ return position;
1957
+ }
1942
1958
  clearSharedData() {
1943
1959
  if (this.structures)
1944
1960
  this.structures = [];
@@ -2284,6 +2300,8 @@
2284
2300
  exports.FLOAT32_OPTIONS = FLOAT32_OPTIONS;
2285
2301
  exports.NEVER = NEVER;
2286
2302
  exports.Packr = Packr;
2303
+ exports.RESERVE_START_SPACE = RESERVE_START_SPACE;
2304
+ exports.RESET_BUFFER_MODE = RESET_BUFFER_MODE;
2287
2305
  exports.REUSE_BUFFER_MODE = REUSE_BUFFER_MODE;
2288
2306
  exports.Unpackr = Unpackr;
2289
2307
  exports.addExtension = addExtension;