mol_compare_deep 0.0.1491 → 0.0.1493

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/node.test.js CHANGED
@@ -1514,6 +1514,53 @@ var $;
1514
1514
  });
1515
1515
  })($ || ($ = {}));
1516
1516
 
1517
+ ;
1518
+ "use strict";
1519
+ var $;
1520
+ (function ($) {
1521
+ function $mol_array_chunks(array, rule) {
1522
+ const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
1523
+ let chunk = [];
1524
+ const chunks = [];
1525
+ for (let i = 0; i < array.length; ++i) {
1526
+ const item = array[i];
1527
+ if (br(item, i)) {
1528
+ if (chunk.length)
1529
+ chunks.push(chunk);
1530
+ chunk = [];
1531
+ }
1532
+ chunk.push(item);
1533
+ }
1534
+ if (chunk.length)
1535
+ chunks.push(chunk);
1536
+ return chunks;
1537
+ }
1538
+ $.$mol_array_chunks = $mol_array_chunks;
1539
+ })($ || ($ = {}));
1540
+
1541
+ ;
1542
+ "use strict";
1543
+ var $;
1544
+ (function ($) {
1545
+ $mol_test({
1546
+ 'empty array'() {
1547
+ $mol_assert_equal($mol_array_chunks([], () => true), []);
1548
+ },
1549
+ 'one chunk'() {
1550
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => false), [[1, 2, 3, 4, 5]]);
1551
+ },
1552
+ 'fixed size chunk'() {
1553
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]]);
1554
+ },
1555
+ 'first empty chunk'() {
1556
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], (_, i) => i === 0), [[1, 2, 3, 4, 5]]);
1557
+ },
1558
+ 'chunk for every item'() {
1559
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => true), [[1], [2], [3], [4], [5]]);
1560
+ },
1561
+ });
1562
+ })($ || ($ = {}));
1563
+
1517
1564
  ;
1518
1565
  "use strict";
1519
1566
  var $;
@@ -1711,7 +1758,9 @@ var $;
1711
1758
  }
1712
1759
  if (ArrayBuffer.isView(json)) {
1713
1760
  const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1714
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1761
+ const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
1762
+ const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
1763
+ return $mol_tree2.data(str, [], span);
1715
1764
  }
1716
1765
  if (json instanceof Date) {
1717
1766
  return new $mol_tree2('', json.toISOString(), [], span);
@@ -1750,7 +1799,7 @@ var $;
1750
1799
  $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
1751
1800
  $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
1752
1801
  $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
1753
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
1802
+ $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 255, 256, 65535])).toString(), '\\01 00 0A 00 FF 00 00 01\n\\FF FF\n');
1754
1803
  $mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
1755
1804
  $mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
1756
1805
  },