mol_view_tree2_lib 1.0.111 → 1.0.112

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.mjs CHANGED
@@ -722,6 +722,30 @@ var $;
722
722
  $.$mol_view_tree2_normalize = $mol_view_tree2_normalize;
723
723
  })($ || ($ = {}));
724
724
 
725
+ ;
726
+ "use strict";
727
+ var $;
728
+ (function ($) {
729
+ function $mol_array_chunks(array, rule) {
730
+ const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
731
+ let chunk = [];
732
+ const chunks = [];
733
+ for (let i = 0; i < array.length; ++i) {
734
+ const item = array[i];
735
+ if (br(item, i)) {
736
+ if (chunk.length)
737
+ chunks.push(chunk);
738
+ chunk = [];
739
+ }
740
+ chunk.push(item);
741
+ }
742
+ if (chunk.length)
743
+ chunks.push(chunk);
744
+ return chunks;
745
+ }
746
+ $.$mol_array_chunks = $mol_array_chunks;
747
+ })($ || ($ = {}));
748
+
725
749
  ;
726
750
  "use strict";
727
751
  var $;
@@ -742,7 +766,9 @@ var $;
742
766
  }
743
767
  if (ArrayBuffer.isView(json)) {
744
768
  const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
745
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
769
+ const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
770
+ const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
771
+ return $mol_tree2.data(str, [], span);
746
772
  }
747
773
  if (json instanceof Date) {
748
774
  return new $mol_tree2('', json.toISOString(), [], span);
package/node.test.js CHANGED
@@ -713,6 +713,30 @@ var $;
713
713
  $.$mol_view_tree2_normalize = $mol_view_tree2_normalize;
714
714
  })($ || ($ = {}));
715
715
 
716
+ ;
717
+ "use strict";
718
+ var $;
719
+ (function ($) {
720
+ function $mol_array_chunks(array, rule) {
721
+ const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
722
+ let chunk = [];
723
+ const chunks = [];
724
+ for (let i = 0; i < array.length; ++i) {
725
+ const item = array[i];
726
+ if (br(item, i)) {
727
+ if (chunk.length)
728
+ chunks.push(chunk);
729
+ chunk = [];
730
+ }
731
+ chunk.push(item);
732
+ }
733
+ if (chunk.length)
734
+ chunks.push(chunk);
735
+ return chunks;
736
+ }
737
+ $.$mol_array_chunks = $mol_array_chunks;
738
+ })($ || ($ = {}));
739
+
716
740
  ;
717
741
  "use strict";
718
742
  var $;
@@ -733,7 +757,9 @@ var $;
733
757
  }
734
758
  if (ArrayBuffer.isView(json)) {
735
759
  const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
736
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
760
+ const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
761
+ const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
762
+ return $mol_tree2.data(str, [], span);
737
763
  }
738
764
  if (json instanceof Date) {
739
765
  return new $mol_tree2('', json.toISOString(), [], span);
@@ -7063,6 +7089,29 @@ var $;
7063
7089
  });
7064
7090
  })($ || ($ = {}));
7065
7091
 
7092
+ ;
7093
+ "use strict";
7094
+ var $;
7095
+ (function ($) {
7096
+ $mol_test({
7097
+ 'empty array'() {
7098
+ $mol_assert_equal($mol_array_chunks([], () => true), []);
7099
+ },
7100
+ 'one chunk'() {
7101
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => false), [[1, 2, 3, 4, 5]]);
7102
+ },
7103
+ 'fixed size chunk'() {
7104
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]]);
7105
+ },
7106
+ 'first empty chunk'() {
7107
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], (_, i) => i === 0), [[1, 2, 3, 4, 5]]);
7108
+ },
7109
+ 'chunk for every item'() {
7110
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => true), [[1], [2], [3], [4], [5]]);
7111
+ },
7112
+ });
7113
+ })($ || ($ = {}));
7114
+
7066
7115
  ;
7067
7116
  "use strict";
7068
7117
  var $;
@@ -7072,7 +7121,7 @@ var $;
7072
7121
  $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
7073
7122
  $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
7074
7123
  $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
7075
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
7124
+ $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');
7076
7125
  $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');
7077
7126
  $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');
7078
7127
  },