mol_tree2 1.0.1310 → 1.0.1312

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
@@ -613,6 +613,30 @@ var $;
613
613
  $.$mol_tree2_empty = $mol_tree2_empty;
614
614
  })($ || ($ = {}));
615
615
 
616
+ ;
617
+ "use strict";
618
+ var $;
619
+ (function ($) {
620
+ function $mol_array_chunks(array, rule) {
621
+ const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
622
+ let chunk = [];
623
+ const chunks = [];
624
+ for (let i = 0; i < array.length; ++i) {
625
+ const item = array[i];
626
+ if (br(item, i)) {
627
+ if (chunk.length)
628
+ chunks.push(chunk);
629
+ chunk = [];
630
+ }
631
+ chunk.push(item);
632
+ }
633
+ if (chunk.length)
634
+ chunks.push(chunk);
635
+ return chunks;
636
+ }
637
+ $.$mol_array_chunks = $mol_array_chunks;
638
+ })($ || ($ = {}));
639
+
616
640
  ;
617
641
  "use strict";
618
642
  var $;
@@ -633,7 +657,9 @@ var $;
633
657
  }
634
658
  if (ArrayBuffer.isView(json)) {
635
659
  const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
636
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
660
+ const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
661
+ const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
662
+ return $mol_tree2.data(str, [], span);
637
663
  }
638
664
  if (json instanceof Date) {
639
665
  return new $mol_tree2('', json.toISOString(), [], span);
@@ -4626,6 +4652,29 @@ var $;
4626
4652
  });
4627
4653
  })($ || ($ = {}));
4628
4654
 
4655
+ ;
4656
+ "use strict";
4657
+ var $;
4658
+ (function ($) {
4659
+ $mol_test({
4660
+ 'empty array'() {
4661
+ $mol_assert_equal($mol_array_chunks([], () => true), []);
4662
+ },
4663
+ 'one chunk'() {
4664
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => false), [[1, 2, 3, 4, 5]]);
4665
+ },
4666
+ 'fixed size chunk'() {
4667
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]]);
4668
+ },
4669
+ 'first empty chunk'() {
4670
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], (_, i) => i === 0), [[1, 2, 3, 4, 5]]);
4671
+ },
4672
+ 'chunk for every item'() {
4673
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => true), [[1], [2], [3], [4], [5]]);
4674
+ },
4675
+ });
4676
+ })($ || ($ = {}));
4677
+
4629
4678
  ;
4630
4679
  "use strict";
4631
4680
  var $;
@@ -4635,7 +4684,7 @@ var $;
4635
4684
  $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
4636
4685
  $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
4637
4686
  $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
4638
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
4687
+ $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');
4639
4688
  $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');
4640
4689
  $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');
4641
4690
  },