mol_compare_deep 0.0.756 → 0.0.757

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
@@ -1791,7 +1791,12 @@ var $;
1791
1791
  var $;
1792
1792
  (function ($) {
1793
1793
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
1794
- return new Proxy(new $mol_range2_array(), {
1794
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
1795
+ if (typeof item !== 'function') {
1796
+ item = index => source[index];
1797
+ size = () => source.length;
1798
+ }
1799
+ return new Proxy(source, {
1795
1800
  get(target, field) {
1796
1801
  if (typeof field === 'string') {
1797
1802
  if (field === 'length')
@@ -1804,7 +1809,7 @@ var $;
1804
1809
  if (index === Math.trunc(index))
1805
1810
  return item(index);
1806
1811
  }
1807
- return target[field];
1812
+ return $mol_range2_array.prototype[field];
1808
1813
  },
1809
1814
  set(target, field) {
1810
1815
  return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
@@ -1845,13 +1850,16 @@ var $;
1845
1850
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
1846
1851
  }
1847
1852
  filter(check, context) {
1848
- const filtered = new $mol_range2_array();
1849
- for (let index = 0; index < this.length; ++index) {
1850
- const item = this[index];
1851
- if (check.call(context, item, index, this))
1852
- filtered.push(item);
1853
- }
1854
- return filtered;
1853
+ const filtered = [];
1854
+ let cursor = -1;
1855
+ return $mol_range2(index => {
1856
+ while (cursor < this.length && index >= filtered.length - 1) {
1857
+ const val = this[++cursor];
1858
+ if (check(val, cursor, this))
1859
+ filtered.push(val);
1860
+ }
1861
+ return filtered[index];
1862
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
1855
1863
  }
1856
1864
  forEach(proceed, context) {
1857
1865
  for (let [key, value] of this.entries())
@@ -1911,7 +1919,7 @@ var $;
1911
1919
  'lazy calls'() {
1912
1920
  let calls = 0;
1913
1921
  const list = $mol_range2(index => (++calls, index), () => 10);
1914
- $mol_assert_ok(list instanceof Array);
1922
+ $mol_assert_equal(true, list instanceof Array);
1915
1923
  $mol_assert_equal(list.length, 10);
1916
1924
  $mol_assert_equal(list[-1], undefined);
1917
1925
  $mol_assert_equal(list[0], 0);
@@ -1954,11 +1962,17 @@ var $;
1954
1962
  $mol_range2(i => i, () => 5).forEach(i => log += i);
1955
1963
  $mol_assert_equal(log, '01234');
1956
1964
  },
1965
+ 'reduce'() {
1966
+ let calls = 0;
1967
+ const list = $mol_range2().slice(1, 6);
1968
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
1969
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
1970
+ },
1957
1971
  'lazy concat'() {
1958
1972
  let calls1 = 0;
1959
1973
  let calls2 = 0;
1960
1974
  const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
1961
- $mol_assert_ok(list instanceof Array);
1975
+ $mol_assert_equal(true, list instanceof Array);
1962
1976
  $mol_assert_equal(list.length, 15);
1963
1977
  $mol_assert_equal(list[0], 0);
1964
1978
  $mol_assert_equal(list[4], 4);
@@ -1970,32 +1984,26 @@ var $;
1970
1984
  $mol_assert_equal(calls1, 2);
1971
1985
  $mol_assert_equal(calls2, 2);
1972
1986
  },
1973
- 'filter'() {
1987
+ 'lazy filter'() {
1974
1988
  let calls = 0;
1975
- const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
1976
- $mol_assert_ok(list instanceof Array);
1989
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
1990
+ $mol_assert_equal(true, list instanceof Array);
1977
1991
  $mol_assert_equal(list.length, 3);
1978
1992
  $mol_assert_equal(list[0], 1);
1979
1993
  $mol_assert_equal(list[2], 5);
1980
1994
  $mol_assert_equal(list[3], undefined);
1981
- $mol_assert_equal(calls, 10);
1995
+ $mol_assert_equal(calls, 8);
1982
1996
  },
1983
- 'reverse'() {
1997
+ 'lazy reverse'() {
1984
1998
  let calls = 0;
1985
1999
  const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
1986
- $mol_assert_ok(list instanceof Array);
2000
+ $mol_assert_equal(true, list instanceof Array);
1987
2001
  $mol_assert_equal(list.length, 3);
1988
2002
  $mol_assert_equal(list[0], 9);
1989
2003
  $mol_assert_equal(list[2], 7);
1990
2004
  $mol_assert_equal(list[3], undefined);
1991
2005
  $mol_assert_equal(calls, 2);
1992
2006
  },
1993
- 'reduce'() {
1994
- let calls = 0;
1995
- const list = $mol_range2().slice(1, 6);
1996
- $mol_assert_equal(list.reduce((s, v) => s + v), 15);
1997
- $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
1998
- },
1999
2007
  'lazy map'() {
2000
2008
  let calls1 = 0;
2001
2009
  let calls2 = 0;
@@ -2005,7 +2013,7 @@ var $;
2005
2013
  $mol_assert_equal(source, self);
2006
2014
  return index + 10;
2007
2015
  }, () => 5);
2008
- $mol_assert_ok(target instanceof Array);
2016
+ $mol_assert_equal(true, target instanceof Array);
2009
2017
  $mol_assert_equal(target.length, 5);
2010
2018
  $mol_assert_equal(target[0], 10);
2011
2019
  $mol_assert_equal(target[4], 14);
@@ -2016,7 +2024,7 @@ var $;
2016
2024
  'lazy slice'() {
2017
2025
  let calls = 0;
2018
2026
  const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
2019
- $mol_assert_ok(list instanceof Array);
2027
+ $mol_assert_equal(true, list instanceof Array);
2020
2028
  $mol_assert_equal(list.length, 4);
2021
2029
  $mol_assert_equal(list[0], 3);
2022
2030
  $mol_assert_equal(list[3], 6);
@@ -2025,22 +2033,22 @@ var $;
2025
2033
  },
2026
2034
  'lazy some'() {
2027
2035
  let calls = 0;
2028
- $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
2036
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
2029
2037
  $mol_assert_equal(calls, 3);
2030
- $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
2031
- $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
2038
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
2039
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
2032
2040
  },
2033
2041
  'lazy every'() {
2034
2042
  let calls = 0;
2035
- $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
2043
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
2036
2044
  $mol_assert_equal(calls, 3);
2037
- $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
2038
- $mol_assert_not($mol_range2(i => i).every(v => v < 5));
2045
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
2046
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
2039
2047
  },
2040
2048
  'lazyfy'() {
2041
2049
  let calls = 0;
2042
- const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
2043
- $mol_assert_ok(list instanceof Array);
2050
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
2051
+ $mol_assert_equal(true, list instanceof Array);
2044
2052
  $mol_assert_equal(list.length, 4);
2045
2053
  $mol_assert_equal(calls, 0);
2046
2054
  $mol_assert_equal(list[0], 12);