mol_tree2 1.0.567 → 1.0.568
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 +41 -33
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.test.js +41 -33
- package/web.test.js.map +1 -1
package/package.json
CHANGED
package/web.test.js
CHANGED
|
@@ -419,7 +419,12 @@ var $;
|
|
|
419
419
|
var $;
|
|
420
420
|
(function ($) {
|
|
421
421
|
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
422
|
-
|
|
422
|
+
const source = typeof item === 'function' ? new $mol_range2_array() : item;
|
|
423
|
+
if (typeof item !== 'function') {
|
|
424
|
+
item = index => source[index];
|
|
425
|
+
size = () => source.length;
|
|
426
|
+
}
|
|
427
|
+
return new Proxy(source, {
|
|
423
428
|
get(target, field) {
|
|
424
429
|
if (typeof field === 'string') {
|
|
425
430
|
if (field === 'length')
|
|
@@ -432,7 +437,7 @@ var $;
|
|
|
432
437
|
if (index === Math.trunc(index))
|
|
433
438
|
return item(index);
|
|
434
439
|
}
|
|
435
|
-
return
|
|
440
|
+
return $mol_range2_array.prototype[field];
|
|
436
441
|
},
|
|
437
442
|
set(target, field) {
|
|
438
443
|
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
@@ -473,13 +478,16 @@ var $;
|
|
|
473
478
|
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
474
479
|
}
|
|
475
480
|
filter(check, context) {
|
|
476
|
-
const filtered =
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
481
|
+
const filtered = [];
|
|
482
|
+
let cursor = -1;
|
|
483
|
+
return $mol_range2(index => {
|
|
484
|
+
while (cursor < this.length && index >= filtered.length - 1) {
|
|
485
|
+
const val = this[++cursor];
|
|
486
|
+
if (check(val, cursor, this))
|
|
487
|
+
filtered.push(val);
|
|
488
|
+
}
|
|
489
|
+
return filtered[index];
|
|
490
|
+
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
|
|
483
491
|
}
|
|
484
492
|
forEach(proceed, context) {
|
|
485
493
|
for (let [key, value] of this.entries())
|
|
@@ -539,7 +547,7 @@ var $;
|
|
|
539
547
|
'lazy calls'() {
|
|
540
548
|
let calls = 0;
|
|
541
549
|
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
542
|
-
$
|
|
550
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
543
551
|
$mol_assert_equal(list.length, 10);
|
|
544
552
|
$mol_assert_equal(list[-1], undefined);
|
|
545
553
|
$mol_assert_equal(list[0], 0);
|
|
@@ -582,11 +590,17 @@ var $;
|
|
|
582
590
|
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
583
591
|
$mol_assert_equal(log, '01234');
|
|
584
592
|
},
|
|
593
|
+
'reduce'() {
|
|
594
|
+
let calls = 0;
|
|
595
|
+
const list = $mol_range2().slice(1, 6);
|
|
596
|
+
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
597
|
+
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
598
|
+
},
|
|
585
599
|
'lazy concat'() {
|
|
586
600
|
let calls1 = 0;
|
|
587
601
|
let calls2 = 0;
|
|
588
602
|
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
589
|
-
$
|
|
603
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
590
604
|
$mol_assert_equal(list.length, 15);
|
|
591
605
|
$mol_assert_equal(list[0], 0);
|
|
592
606
|
$mol_assert_equal(list[4], 4);
|
|
@@ -598,32 +612,26 @@ var $;
|
|
|
598
612
|
$mol_assert_equal(calls1, 2);
|
|
599
613
|
$mol_assert_equal(calls2, 2);
|
|
600
614
|
},
|
|
601
|
-
'filter'() {
|
|
615
|
+
'lazy filter'() {
|
|
602
616
|
let calls = 0;
|
|
603
|
-
const list = $mol_range2(index => (++calls, index), () =>
|
|
604
|
-
$
|
|
617
|
+
const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
|
|
618
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
605
619
|
$mol_assert_equal(list.length, 3);
|
|
606
620
|
$mol_assert_equal(list[0], 1);
|
|
607
621
|
$mol_assert_equal(list[2], 5);
|
|
608
622
|
$mol_assert_equal(list[3], undefined);
|
|
609
|
-
$mol_assert_equal(calls,
|
|
623
|
+
$mol_assert_equal(calls, 8);
|
|
610
624
|
},
|
|
611
|
-
'reverse'() {
|
|
625
|
+
'lazy reverse'() {
|
|
612
626
|
let calls = 0;
|
|
613
627
|
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
614
|
-
$
|
|
628
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
615
629
|
$mol_assert_equal(list.length, 3);
|
|
616
630
|
$mol_assert_equal(list[0], 9);
|
|
617
631
|
$mol_assert_equal(list[2], 7);
|
|
618
632
|
$mol_assert_equal(list[3], undefined);
|
|
619
633
|
$mol_assert_equal(calls, 2);
|
|
620
634
|
},
|
|
621
|
-
'reduce'() {
|
|
622
|
-
let calls = 0;
|
|
623
|
-
const list = $mol_range2().slice(1, 6);
|
|
624
|
-
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
625
|
-
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
626
|
-
},
|
|
627
635
|
'lazy map'() {
|
|
628
636
|
let calls1 = 0;
|
|
629
637
|
let calls2 = 0;
|
|
@@ -633,7 +641,7 @@ var $;
|
|
|
633
641
|
$mol_assert_equal(source, self);
|
|
634
642
|
return index + 10;
|
|
635
643
|
}, () => 5);
|
|
636
|
-
$
|
|
644
|
+
$mol_assert_equal(true, target instanceof Array);
|
|
637
645
|
$mol_assert_equal(target.length, 5);
|
|
638
646
|
$mol_assert_equal(target[0], 10);
|
|
639
647
|
$mol_assert_equal(target[4], 14);
|
|
@@ -644,7 +652,7 @@ var $;
|
|
|
644
652
|
'lazy slice'() {
|
|
645
653
|
let calls = 0;
|
|
646
654
|
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
647
|
-
$
|
|
655
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
648
656
|
$mol_assert_equal(list.length, 4);
|
|
649
657
|
$mol_assert_equal(list[0], 3);
|
|
650
658
|
$mol_assert_equal(list[3], 6);
|
|
@@ -653,22 +661,22 @@ var $;
|
|
|
653
661
|
},
|
|
654
662
|
'lazy some'() {
|
|
655
663
|
let calls = 0;
|
|
656
|
-
$
|
|
664
|
+
$mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
657
665
|
$mol_assert_equal(calls, 3);
|
|
658
|
-
$
|
|
659
|
-
$
|
|
666
|
+
$mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
|
|
667
|
+
$mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
|
|
660
668
|
},
|
|
661
669
|
'lazy every'() {
|
|
662
670
|
let calls = 0;
|
|
663
|
-
$
|
|
671
|
+
$mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
664
672
|
$mol_assert_equal(calls, 3);
|
|
665
|
-
$
|
|
666
|
-
$
|
|
673
|
+
$mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
|
|
674
|
+
$mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
|
|
667
675
|
},
|
|
668
676
|
'lazyfy'() {
|
|
669
677
|
let calls = 0;
|
|
670
|
-
const list =
|
|
671
|
-
$
|
|
678
|
+
const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
679
|
+
$mol_assert_equal(true, list instanceof Array);
|
|
672
680
|
$mol_assert_equal(list.length, 4);
|
|
673
681
|
$mol_assert_equal(calls, 0);
|
|
674
682
|
$mol_assert_equal(list[0], 12);
|