mol_key 0.0.1476 → 0.0.1478

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
@@ -1437,6 +1437,53 @@ var $;
1437
1437
  });
1438
1438
  })($ || ($ = {}));
1439
1439
 
1440
+ ;
1441
+ "use strict";
1442
+ var $;
1443
+ (function ($) {
1444
+ function $mol_array_chunks(array, rule) {
1445
+ const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
1446
+ let chunk = [];
1447
+ const chunks = [];
1448
+ for (let i = 0; i < array.length; ++i) {
1449
+ const item = array[i];
1450
+ if (br(item, i)) {
1451
+ if (chunk.length)
1452
+ chunks.push(chunk);
1453
+ chunk = [];
1454
+ }
1455
+ chunk.push(item);
1456
+ }
1457
+ if (chunk.length)
1458
+ chunks.push(chunk);
1459
+ return chunks;
1460
+ }
1461
+ $.$mol_array_chunks = $mol_array_chunks;
1462
+ })($ || ($ = {}));
1463
+
1464
+ ;
1465
+ "use strict";
1466
+ var $;
1467
+ (function ($) {
1468
+ $mol_test({
1469
+ 'empty array'() {
1470
+ $mol_assert_equal($mol_array_chunks([], () => true), []);
1471
+ },
1472
+ 'one chunk'() {
1473
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => false), [[1, 2, 3, 4, 5]]);
1474
+ },
1475
+ 'fixed size chunk'() {
1476
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]]);
1477
+ },
1478
+ 'first empty chunk'() {
1479
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], (_, i) => i === 0), [[1, 2, 3, 4, 5]]);
1480
+ },
1481
+ 'chunk for every item'() {
1482
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => true), [[1], [2], [3], [4], [5]]);
1483
+ },
1484
+ });
1485
+ })($ || ($ = {}));
1486
+
1440
1487
  ;
1441
1488
  "use strict";
1442
1489
  var $;
@@ -1634,7 +1681,9 @@ var $;
1634
1681
  }
1635
1682
  if (ArrayBuffer.isView(json)) {
1636
1683
  const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1637
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1684
+ const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
1685
+ const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
1686
+ return $mol_tree2.data(str, [], span);
1638
1687
  }
1639
1688
  if (json instanceof Date) {
1640
1689
  return new $mol_tree2('', json.toISOString(), [], span);
@@ -1673,7 +1722,7 @@ var $;
1673
1722
  $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
1674
1723
  $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
1675
1724
  $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
1676
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
1725
+ $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');
1677
1726
  $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');
1678
1727
  $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');
1679
1728
  },