lib0 0.2.47 → 0.2.50

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.
Files changed (65) hide show
  1. package/README.md +2 -1
  2. package/broadcastchannel.d.ts +3 -3
  3. package/broadcastchannel.d.ts.map +1 -1
  4. package/broadcastchannel.js +5 -4
  5. package/decoding.js +2 -2
  6. package/dist/{broadcastchannel-7da37795.cjs → broadcastchannel-6da71c2f.cjs} +7 -6
  7. package/dist/broadcastchannel-6da71c2f.cjs.map +1 -0
  8. package/dist/broadcastchannel.cjs +2 -2
  9. package/dist/broadcastchannel.d.ts +3 -3
  10. package/dist/broadcastchannel.d.ts.map +1 -1
  11. package/dist/{buffer-b0dea3b0.cjs → buffer-c98f67d5.cjs} +4 -4
  12. package/dist/buffer-c98f67d5.cjs.map +1 -0
  13. package/dist/buffer.cjs +1 -1
  14. package/dist/decoding.cjs +1 -1
  15. package/dist/encoding.cjs +1 -1
  16. package/dist/encoding.test.d.ts +1 -0
  17. package/dist/encoding.test.d.ts.map +1 -1
  18. package/dist/index.cjs +5 -5
  19. package/dist/{iterator-fe01d209.cjs → iterator-9fc627c1.cjs} +1 -4
  20. package/dist/iterator-9fc627c1.cjs.map +1 -0
  21. package/dist/iterator.cjs +1 -1
  22. package/dist/iterator.d.ts.map +1 -1
  23. package/dist/metric.d.ts.map +1 -1
  24. package/dist/{prng-25602bac.cjs → prng-bbec83e2.cjs} +3 -3
  25. package/dist/prng-bbec83e2.cjs.map +1 -0
  26. package/dist/prng.cjs +2 -2
  27. package/dist/prng.d.ts +1 -1
  28. package/dist/random.cjs +7 -1
  29. package/dist/random.cjs.map +1 -1
  30. package/dist/random.d.ts +1 -0
  31. package/dist/random.d.ts.map +1 -1
  32. package/dist/random.test.d.ts +1 -0
  33. package/dist/random.test.d.ts.map +1 -1
  34. package/dist/test.cjs +61 -15
  35. package/dist/test.cjs.map +1 -1
  36. package/dist/test.js +87 -41
  37. package/dist/test.js.map +1 -1
  38. package/dist/testing.cjs +2 -2
  39. package/dist/{tree-92f764b3.cjs → tree-b67c7947.cjs} +9 -2
  40. package/dist/tree-b67c7947.cjs.map +1 -0
  41. package/dist/tree.cjs +1 -1
  42. package/dist/tree.d.ts +13 -5
  43. package/dist/tree.d.ts.map +1 -1
  44. package/encoding.js +1 -1
  45. package/encoding.test.d.ts +1 -0
  46. package/encoding.test.d.ts.map +1 -1
  47. package/iterator.d.ts.map +1 -1
  48. package/iterator.js +0 -3
  49. package/metric.d.ts.map +1 -1
  50. package/package.json +1 -1
  51. package/prng.d.ts +1 -1
  52. package/prng.js +1 -1
  53. package/random.d.ts +1 -0
  54. package/random.d.ts.map +1 -1
  55. package/random.js +6 -1
  56. package/random.test.d.ts +1 -0
  57. package/random.test.d.ts.map +1 -1
  58. package/tree.d.ts +13 -5
  59. package/tree.d.ts.map +1 -1
  60. package/tree.js +8 -1
  61. package/dist/broadcastchannel-7da37795.cjs.map +0 -1
  62. package/dist/buffer-b0dea3b0.cjs.map +0 -1
  63. package/dist/iterator-fe01d209.cjs.map +0 -1
  64. package/dist/prng-25602bac.cjs.map +0 -1
  65. package/dist/tree-92f764b3.cjs.map +0 -1
package/dist/test.js CHANGED
@@ -1547,41 +1547,6 @@
1547
1547
  }
1548
1548
  };
1549
1549
 
1550
- /* eslint-env browser */
1551
- const performance = typeof window === 'undefined' ? null : (typeof window.performance !== 'undefined' && window.performance) || null;
1552
-
1553
- const isoCrypto = typeof crypto === 'undefined' ? null : crypto;
1554
-
1555
- /**
1556
- * @type {function(number):ArrayBuffer}
1557
- */
1558
- const cryptoRandomBuffer = isoCrypto !== null
1559
- ? len => {
1560
- // browser
1561
- const buf = new ArrayBuffer(len);
1562
- const arr = new Uint8Array(buf);
1563
- isoCrypto.getRandomValues(arr);
1564
- return buf
1565
- }
1566
- : len => {
1567
- // polyfill
1568
- const buf = new ArrayBuffer(len);
1569
- const arr = new Uint8Array(buf);
1570
- for (let i = 0; i < len; i++) {
1571
- arr[i] = Math.ceil((Math.random() * 0xFFFFFFFF) >>> 0);
1572
- }
1573
- return buf
1574
- };
1575
-
1576
- /* istanbul ignore next */
1577
- const uint32$1 = () => new Uint32Array(cryptoRandomBuffer(4))[0];
1578
-
1579
- // @ts-ignore
1580
- const uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11;
1581
- const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>
1582
- (c ^ uint32$1() & 15 >> c / 4).toString(16)
1583
- );
1584
-
1585
1550
  /* eslint-env browser */
1586
1551
 
1587
1552
  /**
@@ -1742,6 +1707,45 @@
1742
1707
  BITS32: BITS32
1743
1708
  });
1744
1709
 
1710
+ /* eslint-env browser */
1711
+ const performance = typeof window === 'undefined' ? null : (typeof window.performance !== 'undefined' && window.performance) || null;
1712
+
1713
+ const isoCrypto = typeof crypto === 'undefined' ? null : crypto;
1714
+
1715
+ /**
1716
+ * @type {function(number):ArrayBuffer}
1717
+ */
1718
+ const cryptoRandomBuffer = isoCrypto !== null
1719
+ ? len => {
1720
+ // browser
1721
+ const buf = new ArrayBuffer(len);
1722
+ const arr = new Uint8Array(buf);
1723
+ isoCrypto.getRandomValues(arr);
1724
+ return buf
1725
+ }
1726
+ : len => {
1727
+ // polyfill
1728
+ const buf = new ArrayBuffer(len);
1729
+ const arr = new Uint8Array(buf);
1730
+ for (let i = 0; i < len; i++) {
1731
+ arr[i] = Math.ceil((Math.random() * 0xFFFFFFFF) >>> 0);
1732
+ }
1733
+ return buf
1734
+ };
1735
+
1736
+ const uint32$1 = () => new Uint32Array(cryptoRandomBuffer(4))[0];
1737
+
1738
+ const uint53$1 = () => {
1739
+ const arr = new Uint32Array(cryptoRandomBuffer(8));
1740
+ return (arr[0] & BITS21) * (BITS32 + 1) + (arr[1] >>> 0)
1741
+ };
1742
+
1743
+ // @ts-ignore
1744
+ const uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11;
1745
+ const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>
1746
+ (c ^ uint32$1() & 15 >> c / 4).toString(16)
1747
+ );
1748
+
1745
1749
  /**
1746
1750
  * @module prng
1747
1751
  */
@@ -2349,7 +2353,7 @@
2349
2353
  writeVarString(encoder, data);
2350
2354
  break
2351
2355
  case 'number':
2352
- if (isInteger(data) && data <= BITS31) {
2356
+ if (isInteger(data) && abs(data) <= BITS31) {
2353
2357
  // TYPE 125: INTEGER
2354
2358
  write(encoder, 125);
2355
2359
  writeVarInt(encoder, data);
@@ -2926,7 +2930,7 @@
2926
2930
  return num >>> 0 // return unsigned number!
2927
2931
  }
2928
2932
  /* istanbul ignore if */
2929
- if (len > 35) {
2933
+ if (len > 53) {
2930
2934
  throw new Error('Integer out of range!')
2931
2935
  }
2932
2936
  }
@@ -2960,7 +2964,7 @@
2960
2964
  return sign * (num >>> 0)
2961
2965
  }
2962
2966
  /* istanbul ignore if */
2963
- if (len > 41) {
2967
+ if (len > 53) {
2964
2968
  throw new Error('Integer out of range!')
2965
2969
  }
2966
2970
  }
@@ -3414,7 +3418,7 @@
3414
3418
  /**
3415
3419
  * Description of the function
3416
3420
  * @callback generatorNext
3417
- * @return {number} A 32bit integer
3421
+ * @return {number} A random float in the cange of [0,1)
3418
3422
  */
3419
3423
 
3420
3424
  /**
@@ -4605,8 +4609,8 @@
4605
4609
  }
4606
4610
  });
4607
4611
  });
4612
+ assert(durationConcatElements < durationConcatElementsNative * 1.3, '1.3x faster. We expect that the native approach is slower. If this fails, our expectantion is not met in your javascript environment. Please report this issue.');
4608
4613
  assert(durationConcatElements < durationSingleElements, 'We expect that the second approach is faster. If this fails, our expectantion is not met in your javascript environment. Please report this issue.');
4609
- assert(durationConcatElements < durationConcatElementsNative * 1.3, 'We expect that the native approach is slower. If this fails, our expectantion is not met in your javascript environment. Please report this issue.');
4610
4614
  };
4611
4615
 
4612
4616
  /**
@@ -5087,6 +5091,18 @@
5087
5091
  }
5088
5092
  };
5089
5093
 
5094
+ /**
5095
+ * @param {t.TestCase} tc
5096
+ */
5097
+ const testLargeNumberAnyEncoding = tc => {
5098
+ const encoder = createEncoder();
5099
+ const num = -2.2062063918362897e+50;
5100
+ writeAny(encoder, num);
5101
+ const decoder = createDecoder(toUint8Array(encoder));
5102
+ const readNum = readAny(decoder);
5103
+ assert(readNum === num);
5104
+ };
5105
+
5090
5106
  var encoding = /*#__PURE__*/Object.freeze({
5091
5107
  __proto__: null,
5092
5108
  testGolangBinaryEncodingCompatibility: testGolangBinaryEncodingCompatibility,
@@ -5117,7 +5133,8 @@
5117
5133
  testIntDiffRleEncoder: testIntDiffRleEncoder,
5118
5134
  testIntEncoders: testIntEncoders,
5119
5135
  testIntDiffEncoder: testIntDiffEncoder,
5120
- testStringDecoder: testStringDecoder
5136
+ testStringDecoder: testStringDecoder,
5137
+ testLargeNumberAnyEncoding: testLargeNumberAnyEncoding
5121
5138
  });
5122
5139
 
5123
5140
  /**
@@ -6065,6 +6082,34 @@
6065
6082
  assert(((smallest & BITS32) >>> 0) === smallest, 'Smallest number is 32 bits long.');
6066
6083
  };
6067
6084
 
6085
+ /**
6086
+ * @param {t.TestCase} tc
6087
+ */
6088
+ const testUint53 = tc => {
6089
+ const iterations = 10000;
6090
+ let largest = 0;
6091
+ let smallest = MAX_SAFE_INTEGER;
6092
+ let newNum = 0;
6093
+ let lenSum = 0;
6094
+ let ones = 0;
6095
+ for (let i = 0; i < iterations; i++) {
6096
+ newNum = uint53$1();
6097
+ lenSum += newNum.toString().length;
6098
+ ones += newNum.toString(2).split('').filter(x => x === '1').length;
6099
+ if (newNum > largest) {
6100
+ largest = newNum;
6101
+ }
6102
+ if (newNum < smallest) {
6103
+ smallest = newNum;
6104
+ }
6105
+ }
6106
+ info(`Largest number generated is ${largest}`);
6107
+ info(`Smallest number generated is ${smallest}`);
6108
+ info(`Average decimal length of number is ${lenSum / iterations}`);
6109
+ info(`Average number of 1s in number is ${ones / iterations} (expecting ~26.5)`);
6110
+ assert(largest > MAX_SAFE_INTEGER * 0.9);
6111
+ };
6112
+
6068
6113
  /**
6069
6114
  * @param {t.TestCase} tc
6070
6115
  */
@@ -6096,6 +6141,7 @@
6096
6141
  var random = /*#__PURE__*/Object.freeze({
6097
6142
  __proto__: null,
6098
6143
  testUint32: testUint32,
6144
+ testUint53: testUint53,
6099
6145
  testUuidv4: testUuidv4,
6100
6146
  testUuidv4Overlaps: testUuidv4Overlaps
6101
6147
  });