msgpackr 1.11.11 → 2.0.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
@@ -29,7 +29,6 @@
29
29
  C1.name = 'MessagePack 0xC1';
30
30
  var sequentialMode = false;
31
31
  var inlineObjectReadThreshold = 2;
32
- var readStruct;
33
32
 
34
33
  class Unpackr {
35
34
  constructor(options) {
@@ -61,8 +60,8 @@
61
60
  // re-entrant execution, save the state and restore it after we do this unpack
62
61
  return saveState(() => {
63
62
  clearSource();
64
- return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
65
- })
63
+ return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
64
+ });
66
65
  }
67
66
  if (!source.buffer && source.constructor === ArrayBuffer)
68
67
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
@@ -86,14 +85,14 @@
86
85
  // if it doesn't have a buffer, maybe it is the wrong type of object
87
86
  src = null;
88
87
  if (source instanceof Uint8Array)
89
- throw error
90
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
88
+ throw error;
89
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
91
90
  }
92
91
  if (this instanceof Unpackr) {
93
92
  currentUnpackr = this;
94
93
  if (this.structures) {
95
94
  currentStructures = this.structures;
96
- return checkedRead(options)
95
+ return checkedRead();
97
96
  } else if (!currentStructures || currentStructures.length > 0) {
98
97
  currentStructures = [];
99
98
  }
@@ -102,7 +101,7 @@
102
101
  if (!currentStructures || currentStructures.length > 0)
103
102
  currentStructures = [];
104
103
  }
105
- return checkedRead(options)
104
+ return checkedRead();
106
105
  }
107
106
  unpackMultiple(source, forEach) {
108
107
  let values, lastPosition = 0;
@@ -115,7 +114,7 @@
115
114
  while(position$1 < size) {
116
115
  lastPosition = position$1;
117
116
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
118
- return
117
+ return;
119
118
  }
120
119
  }
121
120
  }
@@ -125,12 +124,12 @@
125
124
  lastPosition = position$1;
126
125
  values.push(checkedRead());
127
126
  }
128
- return values
127
+ return values;
129
128
  }
130
129
  } catch(error) {
131
130
  error.lastPosition = lastPosition;
132
131
  error.values = values;
133
- throw error
132
+ throw error;
134
133
  } finally {
135
134
  sequentialMode = false;
136
135
  clearSource();
@@ -160,10 +159,10 @@
160
159
  }
161
160
  }
162
161
  }
163
- return this.structures = loadedStructures
162
+ return this.structures = loadedStructures;
164
163
  }
165
164
  decode(source, options) {
166
- return this.unpack(source, options)
165
+ return this.unpack(source, options);
167
166
  }
168
167
  }
169
168
  function checkedRead(options) {
@@ -173,15 +172,7 @@
173
172
  if (sharedLength < currentStructures.length)
174
173
  currentStructures.length = sharedLength;
175
174
  }
176
- let result;
177
- if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct) {
178
- result = readStruct(src, position$1, srcEnd, currentUnpackr);
179
- src = null; // dispose of this so that recursive unpack calls don't save state
180
- if (!(options && options.lazy) && result)
181
- result = result.toJSON();
182
- position$1 = srcEnd;
183
- } else
184
- result = read();
175
+ let result = read();
185
176
  if (bundledStrings$1) { // bundled strings to skip past
186
177
  position$1 = bundledStrings$1.postBundlePosition;
187
178
  bundledStrings$1 = null;
@@ -201,7 +192,7 @@
201
192
  referenceMap = null;
202
193
  } else if (position$1 > srcEnd) {
203
194
  // over read
204
- throw new Error('Unexpected end of MessagePack data')
195
+ throw new Error('Unexpected end of MessagePack data');
205
196
  } else if (!sequentialMode) {
206
197
  let jsonView;
207
198
  try {
@@ -209,10 +200,10 @@
209
200
  } catch(error) {
210
201
  jsonView = '(JSON view not available ' + error + ')';
211
202
  }
212
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
203
+ throw new Error('Data read, but end of buffer not reached ' + jsonView);
213
204
  }
214
205
  // else more to read, but we are reading sequentially, so don't clear source yet
215
- return result
206
+ return result;
216
207
  } catch(error) {
217
208
  if (currentStructures && currentStructures.restoreStructures)
218
209
  restoreStructures();
@@ -220,7 +211,7 @@
220
211
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
221
212
  error.incomplete = true;
222
213
  }
223
- throw error
214
+ throw error;
224
215
  }
225
216
  }
226
217
 
@@ -236,7 +227,7 @@
236
227
  if (token < 0xa0) {
237
228
  if (token < 0x80) {
238
229
  if (token < 0x40)
239
- return token
230
+ return token;
240
231
  else {
241
232
  let structure = currentStructures[token & 0x3f] ||
242
233
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
@@ -244,9 +235,9 @@
244
235
  if (!structure.read) {
245
236
  structure.read = createStructureReader(structure, token & 0x3f);
246
237
  }
247
- return structure.read()
238
+ return structure.read();
248
239
  } else
249
- return token
240
+ return token;
250
241
  }
251
242
  } else if (token < 0x90) {
252
243
  // map
@@ -259,13 +250,13 @@
259
250
  key = '__proto_';
260
251
  object[key] = read();
261
252
  }
262
- return object
253
+ return object;
263
254
  } else {
264
255
  let map = new Map();
265
256
  for (let i = 0; i < token; i++) {
266
257
  map.set(read(), read());
267
258
  }
268
- return map
259
+ return map;
269
260
  }
270
261
  } else {
271
262
  token -= 0x90;
@@ -274,91 +265,91 @@
274
265
  array[i] = read();
275
266
  }
276
267
  if (currentUnpackr.freezeData)
277
- return Object.freeze(array)
278
- return array
268
+ return Object.freeze(array);
269
+ return array;
279
270
  }
280
271
  } else if (token < 0xc0) {
281
272
  // fixstr
282
273
  let length = token - 0xa0;
283
274
  if (srcStringEnd >= position$1) {
284
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
275
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
285
276
  }
286
277
  if (srcStringEnd == 0 && srcEnd < 140) {
287
278
  // for small blocks, avoiding the overhead of the extract call is helpful
288
279
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
289
280
  if (string != null)
290
- return string
281
+ return string;
291
282
  }
292
- return readFixedString(length)
283
+ return readFixedString(length);
293
284
  } else {
294
285
  let value;
295
286
  switch (token) {
296
- case 0xc0: return null
287
+ case 0xc0: return null;
297
288
  case 0xc1:
298
289
  if (bundledStrings$1) {
299
290
  value = read(); // followed by the length of the string in characters (not bytes!)
300
291
  if (value > 0)
301
- return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
292
+ return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value);
302
293
  else
303
- return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
294
+ return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value);
304
295
  }
305
296
  return C1; // "never-used", return special object to denote that
306
- case 0xc2: return false
307
- case 0xc3: return true
297
+ case 0xc2: return false;
298
+ case 0xc3: return true;
308
299
  case 0xc4:
309
300
  // bin 8
310
301
  value = src[position$1++];
311
302
  if (value === undefined)
312
- throw new Error('Unexpected end of buffer')
313
- return readBin(value)
303
+ throw new Error('Unexpected end of buffer');
304
+ return readBin(value);
314
305
  case 0xc5:
315
306
  // bin 16
316
307
  value = dataView.getUint16(position$1);
317
308
  position$1 += 2;
318
- return readBin(value)
309
+ return readBin(value);
319
310
  case 0xc6:
320
311
  // bin 32
321
312
  value = dataView.getUint32(position$1);
322
313
  position$1 += 4;
323
- return readBin(value)
314
+ return readBin(value);
324
315
  case 0xc7:
325
316
  // ext 8
326
- return readExt(src[position$1++])
317
+ return readExt(src[position$1++]);
327
318
  case 0xc8:
328
319
  // ext 16
329
320
  value = dataView.getUint16(position$1);
330
321
  position$1 += 2;
331
- return readExt(value)
322
+ return readExt(value);
332
323
  case 0xc9:
333
324
  // ext 32
334
325
  value = dataView.getUint32(position$1);
335
326
  position$1 += 4;
336
- return readExt(value)
327
+ return readExt(value);
337
328
  case 0xca:
338
329
  value = dataView.getFloat32(position$1);
339
330
  if (currentUnpackr.useFloat32 > 2) {
340
331
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
341
332
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
342
333
  position$1 += 4;
343
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
334
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
344
335
  }
345
336
  position$1 += 4;
346
- return value
337
+ return value;
347
338
  case 0xcb:
348
339
  value = dataView.getFloat64(position$1);
349
340
  position$1 += 8;
350
- return value
341
+ return value;
351
342
  // uint handlers
352
343
  case 0xcc:
353
- return src[position$1++]
344
+ return src[position$1++];
354
345
  case 0xcd:
355
346
  value = dataView.getUint16(position$1);
356
347
  position$1 += 2;
357
- return value
348
+ return value;
358
349
  case 0xce:
359
350
  value = dataView.getUint32(position$1);
360
351
  position$1 += 4;
361
- return value
352
+ return value;
362
353
  case 0xcf:
363
354
  if (currentUnpackr.int64AsType === 'number') {
364
355
  value = dataView.getUint32(position$1) * 0x100000000;
@@ -371,19 +362,19 @@
371
362
  } else
372
363
  value = dataView.getBigUint64(position$1);
373
364
  position$1 += 8;
374
- return value
365
+ return value;
375
366
 
376
367
  // int handlers
377
368
  case 0xd0:
378
- return dataView.getInt8(position$1++)
369
+ return dataView.getInt8(position$1++);
379
370
  case 0xd1:
380
371
  value = dataView.getInt16(position$1);
381
372
  position$1 += 2;
382
- return value
373
+ return value;
383
374
  case 0xd2:
384
375
  value = dataView.getInt32(position$1);
385
376
  position$1 += 4;
386
- return value
377
+ return value;
387
378
  case 0xd3:
388
379
  if (currentUnpackr.int64AsType === 'number') {
389
380
  value = dataView.getInt32(position$1) * 0x100000000;
@@ -396,96 +387,96 @@
396
387
  } else
397
388
  value = dataView.getBigInt64(position$1);
398
389
  position$1 += 8;
399
- return value
390
+ return value;
400
391
 
401
392
  case 0xd4:
402
393
  // fixext 1
403
394
  value = src[position$1++];
404
395
  if (value == 0x72) {
405
- return recordDefinition(src[position$1++] & 0x3f)
396
+ return recordDefinition(src[position$1++] & 0x3f);
406
397
  } else {
407
398
  let extension = currentExtensions[value];
408
399
  if (extension) {
409
400
  if (extension.read) {
410
401
  position$1++; // skip filler byte
411
- return extension.read(read())
402
+ return extension.read(read());
412
403
  } else if (extension.noBuffer) {
413
404
  position$1++; // skip filler byte
414
- return extension()
405
+ return extension();
415
406
  } else
416
- return extension(src.subarray(position$1, ++position$1))
407
+ return extension(src.subarray(position$1, ++position$1));
417
408
  } else
418
- throw new Error('Unknown extension ' + value)
409
+ throw new Error('Unknown extension ' + value);
419
410
  }
420
411
  case 0xd5:
421
412
  // fixext 2
422
413
  value = src[position$1];
423
414
  if (value == 0x72) {
424
415
  position$1++;
425
- return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
416
+ return recordDefinition(src[position$1++] & 0x3f, src[position$1++]);
426
417
  } else
427
- return readExt(2)
418
+ return readExt(2);
428
419
  case 0xd6:
429
420
  // fixext 4
430
- return readExt(4)
421
+ return readExt(4);
431
422
  case 0xd7:
432
423
  // fixext 8
433
- return readExt(8)
424
+ return readExt(8);
434
425
  case 0xd8:
435
426
  // fixext 16
436
- return readExt(16)
427
+ return readExt(16);
437
428
  case 0xd9:
438
429
  // str 8
439
430
  value = src[position$1++];
440
431
  if (srcStringEnd >= position$1) {
441
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
432
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
442
433
  }
443
- return readString8(value)
434
+ return readString8(value);
444
435
  case 0xda:
445
436
  // str 16
446
437
  value = dataView.getUint16(position$1);
447
438
  position$1 += 2;
448
439
  if (srcStringEnd >= position$1) {
449
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
440
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
450
441
  }
451
- return readString16(value)
442
+ return readString16(value);
452
443
  case 0xdb:
453
444
  // str 32
454
445
  value = dataView.getUint32(position$1);
455
446
  position$1 += 4;
456
447
  if (srcStringEnd >= position$1) {
457
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
448
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
458
449
  }
459
- return readString32(value)
450
+ return readString32(value);
460
451
  case 0xdc:
461
452
  // array 16
462
453
  value = dataView.getUint16(position$1);
463
454
  position$1 += 2;
464
- return readArray(value)
455
+ return readArray(value);
465
456
  case 0xdd:
466
457
  // array 32
467
458
  value = dataView.getUint32(position$1);
468
459
  position$1 += 4;
469
- return readArray(value)
460
+ return readArray(value);
470
461
  case 0xde:
471
462
  // map 16
472
463
  value = dataView.getUint16(position$1);
473
464
  position$1 += 2;
474
- return readMap(value)
465
+ return readMap(value);
475
466
  case 0xdf:
476
467
  // map 32
477
468
  value = dataView.getUint32(position$1);
478
469
  position$1 += 4;
479
- return readMap(value)
470
+ return readMap(value);
480
471
  default: // negative int
481
472
  if (token >= 0xe0)
482
- return token - 0x100
473
+ return token - 0x100;
483
474
  if (token === undefined) {
484
475
  let error = new Error('Unexpected end of MessagePack data');
485
476
  error.incomplete = true;
486
- throw error
477
+ throw error;
487
478
  }
488
- throw new Error('Unknown MessagePack token ' + token)
479
+ throw new Error('Unknown MessagePack token ' + token);
489
480
 
490
481
  }
491
482
  }
@@ -506,7 +497,7 @@
506
497
  }
507
498
  if (structure.highByte === 0)
508
499
  structure.read = createSecondByteReader(firstId, structure.read);
509
- return optimizedReadObject() // second byte is already read, if there is one so immediately read object
500
+ return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
510
501
  }
511
502
  let object = {};
512
503
  for (let i = 0, l = structure.length; i < l; i++) {
@@ -517,38 +508,38 @@
517
508
  }
518
509
  if (currentUnpackr.freezeData)
519
510
  return Object.freeze(object);
520
- return object
511
+ return object;
521
512
  }
522
513
  readObject.count = 0;
523
514
  if (structure.highByte === 0) {
524
- return createSecondByteReader(firstId, readObject)
515
+ return createSecondByteReader(firstId, readObject);
525
516
  }
526
- return readObject
517
+ return readObject;
527
518
  }
528
519
 
529
520
  const createSecondByteReader = (firstId, read0) => {
530
521
  return function() {
531
522
  let highByte = src[position$1++];
532
523
  if (highByte === 0)
533
- return read0()
524
+ return read0();
534
525
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
535
526
  let structure = currentStructures[id] || loadStructures()[id];
536
527
  if (!structure) {
537
- throw new Error('Record id is not defined for ' + id)
528
+ throw new Error('Record id is not defined for ' + id);
538
529
  }
539
530
  if (!structure.read)
540
531
  structure.read = createStructureReader(structure, firstId);
541
- return structure.read()
542
- }
532
+ return structure.read();
533
+ };
543
534
  };
544
535
 
545
536
  function loadStructures() {
546
537
  let loadedStructures = saveState(() => {
547
538
  // save the state in case getStructures modifies our buffer
548
539
  src = null;
549
- return currentUnpackr.getStructures()
540
+ return currentUnpackr.getStructures();
550
541
  });
551
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
542
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
552
543
  }
553
544
 
554
545
  var readFixedString = readStringJS;
@@ -560,10 +551,10 @@
560
551
  let result;
561
552
  if (length < 16) {
562
553
  if (result = shortStringInJS(length))
563
- return result
554
+ return result;
564
555
  }
565
556
  if (length > 64 && decoder)
566
- return decoder.decode(src.subarray(position$1, position$1 += length))
557
+ return decoder.decode(src.subarray(position$1, position$1 += length));
567
558
  const end = position$1 + length;
568
559
  const units = [];
569
560
  result = '';
@@ -626,7 +617,7 @@
626
617
  result += fromCharCode.apply(String, units);
627
618
  }
628
619
 
629
- return result
620
+ return result;
630
621
  }
631
622
 
632
623
  function readArray(length) {
@@ -635,8 +626,8 @@
635
626
  array[i] = read();
636
627
  }
637
628
  if (currentUnpackr.freezeData)
638
- return Object.freeze(array)
639
- return array
629
+ return Object.freeze(array);
630
+ return array;
640
631
  }
641
632
 
642
633
  function readMap(length) {
@@ -648,13 +639,13 @@
648
639
  key = '__proto_';
649
640
  object[key] = read();
650
641
  }
651
- return object
642
+ return object;
652
643
  } else {
653
644
  let map = new Map();
654
645
  for (let i = 0; i < length; i++) {
655
646
  map.set(read(), read());
656
647
  }
657
- return map
648
+ return map;
658
649
  }
659
650
  }
660
651
 
@@ -666,40 +657,40 @@
666
657
  const byte = src[position$1++];
667
658
  if ((byte & 0x80) > 0) {
668
659
  position$1 = start;
669
- return
660
+ return;
670
661
  }
671
662
  bytes[i] = byte;
672
663
  }
673
- return fromCharCode.apply(String, bytes)
664
+ return fromCharCode.apply(String, bytes);
674
665
  }
675
666
  function shortStringInJS(length) {
676
667
  if (length < 4) {
677
668
  if (length < 2) {
678
669
  if (length === 0)
679
- return ''
670
+ return '';
680
671
  else {
681
672
  let a = src[position$1++];
682
673
  if ((a & 0x80) > 1) {
683
674
  position$1 -= 1;
684
- return
675
+ return;
685
676
  }
686
- return fromCharCode(a)
677
+ return fromCharCode(a);
687
678
  }
688
679
  } else {
689
680
  let a = src[position$1++];
690
681
  let b = src[position$1++];
691
682
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
692
683
  position$1 -= 2;
693
- return
684
+ return;
694
685
  }
695
686
  if (length < 3)
696
- return fromCharCode(a, b)
687
+ return fromCharCode(a, b);
697
688
  let c = src[position$1++];
698
689
  if ((c & 0x80) > 0) {
699
690
  position$1 -= 3;
700
- return
691
+ return;
701
692
  }
702
- return fromCharCode(a, b, c)
693
+ return fromCharCode(a, b, c);
703
694
  }
704
695
  } else {
705
696
  let a = src[position$1++];
@@ -708,34 +699,34 @@
708
699
  let d = src[position$1++];
709
700
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
710
701
  position$1 -= 4;
711
- return
702
+ return;
712
703
  }
713
704
  if (length < 6) {
714
705
  if (length === 4)
715
- return fromCharCode(a, b, c, d)
706
+ return fromCharCode(a, b, c, d);
716
707
  else {
717
708
  let e = src[position$1++];
718
709
  if ((e & 0x80) > 0) {
719
710
  position$1 -= 5;
720
- return
711
+ return;
721
712
  }
722
- return fromCharCode(a, b, c, d, e)
713
+ return fromCharCode(a, b, c, d, e);
723
714
  }
724
715
  } else if (length < 8) {
725
716
  let e = src[position$1++];
726
717
  let f = src[position$1++];
727
718
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
728
719
  position$1 -= 6;
729
- return
720
+ return;
730
721
  }
731
722
  if (length < 7)
732
- return fromCharCode(a, b, c, d, e, f)
723
+ return fromCharCode(a, b, c, d, e, f);
733
724
  let g = src[position$1++];
734
725
  if ((g & 0x80) > 0) {
735
726
  position$1 -= 7;
736
- return
727
+ return;
737
728
  }
738
- return fromCharCode(a, b, c, d, e, f, g)
729
+ return fromCharCode(a, b, c, d, e, f, g);
739
730
  } else {
740
731
  let e = src[position$1++];
741
732
  let f = src[position$1++];
@@ -743,34 +734,34 @@
743
734
  let h = src[position$1++];
744
735
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
745
736
  position$1 -= 8;
746
- return
737
+ return;
747
738
  }
748
739
  if (length < 10) {
749
740
  if (length === 8)
750
- return fromCharCode(a, b, c, d, e, f, g, h)
741
+ return fromCharCode(a, b, c, d, e, f, g, h);
751
742
  else {
752
743
  let i = src[position$1++];
753
744
  if ((i & 0x80) > 0) {
754
745
  position$1 -= 9;
755
- return
746
+ return;
756
747
  }
757
- return fromCharCode(a, b, c, d, e, f, g, h, i)
748
+ return fromCharCode(a, b, c, d, e, f, g, h, i);
758
749
  }
759
750
  } else if (length < 12) {
760
751
  let i = src[position$1++];
761
752
  let j = src[position$1++];
762
753
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
763
754
  position$1 -= 10;
764
- return
755
+ return;
765
756
  }
766
757
  if (length < 11)
767
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
758
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j);
768
759
  let k = src[position$1++];
769
760
  if ((k & 0x80) > 0) {
770
761
  position$1 -= 11;
771
- return
762
+ return;
772
763
  }
773
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
764
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
774
765
  } else {
775
766
  let i = src[position$1++];
776
767
  let j = src[position$1++];
@@ -778,34 +769,34 @@
778
769
  let l = src[position$1++];
779
770
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
780
771
  position$1 -= 12;
781
- return
772
+ return;
782
773
  }
783
774
  if (length < 14) {
784
775
  if (length === 12)
785
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
776
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
786
777
  else {
787
778
  let m = src[position$1++];
788
779
  if ((m & 0x80) > 0) {
789
780
  position$1 -= 13;
790
- return
781
+ return;
791
782
  }
792
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
783
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
793
784
  }
794
785
  } else {
795
786
  let m = src[position$1++];
796
787
  let n = src[position$1++];
797
788
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
798
789
  position$1 -= 14;
799
- return
790
+ return;
800
791
  }
801
792
  if (length < 15)
802
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
793
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
803
794
  let o = src[position$1++];
804
795
  if ((o & 0x80) > 0) {
805
796
  position$1 -= 15;
806
- return
797
+ return;
807
798
  }
808
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
799
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
809
800
  }
810
801
  }
811
802
  }
@@ -823,22 +814,22 @@
823
814
  case 0xd9:
824
815
  // str 8
825
816
  length = src[position$1++];
826
- break
817
+ break;
827
818
  case 0xda:
828
819
  // str 16
829
820
  length = dataView.getUint16(position$1);
830
821
  position$1 += 2;
831
- break
822
+ break;
832
823
  case 0xdb:
833
824
  // str 32
834
825
  length = dataView.getUint32(position$1);
835
826
  position$1 += 4;
836
- break
827
+ break;
837
828
  default:
838
- throw new Error('Expected string')
829
+ throw new Error('Expected string');
839
830
  }
840
831
  }
841
- return readStringJS(length)
832
+ return readStringJS(length);
842
833
  }
843
834
 
844
835
 
@@ -846,7 +837,7 @@
846
837
  return currentUnpackr.copyBuffers ?
847
838
  // specifically use the copying slice (not the node one)
848
839
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
849
- src.subarray(position$1, position$1 += length)
840
+ src.subarray(position$1, position$1 += length);
850
841
  }
851
842
  function readExt(length) {
852
843
  let type = src[position$1++];
@@ -859,10 +850,10 @@
859
850
  } finally {
860
851
  position$1 = end;
861
852
  }
862
- })
853
+ });
863
854
  }
864
855
  else
865
- throw new Error('Unknown extension type ' + type)
856
+ throw new Error('Unknown extension type ' + type);
866
857
  }
867
858
 
868
859
  var keyCache = new Array(4096);
@@ -872,12 +863,12 @@
872
863
  // fixstr, potentially use key cache
873
864
  length = length - 0xa0;
874
865
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
875
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
866
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
876
867
  else if (!(srcStringEnd == 0 && srcEnd < 180))
877
- return readFixedString(length)
868
+ return readFixedString(length);
878
869
  } else { // not cacheable, go back and do a standard read
879
870
  position$1--;
880
- return asSafeString(read())
871
+ return asSafeString(read());
881
872
  }
882
873
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
883
874
  let entry = keyCache[key];
@@ -890,7 +881,7 @@
890
881
  chunk = dataView.getUint32(checkPosition);
891
882
  if (chunk != entry[i++]) {
892
883
  checkPosition = 0x70000000;
893
- break
884
+ break;
894
885
  }
895
886
  checkPosition += 4;
896
887
  }
@@ -899,12 +890,12 @@
899
890
  chunk = src[checkPosition++];
900
891
  if (chunk != entry[i++]) {
901
892
  checkPosition = 0x70000000;
902
- break
893
+ break;
903
894
  }
904
895
  }
905
896
  if (checkPosition === end) {
906
897
  position$1 = checkPosition;
907
- return entry.string
898
+ return entry.string;
908
899
  }
909
900
  end -= 3;
910
901
  checkPosition = position$1;
@@ -925,8 +916,8 @@
925
916
  // for small blocks, avoiding the overhead of the extract call is helpful
926
917
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
927
918
  if (string != null)
928
- return entry.string = string
929
- return entry.string = readFixedString(length)
919
+ return entry.string = string;
920
+ return entry.string = readFixedString(length);
930
921
  }
931
922
 
932
923
  function asSafeString(property) {
@@ -957,7 +948,7 @@
957
948
  }
958
949
  currentStructures[id] = structure;
959
950
  structure.read = createStructureReader(structure, firstByte);
960
- return structure.read()
951
+ return structure.read();
961
952
  };
962
953
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
963
954
  currentExtensions[0].noBuffer = true;
@@ -979,17 +970,17 @@
979
970
  out <<= BigInt(64);
980
971
  out |= view.getBigUint64(i);
981
972
  }
982
- return out
973
+ return out;
983
974
  }
984
975
  // if (length === 8) return view.getBigUint64(start)
985
976
  let middle = start + (length >> 4 << 3);
986
977
  let left = decode(start, middle);
987
978
  let right = decode(middle, end);
988
- return (left << BigInt((end - middle) * 8)) | right
979
+ return (left << BigInt((end - middle) * 8)) | right;
989
980
  };
990
981
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
991
982
  }
992
- return head
983
+ return head;
993
984
  };
994
985
 
995
986
  let errors = {
@@ -1000,14 +991,14 @@
1000
991
  if (!errors[data[0]]) {
1001
992
  let error = Error(data[1], { cause: data[2] });
1002
993
  error.name = data[0];
1003
- return error
994
+ return error;
1004
995
  }
1005
- return errors[data[0]](data[1], { cause: data[2] })
996
+ return errors[data[0]](data[1], { cause: data[2] });
1006
997
  };
1007
998
 
1008
999
  currentExtensions[0x69] = (data) => {
1009
1000
  // id extension (for structured clones)
1010
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1001
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1011
1002
  let id = dataView.getUint32(position$1 - 4);
1012
1003
  if (!referenceMap)
1013
1004
  referenceMap = new Map();
@@ -1028,7 +1019,7 @@
1028
1019
  let targetProperties = read(); // read the next value as the target object to id
1029
1020
  if (!refEntry.used) {
1030
1021
  // no cycle, can just use the returned read object
1031
- return refEntry.target = targetProperties // replace the placeholder with the real one
1022
+ return refEntry.target = targetProperties; // replace the placeholder with the real one
1032
1023
  } else {
1033
1024
  // there is a cycle, so we have to assign properties to original target
1034
1025
  Object.assign(target, targetProperties);
@@ -1039,16 +1030,16 @@
1039
1030
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1040
1031
  if (target instanceof Set)
1041
1032
  for (let i of Array.from(targetProperties)) target.add(i);
1042
- return target
1033
+ return target;
1043
1034
  };
1044
1035
 
1045
1036
  currentExtensions[0x70] = (data) => {
1046
1037
  // pointer extension (for structured clones)
1047
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1038
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1048
1039
  let id = dataView.getUint32(position$1 - 4);
1049
1040
  let refEntry = referenceMap.get(id);
1050
1041
  refEntry.used = true;
1051
- return refEntry.target
1042
+ return refEntry.target;
1052
1043
  };
1053
1044
 
1054
1045
  currentExtensions[0x73] = () => new Set(read());
@@ -1063,15 +1054,15 @@
1063
1054
 
1064
1055
  let typedArrayName = typedArrays[typeCode];
1065
1056
  if (!typedArrayName) {
1066
- if (typeCode === 16) return buffer
1067
- if (typeCode === 17) return new DataView(buffer)
1068
- throw new Error('Could not find typed array for code ' + typeCode)
1057
+ if (typeCode === 16) return buffer;
1058
+ if (typeCode === 17) return new DataView(buffer);
1059
+ throw new Error('Could not find typed array for code ' + typeCode);
1069
1060
  }
1070
- return new glbl[typedArrayName](buffer)
1061
+ return new glbl[typedArrayName](buffer);
1071
1062
  };
1072
1063
  currentExtensions[0x78] = () => {
1073
1064
  let data = read();
1074
- return new RegExp(data[0], data[1])
1065
+ return new RegExp(data[0], data[1]);
1075
1066
  };
1076
1067
  const TEMP_BUNDLE = [];
1077
1068
  currentExtensions[0x62] = (data) => {
@@ -1084,23 +1075,23 @@
1084
1075
  bundledStrings$1.position1 = 0;
1085
1076
  bundledStrings$1.postBundlePosition = position$1;
1086
1077
  position$1 = dataPosition;
1087
- return read()
1078
+ return read();
1088
1079
  };
1089
1080
 
1090
1081
  currentExtensions[0xff] = (data) => {
1091
1082
  // 32-bit date extension
1092
1083
  if (data.length == 4)
1093
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1084
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
1094
1085
  else if (data.length == 8)
1095
1086
  return new Date(
1096
1087
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1097
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1088
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
1098
1089
  else if (data.length == 12)
1099
1090
  return new Date(
1100
1091
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1101
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1092
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
1102
1093
  else
1103
- return new Date('invalid')
1094
+ return new Date('invalid');
1104
1095
  };
1105
1096
  // registration of bulk record definition?
1106
1097
  // currentExtensions[0x52] = () =>
@@ -1134,7 +1125,7 @@
1134
1125
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1135
1126
  currentUnpackr = savedPackr;
1136
1127
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1137
- return value
1128
+ return value;
1138
1129
  }
1139
1130
  function clearSource() {
1140
1131
  src = null;
@@ -1169,7 +1160,7 @@
1169
1160
  function roundFloat32(float32Number) {
1170
1161
  f32Array[0] = float32Number;
1171
1162
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1172
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1163
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
1173
1164
  }
1174
1165
 
1175
1166
  let textEncoder;
@@ -1179,7 +1170,7 @@
1179
1170
  let extensions, extensionClasses;
1180
1171
  const hasNodeBuffer = typeof Buffer !== 'undefined';
1181
1172
  const ByteArrayAllocate = hasNodeBuffer ?
1182
- function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
1173
+ function(length) { return Buffer.allocUnsafeSlow(length); } : Uint8Array;
1183
1174
  const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1184
1175
  const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1185
1176
  let target, keysTarget;
@@ -1187,7 +1178,6 @@
1187
1178
  let position = 0;
1188
1179
  let safeEnd;
1189
1180
  let bundledStrings = null;
1190
- let writeStructSlots;
1191
1181
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1192
1182
  const hasNonLatin = /[\u0080-\uFFFF]/;
1193
1183
  const RECORD_SYMBOL = Symbol('record-id');
@@ -1200,10 +1190,10 @@
1200
1190
  let structures;
1201
1191
  let referenceMap;
1202
1192
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1203
- return target.utf8Write(string, position, target.byteLength - position)
1193
+ return target.utf8Write(string, position, target.byteLength - position);
1204
1194
  } : (textEncoder && textEncoder.encodeInto) ?
1205
1195
  function(string, position) {
1206
- return textEncoder.encodeInto(string, target.subarray(position)).written
1196
+ return textEncoder.encodeInto(string, target.subarray(position)).written;
1207
1197
  } : false;
1208
1198
 
1209
1199
  let packr = this;
@@ -1215,7 +1205,7 @@
1215
1205
  if (maxSharedStructures == null)
1216
1206
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1217
1207
  if (maxSharedStructures > 8160)
1218
- throw new Error('Maximum maxSharedStructure is 8160')
1208
+ throw new Error('Maximum maxSharedStructure is 8160');
1219
1209
  if (options.structuredClone && options.moreTypes == undefined) {
1220
1210
  this.moreTypes = true;
1221
1211
  }
@@ -1229,7 +1219,7 @@
1229
1219
  let sharedLimitId = maxSharedStructures + 0x40;
1230
1220
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1231
1221
  if (maxStructureId > 8256) {
1232
- throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
1222
+ throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192');
1233
1223
  }
1234
1224
  let recordIdsToRemove = [];
1235
1225
  let transitionsCount = 0;
@@ -1265,7 +1255,7 @@
1265
1255
  let sharedLength = structures.sharedLength || 0;
1266
1256
  if (sharedLength > maxSharedStructures) {
1267
1257
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1268
- throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
1258
+ throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength);
1269
1259
  }
1270
1260
  if (!structures.transitions) {
1271
1261
  // rebuild our structure transitions
@@ -1273,7 +1263,7 @@
1273
1263
  for (let i = 0; i < sharedLength; i++) {
1274
1264
  let keys = structures[i];
1275
1265
  if (!keys)
1276
- continue
1266
+ continue;
1277
1267
  let nextTransition, transition = structures.transitions;
1278
1268
  for (let j = 0, l = keys.length; j < l; j++) {
1279
1269
  let key = keys[j];
@@ -1295,14 +1285,7 @@
1295
1285
  hasSharedUpdate = false;
1296
1286
  let encodingError;
1297
1287
  try {
1298
- if (packr.randomAccessStructure && value && typeof value === 'object') {
1299
- if (value.constructor === Object) writeStruct(value); // simple object
1300
- else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1301
- // allow user classes, if they don't need special handling (but do use toJSON if available)
1302
- writeStruct(value.toJSON ? value.toJSON() : value);
1303
- } else pack(value);
1304
- } else
1305
- pack(value);
1288
+ pack(value);
1306
1289
  let lastBundle = bundledStrings;
1307
1290
  if (bundledStrings)
1308
1291
  writeBundles(start, pack, 0);
@@ -1339,15 +1322,15 @@
1339
1322
  packr.offset = position;
1340
1323
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1341
1324
  referenceMap = null;
1342
- return serialized
1325
+ return serialized;
1343
1326
  }
1344
1327
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1345
1328
  if (encodeOptions & REUSE_BUFFER_MODE) {
1346
1329
  target.start = start;
1347
1330
  target.end = position;
1348
- return target
1331
+ return target;
1349
1332
  }
1350
- return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1333
+ return target.subarray(start, position); // position can change if we call pack again in saveStructures, so we get the buffer now
1351
1334
  } catch(error) {
1352
1335
  encodingError = error;
1353
1336
  throw error;
@@ -1362,12 +1345,12 @@
1362
1345
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1363
1346
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1364
1347
  // get updated structures and try again if the update failed
1365
- return packr.pack(value, encodeOptions)
1348
+ return packr.pack(value, encodeOptions);
1366
1349
  }
1367
1350
  packr.lastNamedStructuresLength = sharedLength;
1368
1351
  // don't keep large buffers around
1369
1352
  if (target.length > 0x40000000) target = null;
1370
- return returnBuffer
1353
+ return returnBuffer;
1371
1354
  }
1372
1355
  }
1373
1356
  }
@@ -1453,7 +1436,7 @@
1453
1436
  bundledStrings[twoByte ? 0 : 1] += value;
1454
1437
  target[position++] = 0xc1;
1455
1438
  pack(twoByte ? -strLength : strLength);
1456
- return
1439
+ return;
1457
1440
  }
1458
1441
  let headerSize;
1459
1442
  // first we estimate the header size, so we can write to the correct location
@@ -1527,7 +1510,7 @@
1527
1510
  } else if (type === 'number') {
1528
1511
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1529
1512
  // positive uint
1530
- if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
1513
+ if (value < 0x40 || (value < 0x80 && this.useRecords === false)) {
1531
1514
  target[position++] = value;
1532
1515
  } else if (value < 0x100) {
1533
1516
  target[position++] = 0xcc;
@@ -1566,7 +1549,7 @@
1566
1549
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1567
1550
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1568
1551
  position += 4;
1569
- return
1552
+ return;
1570
1553
  } else
1571
1554
  position--; // move back into position for writing a double
1572
1555
  }
@@ -1589,7 +1572,7 @@
1589
1572
  target[position++] = 0x70; // "p" for pointer
1590
1573
  targetView.setUint32(position, referee.id);
1591
1574
  position += 4;
1592
- return
1575
+ return;
1593
1576
  } else
1594
1577
  referenceMap.set(value, { offset: position - start });
1595
1578
  }
@@ -1639,7 +1622,7 @@
1639
1622
  } else {
1640
1623
  pack(writeResult);
1641
1624
  }
1642
- return
1625
+ return;
1643
1626
  }
1644
1627
  let currentTarget = target;
1645
1628
  let currentTargetView = targetView;
@@ -1656,7 +1639,7 @@
1656
1639
  makeRoom(position);
1657
1640
  return {
1658
1641
  target, targetView, position: position - size
1659
- }
1642
+ };
1660
1643
  }, pack);
1661
1644
  } finally {
1662
1645
  // restore current target information (unless already restored)
@@ -1672,7 +1655,7 @@
1672
1655
  makeRoom(result.length + position);
1673
1656
  position = writeExtensionData(result, target, position, extension.type);
1674
1657
  }
1675
- return
1658
+ return;
1676
1659
  }
1677
1660
  }
1678
1661
  // check isArray after extensions, because extensions can extend Array
@@ -1684,7 +1667,7 @@
1684
1667
  const json = value.toJSON();
1685
1668
  // if for some reason value.toJSON returns itself it'll loop forever
1686
1669
  if (json !== value)
1687
- return pack(json)
1670
+ return pack(json);
1688
1671
  }
1689
1672
 
1690
1673
  // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -1723,7 +1706,7 @@
1723
1706
  let chunks = [];
1724
1707
  while (true) {
1725
1708
  chunks.push(value & mask);
1726
- if ((value >> BigInt(63)) === empty) break
1709
+ if ((value >> BigInt(63)) === empty) break;
1727
1710
  value >>= BigInt(64);
1728
1711
  }
1729
1712
 
@@ -1755,11 +1738,11 @@
1755
1738
  if (array.length + position > safeEnd)
1756
1739
  makeRoom(array.length + position);
1757
1740
  position = writeExtensionData(array, target, position, 0x42);
1758
- return
1741
+ return;
1759
1742
  } else {
1760
1743
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1761
1744
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1762
- ' largeBigIntToString to convert to string')
1745
+ ' largeBigIntToString to convert to string');
1763
1746
  }
1764
1747
  }
1765
1748
  position += 8;
@@ -1772,7 +1755,7 @@
1772
1755
  target[position++] = 0;
1773
1756
  }
1774
1757
  } else {
1775
- throw new Error('Unknown type: ' + type)
1758
+ throw new Error('Unknown type: ' + type);
1776
1759
  }
1777
1760
  };
1778
1761
 
@@ -1923,7 +1906,7 @@
1923
1906
  if (end > 0x1000000) {
1924
1907
  // special handling for really large buffers
1925
1908
  if ((end - start) > MAX_BUFFER_SIZE)
1926
- throw new Error('Packed buffer would be larger than maximum buffer size')
1909
+ throw new Error('Packed buffer would be larger than maximum buffer size');
1927
1910
  newSize = Math.min(MAX_BUFFER_SIZE,
1928
1911
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1929
1912
  } else // faster handling for smaller buffers
@@ -1938,7 +1921,7 @@
1938
1921
  position -= start;
1939
1922
  start = 0;
1940
1923
  safeEnd = newBuffer.length - 10;
1941
- return target = newBuffer
1924
+ return target = newBuffer;
1942
1925
  };
1943
1926
  const newRecord = (transition, keys, newTransitions) => {
1944
1927
  let recordId = structures.nextId;
@@ -2020,23 +2003,6 @@
2020
2003
  target[insertionOffset + start] = keysTarget[0];
2021
2004
  }
2022
2005
  };
2023
- const writeStruct = (object) => {
2024
- let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
2025
- if (notifySharedUpdate)
2026
- return hasSharedUpdate = true;
2027
- position = newPosition;
2028
- let startTarget = target;
2029
- pack(value);
2030
- resetStructures();
2031
- if (startTarget !== target) {
2032
- return { position, targetView, target }; // indicate the buffer was re-allocated
2033
- }
2034
- return position;
2035
- }, this);
2036
- if (newPosition === 0) // bail and go to a msgpack object
2037
- return writeObject(object);
2038
- position = newPosition;
2039
- };
2040
2006
  }
2041
2007
  useBuffer(buffer) {
2042
2008
  // this means we are finished using our own buffer and we can write over it safely
@@ -2054,8 +2020,6 @@
2054
2020
  clearSharedData() {
2055
2021
  if (this.structures)
2056
2022
  this.structures = [];
2057
- if (this.typedStructs)
2058
- this.typedStructs = [];
2059
2023
  }
2060
2024
  }
2061
2025
 
@@ -2079,7 +2043,7 @@
2079
2043
  } else if (isNaN(seconds)) {
2080
2044
  if (this.onInvalidDate) {
2081
2045
  allocateForWrite(0);
2082
- return pack(this.onInvalidDate())
2046
+ return pack(this.onInvalidDate());
2083
2047
  }
2084
2048
  // Intentionally invalid timestamp
2085
2049
  let { target, targetView, position} = allocateForWrite(3);
@@ -2100,7 +2064,7 @@
2100
2064
  pack(set, allocateForWrite, pack) {
2101
2065
  if (this.setAsEmptyObject) {
2102
2066
  allocateForWrite(0);
2103
- return pack({})
2067
+ return pack({});
2104
2068
  }
2105
2069
  let array = Array.from(set);
2106
2070
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
@@ -2208,19 +2172,19 @@
2208
2172
  switch (length) {
2209
2173
  case 1:
2210
2174
  target[position++] = 0xd4;
2211
- break
2175
+ break;
2212
2176
  case 2:
2213
2177
  target[position++] = 0xd5;
2214
- break
2178
+ break;
2215
2179
  case 4:
2216
2180
  target[position++] = 0xd6;
2217
- break
2181
+ break;
2218
2182
  case 8:
2219
2183
  target[position++] = 0xd7;
2220
- break
2184
+ break;
2221
2185
  case 16:
2222
2186
  target[position++] = 0xd8;
2223
- break
2187
+ break;
2224
2188
  default:
2225
2189
  if (length < 0x100) {
2226
2190
  target[position++] = 0xc7;
@@ -2240,7 +2204,7 @@
2240
2204
  target[position++] = type;
2241
2205
  target.set(result, position);
2242
2206
  position += length;
2243
- return position
2207
+ return position;
2244
2208
  }
2245
2209
 
2246
2210
  function insertIds(serialized, idsToInsert) {
@@ -2262,7 +2226,7 @@
2262
2226
  serialized[position++] = id & 0xff;
2263
2227
  lastEnd = offset;
2264
2228
  }
2265
- return serialized
2229
+ return serialized;
2266
2230
  }
2267
2231
 
2268
2232
  function writeBundles(start, pack, incrementPosition) {
@@ -2279,9 +2243,9 @@
2279
2243
  function addExtension(extension) {
2280
2244
  if (extension.Class) {
2281
2245
  if (!extension.pack && !extension.write)
2282
- throw new Error('Extension has no pack or write function')
2246
+ throw new Error('Extension has no pack or write function');
2283
2247
  if (extension.pack && !extension.type)
2284
- throw new Error('Extension has no type (numeric code to identify the extension)')
2248
+ throw new Error('Extension has no type (numeric code to identify the extension)');
2285
2249
  extensionClasses.unshift(extension.Class);
2286
2250
  extensions.unshift(extension);
2287
2251
  }
@@ -2294,7 +2258,7 @@
2294
2258
  packr._mergeStructures(existingStructures);
2295
2259
  return compatible;
2296
2260
  };
2297
- return structures
2261
+ return structures;
2298
2262
  }
2299
2263
 
2300
2264
  let defaultPackr = new Packr({ useRecords: false });
@@ -2315,13 +2279,13 @@
2315
2279
  */
2316
2280
  function packIter (objectIterator, options = {}) {
2317
2281
  if (!objectIterator || typeof objectIterator !== 'object') {
2318
- throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable')
2282
+ throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable');
2319
2283
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
2320
- return packIterSync(objectIterator, options)
2284
+ return packIterSync(objectIterator, options);
2321
2285
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
2322
- return packIterAsync(objectIterator, options)
2286
+ return packIterAsync(objectIterator, options);
2323
2287
  } else {
2324
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise')
2288
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise');
2325
2289
  }
2326
2290
  }
2327
2291
 
@@ -2348,7 +2312,7 @@
2348
2312
  */
2349
2313
  function unpackIter (bufferIterator, options = {}) {
2350
2314
  if (!bufferIterator || typeof bufferIterator !== 'object') {
2351
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise')
2315
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise');
2352
2316
  }
2353
2317
 
2354
2318
  const unpackr = new Unpackr(options);
@@ -2368,10 +2332,10 @@
2368
2332
  incomplete = chunk.slice(err.lastPosition);
2369
2333
  yields = err.values;
2370
2334
  } else {
2371
- throw err
2335
+ throw err;
2372
2336
  }
2373
2337
  }
2374
- return yields
2338
+ return yields;
2375
2339
  };
2376
2340
 
2377
2341
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
@@ -2379,13 +2343,13 @@
2379
2343
  for (const value of bufferIterator) {
2380
2344
  yield * parser(value);
2381
2345
  }
2382
- })()
2346
+ })();
2383
2347
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
2384
2348
  return (async function * iter () {
2385
2349
  for await (const value of bufferIterator) {
2386
2350
  yield * parser(value);
2387
2351
  }
2388
- })()
2352
+ })();
2389
2353
  }
2390
2354
  }
2391
2355
  const decodeIter = unpackIter;