mol_view_tree2_lib 1.0.111 → 1.0.113

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/web.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/web.test.js CHANGED
@@ -1247,6 +1247,29 @@ var $;
1247
1247
  });
1248
1248
  })($ || ($ = {}));
1249
1249
 
1250
+ ;
1251
+ "use strict";
1252
+ var $;
1253
+ (function ($) {
1254
+ $mol_test({
1255
+ 'empty array'() {
1256
+ $mol_assert_equal($mol_array_chunks([], () => true), []);
1257
+ },
1258
+ 'one chunk'() {
1259
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => false), [[1, 2, 3, 4, 5]]);
1260
+ },
1261
+ 'fixed size chunk'() {
1262
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]]);
1263
+ },
1264
+ 'first empty chunk'() {
1265
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], (_, i) => i === 0), [[1, 2, 3, 4, 5]]);
1266
+ },
1267
+ 'chunk for every item'() {
1268
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => true), [[1], [2], [3], [4], [5]]);
1269
+ },
1270
+ });
1271
+ })($ || ($ = {}));
1272
+
1250
1273
  ;
1251
1274
  "use strict";
1252
1275
  var $;
@@ -1256,7 +1279,7 @@ var $;
1256
1279
  $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
1257
1280
  $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
1258
1281
  $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
1259
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
1282
+ $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');
1260
1283
  $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');
1261
1284
  $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');
1262
1285
  },