mol_mutable 0.0.1136 → 0.0.1137

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
@@ -3737,6 +3737,53 @@ var $;
3737
3737
  });
3738
3738
  })($ || ($ = {}));
3739
3739
 
3740
+ ;
3741
+ "use strict";
3742
+ var $;
3743
+ (function ($) {
3744
+ function $mol_array_chunks(array, rule) {
3745
+ const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
3746
+ let chunk = [];
3747
+ const chunks = [];
3748
+ for (let i = 0; i < array.length; ++i) {
3749
+ const item = array[i];
3750
+ if (br(item, i)) {
3751
+ if (chunk.length)
3752
+ chunks.push(chunk);
3753
+ chunk = [];
3754
+ }
3755
+ chunk.push(item);
3756
+ }
3757
+ if (chunk.length)
3758
+ chunks.push(chunk);
3759
+ return chunks;
3760
+ }
3761
+ $.$mol_array_chunks = $mol_array_chunks;
3762
+ })($ || ($ = {}));
3763
+
3764
+ ;
3765
+ "use strict";
3766
+ var $;
3767
+ (function ($) {
3768
+ $mol_test({
3769
+ 'empty array'() {
3770
+ $mol_assert_equal($mol_array_chunks([], () => true), []);
3771
+ },
3772
+ 'one chunk'() {
3773
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => false), [[1, 2, 3, 4, 5]]);
3774
+ },
3775
+ 'fixed size chunk'() {
3776
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]]);
3777
+ },
3778
+ 'first empty chunk'() {
3779
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], (_, i) => i === 0), [[1, 2, 3, 4, 5]]);
3780
+ },
3781
+ 'chunk for every item'() {
3782
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => true), [[1], [2], [3], [4], [5]]);
3783
+ },
3784
+ });
3785
+ })($ || ($ = {}));
3786
+
3740
3787
  ;
3741
3788
  "use strict";
3742
3789
  var $;
@@ -3934,7 +3981,9 @@ var $;
3934
3981
  }
3935
3982
  if (ArrayBuffer.isView(json)) {
3936
3983
  const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
3937
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
3984
+ const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
3985
+ const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
3986
+ return $mol_tree2.data(str, [], span);
3938
3987
  }
3939
3988
  if (json instanceof Date) {
3940
3989
  return new $mol_tree2('', json.toISOString(), [], span);
@@ -3973,7 +4022,7 @@ var $;
3973
4022
  $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
3974
4023
  $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
3975
4024
  $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
3976
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
4025
+ $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');
3977
4026
  $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');
3978
4027
  $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');
3979
4028
  },