mol_vary 0.0.109 → 0.0.111

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
@@ -1946,6 +1946,30 @@ var $;
1946
1946
  $.$mol_tree2_from_string = $mol_tree2_from_string;
1947
1947
  })($ || ($ = {}));
1948
1948
 
1949
+ ;
1950
+ "use strict";
1951
+ var $;
1952
+ (function ($) {
1953
+ function $mol_array_chunks(array, rule) {
1954
+ const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
1955
+ let chunk = [];
1956
+ const chunks = [];
1957
+ for (let i = 0; i < array.length; ++i) {
1958
+ const item = array[i];
1959
+ if (br(item, i)) {
1960
+ if (chunk.length)
1961
+ chunks.push(chunk);
1962
+ chunk = [];
1963
+ }
1964
+ chunk.push(item);
1965
+ }
1966
+ if (chunk.length)
1967
+ chunks.push(chunk);
1968
+ return chunks;
1969
+ }
1970
+ $.$mol_array_chunks = $mol_array_chunks;
1971
+ })($ || ($ = {}));
1972
+
1949
1973
  ;
1950
1974
  "use strict";
1951
1975
  var $;
@@ -1966,7 +1990,9 @@ var $;
1966
1990
  }
1967
1991
  if (ArrayBuffer.isView(json)) {
1968
1992
  const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1969
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1993
+ const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
1994
+ const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
1995
+ return $mol_tree2.data(str, [], span);
1970
1996
  }
1971
1997
  if (json instanceof Date) {
1972
1998
  return new $mol_tree2('', json.toISOString(), [], span);
package/node.test.js CHANGED
@@ -1937,6 +1937,30 @@ var $;
1937
1937
  $.$mol_tree2_from_string = $mol_tree2_from_string;
1938
1938
  })($ || ($ = {}));
1939
1939
 
1940
+ ;
1941
+ "use strict";
1942
+ var $;
1943
+ (function ($) {
1944
+ function $mol_array_chunks(array, rule) {
1945
+ const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
1946
+ let chunk = [];
1947
+ const chunks = [];
1948
+ for (let i = 0; i < array.length; ++i) {
1949
+ const item = array[i];
1950
+ if (br(item, i)) {
1951
+ if (chunk.length)
1952
+ chunks.push(chunk);
1953
+ chunk = [];
1954
+ }
1955
+ chunk.push(item);
1956
+ }
1957
+ if (chunk.length)
1958
+ chunks.push(chunk);
1959
+ return chunks;
1960
+ }
1961
+ $.$mol_array_chunks = $mol_array_chunks;
1962
+ })($ || ($ = {}));
1963
+
1940
1964
  ;
1941
1965
  "use strict";
1942
1966
  var $;
@@ -1957,7 +1981,9 @@ var $;
1957
1981
  }
1958
1982
  if (ArrayBuffer.isView(json)) {
1959
1983
  const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1960
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1984
+ const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
1985
+ const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
1986
+ return $mol_tree2.data(str, [], span);
1961
1987
  }
1962
1988
  if (json instanceof Date) {
1963
1989
  return new $mol_tree2('', json.toISOString(), [], span);
@@ -4842,6 +4868,29 @@ var $;
4842
4868
  });
4843
4869
  })($ || ($ = {}));
4844
4870
 
4871
+ ;
4872
+ "use strict";
4873
+ var $;
4874
+ (function ($) {
4875
+ $mol_test({
4876
+ 'empty array'() {
4877
+ $mol_assert_equal($mol_array_chunks([], () => true), []);
4878
+ },
4879
+ 'one chunk'() {
4880
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => false), [[1, 2, 3, 4, 5]]);
4881
+ },
4882
+ 'fixed size chunk'() {
4883
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]]);
4884
+ },
4885
+ 'first empty chunk'() {
4886
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], (_, i) => i === 0), [[1, 2, 3, 4, 5]]);
4887
+ },
4888
+ 'chunk for every item'() {
4889
+ $mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => true), [[1], [2], [3], [4], [5]]);
4890
+ },
4891
+ });
4892
+ })($ || ($ = {}));
4893
+
4845
4894
  ;
4846
4895
  "use strict";
4847
4896
  var $;
@@ -4921,7 +4970,7 @@ var $;
4921
4970
  $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
4922
4971
  $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
4923
4972
  $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
4924
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
4973
+ $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');
4925
4974
  $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');
4926
4975
  $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');
4927
4976
  },