mol_tree2 1.0.444 → 1.0.446
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 +296 -2
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.test.js +296 -2
- package/web.test.js.map +1 -1
package/package.json
CHANGED
package/web.test.js
CHANGED
|
@@ -402,6 +402,298 @@ var $;
|
|
|
402
402
|
;
|
|
403
403
|
"use strict";
|
|
404
404
|
var $;
|
|
405
|
+
(function ($) {
|
|
406
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
407
|
+
for (;;) {
|
|
408
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
409
|
+
if (exists(id))
|
|
410
|
+
continue;
|
|
411
|
+
return id;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
$.$mol_guid = $mol_guid;
|
|
415
|
+
})($ || ($ = {}));
|
|
416
|
+
//mol/guid/guid.ts
|
|
417
|
+
;
|
|
418
|
+
"use strict";
|
|
419
|
+
var $;
|
|
420
|
+
(function ($) {
|
|
421
|
+
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
422
|
+
return new Proxy(new $mol_range2_array(), {
|
|
423
|
+
get(target, field) {
|
|
424
|
+
if (typeof field === 'string') {
|
|
425
|
+
if (field === 'length')
|
|
426
|
+
return size();
|
|
427
|
+
const index = Number(field);
|
|
428
|
+
if (index < 0)
|
|
429
|
+
return undefined;
|
|
430
|
+
if (index >= size())
|
|
431
|
+
return undefined;
|
|
432
|
+
if (index === Math.trunc(index))
|
|
433
|
+
return item(index);
|
|
434
|
+
}
|
|
435
|
+
return target[field];
|
|
436
|
+
},
|
|
437
|
+
set(target, field) {
|
|
438
|
+
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
439
|
+
},
|
|
440
|
+
ownKeys(target) {
|
|
441
|
+
return [...Array(size())].map((v, i) => String(i)).concat('length');
|
|
442
|
+
},
|
|
443
|
+
getOwnPropertyDescriptor(target, field) {
|
|
444
|
+
if (field === "length")
|
|
445
|
+
return {
|
|
446
|
+
value: size(),
|
|
447
|
+
writable: true,
|
|
448
|
+
enumerable: false,
|
|
449
|
+
configurable: false,
|
|
450
|
+
};
|
|
451
|
+
const index = Number(field);
|
|
452
|
+
if (index === Math.trunc(index))
|
|
453
|
+
return {
|
|
454
|
+
get: () => this.get(target, field, this),
|
|
455
|
+
enumerable: true,
|
|
456
|
+
configurable: true,
|
|
457
|
+
};
|
|
458
|
+
return Object.getOwnPropertyDescriptor(target, field);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
$.$mol_range2 = $mol_range2;
|
|
463
|
+
class $mol_range2_array extends Array {
|
|
464
|
+
concat(...tail) {
|
|
465
|
+
if (tail.length === 0)
|
|
466
|
+
return this;
|
|
467
|
+
if (tail.length > 1) {
|
|
468
|
+
let list = this;
|
|
469
|
+
for (let item of tail)
|
|
470
|
+
list = list.concat(item);
|
|
471
|
+
return list;
|
|
472
|
+
}
|
|
473
|
+
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
474
|
+
}
|
|
475
|
+
filter(check, context) {
|
|
476
|
+
const filtered = new $mol_range2_array();
|
|
477
|
+
for (let index = 0; index < this.length; ++index) {
|
|
478
|
+
const item = this[index];
|
|
479
|
+
if (check.call(context, item, index, this))
|
|
480
|
+
filtered.push(item);
|
|
481
|
+
}
|
|
482
|
+
return filtered;
|
|
483
|
+
}
|
|
484
|
+
forEach(proceed, context) {
|
|
485
|
+
for (let [key, value] of this.entries())
|
|
486
|
+
proceed.call(context, value, key, this);
|
|
487
|
+
}
|
|
488
|
+
map(proceed, context) {
|
|
489
|
+
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
490
|
+
}
|
|
491
|
+
reduce(merge, result) {
|
|
492
|
+
let index = 0;
|
|
493
|
+
if (arguments.length === 1) {
|
|
494
|
+
result = this[index++];
|
|
495
|
+
}
|
|
496
|
+
for (; index < this.length; ++index) {
|
|
497
|
+
result = merge(result, this[index], index, this);
|
|
498
|
+
}
|
|
499
|
+
return result;
|
|
500
|
+
}
|
|
501
|
+
toReversed() {
|
|
502
|
+
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
503
|
+
}
|
|
504
|
+
slice(from = 0, to = this.length) {
|
|
505
|
+
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
506
|
+
}
|
|
507
|
+
some(check, context) {
|
|
508
|
+
for (let index = 0; index < this.length; ++index) {
|
|
509
|
+
if (check.call(context, this[index], index, this))
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
every(check, context) {
|
|
515
|
+
for (let index = 0; index < this.length; ++index) {
|
|
516
|
+
if (!check.call(context, this[index], index, this))
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
reverse() {
|
|
522
|
+
return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
|
|
523
|
+
}
|
|
524
|
+
sort() {
|
|
525
|
+
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
|
|
526
|
+
}
|
|
527
|
+
[Symbol.toPrimitive]() {
|
|
528
|
+
return $mol_guid();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
$.$mol_range2_array = $mol_range2_array;
|
|
532
|
+
})($ || ($ = {}));
|
|
533
|
+
//mol/range2/range2.ts
|
|
534
|
+
;
|
|
535
|
+
"use strict";
|
|
536
|
+
var $;
|
|
537
|
+
(function ($) {
|
|
538
|
+
$mol_test({
|
|
539
|
+
'lazy calls'() {
|
|
540
|
+
let calls = 0;
|
|
541
|
+
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
542
|
+
$mol_assert_ok(list instanceof Array);
|
|
543
|
+
$mol_assert_equal(list.length, 10);
|
|
544
|
+
$mol_assert_equal(list[-1], undefined);
|
|
545
|
+
$mol_assert_equal(list[0], 0);
|
|
546
|
+
$mol_assert_equal(list[9], 9);
|
|
547
|
+
$mol_assert_equal(list[9.5], undefined);
|
|
548
|
+
$mol_assert_equal(list[10], undefined);
|
|
549
|
+
$mol_assert_equal(calls, 2);
|
|
550
|
+
},
|
|
551
|
+
'infinity list'() {
|
|
552
|
+
let calls = 0;
|
|
553
|
+
const list = $mol_range2(index => (++calls, index));
|
|
554
|
+
$mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
|
|
555
|
+
$mol_assert_equal(list[0], 0);
|
|
556
|
+
$mol_assert_equal(list[4], 4);
|
|
557
|
+
$mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
|
|
558
|
+
$mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
|
|
559
|
+
$mol_assert_equal(calls, 3);
|
|
560
|
+
},
|
|
561
|
+
'stringify'() {
|
|
562
|
+
const list = $mol_range2(i => i, () => 5);
|
|
563
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
564
|
+
$mol_assert_equal(list.join(';'), '0;1;2;3;4');
|
|
565
|
+
},
|
|
566
|
+
'for-of'() {
|
|
567
|
+
let log = '';
|
|
568
|
+
for (let i of $mol_range2(i => i + 1, () => 5)) {
|
|
569
|
+
log += i;
|
|
570
|
+
}
|
|
571
|
+
$mol_assert_equal(log, '12345');
|
|
572
|
+
},
|
|
573
|
+
'for-in'() {
|
|
574
|
+
let log = '';
|
|
575
|
+
for (let i in $mol_range2(i => i, () => 5)) {
|
|
576
|
+
log += i;
|
|
577
|
+
}
|
|
578
|
+
$mol_assert_equal(log, '01234');
|
|
579
|
+
},
|
|
580
|
+
'forEach'() {
|
|
581
|
+
let log = '';
|
|
582
|
+
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
583
|
+
$mol_assert_equal(log, '01234');
|
|
584
|
+
},
|
|
585
|
+
'lazy concat'() {
|
|
586
|
+
let calls1 = 0;
|
|
587
|
+
let calls2 = 0;
|
|
588
|
+
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
589
|
+
$mol_assert_ok(list instanceof Array);
|
|
590
|
+
$mol_assert_equal(list.length, 15);
|
|
591
|
+
$mol_assert_equal(list[0], 0);
|
|
592
|
+
$mol_assert_equal(list[4], 4);
|
|
593
|
+
$mol_assert_equal(list[5], 0);
|
|
594
|
+
$mol_assert_equal(list[9], 4);
|
|
595
|
+
$mol_assert_equal(list[10], 0);
|
|
596
|
+
$mol_assert_equal(list[14], 4);
|
|
597
|
+
$mol_assert_equal(list[15], undefined);
|
|
598
|
+
$mol_assert_equal(calls1, 2);
|
|
599
|
+
$mol_assert_equal(calls2, 2);
|
|
600
|
+
},
|
|
601
|
+
'filter'() {
|
|
602
|
+
let calls = 0;
|
|
603
|
+
const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
|
|
604
|
+
$mol_assert_ok(list instanceof Array);
|
|
605
|
+
$mol_assert_equal(list.length, 3);
|
|
606
|
+
$mol_assert_equal(list[0], 1);
|
|
607
|
+
$mol_assert_equal(list[2], 5);
|
|
608
|
+
$mol_assert_equal(list[3], undefined);
|
|
609
|
+
$mol_assert_equal(calls, 10);
|
|
610
|
+
},
|
|
611
|
+
'reverse'() {
|
|
612
|
+
let calls = 0;
|
|
613
|
+
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
614
|
+
$mol_assert_ok(list instanceof Array);
|
|
615
|
+
$mol_assert_equal(list.length, 3);
|
|
616
|
+
$mol_assert_equal(list[0], 9);
|
|
617
|
+
$mol_assert_equal(list[2], 7);
|
|
618
|
+
$mol_assert_equal(list[3], undefined);
|
|
619
|
+
$mol_assert_equal(calls, 2);
|
|
620
|
+
},
|
|
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
|
+
'lazy map'() {
|
|
628
|
+
let calls1 = 0;
|
|
629
|
+
let calls2 = 0;
|
|
630
|
+
const source = $mol_range2(index => (++calls1, index), () => 5);
|
|
631
|
+
const target = source.map((item, index, self) => {
|
|
632
|
+
++calls2;
|
|
633
|
+
$mol_assert_equal(source, self);
|
|
634
|
+
return index + 10;
|
|
635
|
+
}, () => 5);
|
|
636
|
+
$mol_assert_ok(target instanceof Array);
|
|
637
|
+
$mol_assert_equal(target.length, 5);
|
|
638
|
+
$mol_assert_equal(target[0], 10);
|
|
639
|
+
$mol_assert_equal(target[4], 14);
|
|
640
|
+
$mol_assert_equal(target[5], undefined);
|
|
641
|
+
$mol_assert_equal(calls1, 2);
|
|
642
|
+
$mol_assert_equal(calls2, 2);
|
|
643
|
+
},
|
|
644
|
+
'lazy slice'() {
|
|
645
|
+
let calls = 0;
|
|
646
|
+
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
647
|
+
$mol_assert_ok(list instanceof Array);
|
|
648
|
+
$mol_assert_equal(list.length, 4);
|
|
649
|
+
$mol_assert_equal(list[0], 3);
|
|
650
|
+
$mol_assert_equal(list[3], 6);
|
|
651
|
+
$mol_assert_equal(list[4], undefined);
|
|
652
|
+
$mol_assert_equal(calls, 2);
|
|
653
|
+
},
|
|
654
|
+
'lazy some'() {
|
|
655
|
+
let calls = 0;
|
|
656
|
+
$mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
657
|
+
$mol_assert_equal(calls, 3);
|
|
658
|
+
$mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
|
|
659
|
+
$mol_assert_ok($mol_range2(i => i).some(v => v > 5));
|
|
660
|
+
},
|
|
661
|
+
'lazy every'() {
|
|
662
|
+
let calls = 0;
|
|
663
|
+
$mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
664
|
+
$mol_assert_equal(calls, 3);
|
|
665
|
+
$mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
|
|
666
|
+
$mol_assert_not($mol_range2(i => i).every(v => v < 5));
|
|
667
|
+
},
|
|
668
|
+
'lazyfy'() {
|
|
669
|
+
let calls = 0;
|
|
670
|
+
const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
671
|
+
$mol_assert_ok(list instanceof Array);
|
|
672
|
+
$mol_assert_equal(list.length, 4);
|
|
673
|
+
$mol_assert_equal(calls, 0);
|
|
674
|
+
$mol_assert_equal(list[0], 12);
|
|
675
|
+
$mol_assert_equal(list[3], 15);
|
|
676
|
+
$mol_assert_equal(list[4], undefined);
|
|
677
|
+
$mol_assert_equal(calls, 2);
|
|
678
|
+
},
|
|
679
|
+
'prevent modification'() {
|
|
680
|
+
const list = $mol_range2(i => i, () => 5);
|
|
681
|
+
$mol_assert_fail(() => list.push(4), TypeError);
|
|
682
|
+
$mol_assert_fail(() => list.pop(), TypeError);
|
|
683
|
+
$mol_assert_fail(() => list.unshift(4), TypeError);
|
|
684
|
+
$mol_assert_fail(() => list.shift(), TypeError);
|
|
685
|
+
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
|
686
|
+
$mol_assert_fail(() => list[1] = 2, TypeError);
|
|
687
|
+
$mol_assert_fail(() => list.reverse(), TypeError);
|
|
688
|
+
$mol_assert_fail(() => list.sort(), TypeError);
|
|
689
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
})($ || ($ = {}));
|
|
693
|
+
//mol/range2/range2.test.ts
|
|
694
|
+
;
|
|
695
|
+
"use strict";
|
|
696
|
+
var $;
|
|
405
697
|
(function ($) {
|
|
406
698
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
407
699
|
function $mol_compare_deep(left, right) {
|
|
@@ -447,6 +739,8 @@ var $;
|
|
|
447
739
|
result = compare_pojo(left, right);
|
|
448
740
|
else if (!Reflect.getPrototypeOf(left_proto))
|
|
449
741
|
result = compare_pojo(left, right);
|
|
742
|
+
else if (Symbol.toPrimitive in left)
|
|
743
|
+
result = compare_primitive(left, right);
|
|
450
744
|
else if (Array.isArray(left))
|
|
451
745
|
result = compare_array(left, right);
|
|
452
746
|
else if (left instanceof Set)
|
|
@@ -457,8 +751,6 @@ var $;
|
|
|
457
751
|
result = compare_buffer(left, right);
|
|
458
752
|
else if (Symbol.iterator in left)
|
|
459
753
|
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
|
460
|
-
else if (Symbol.toPrimitive in left)
|
|
461
|
-
result = compare_primitive(left, right);
|
|
462
754
|
else
|
|
463
755
|
result = false;
|
|
464
756
|
}
|
|
@@ -568,6 +860,8 @@ var $;
|
|
|
568
860
|
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
569
861
|
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
570
862
|
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
863
|
+
$mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
|
|
864
|
+
$mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
|
|
571
865
|
},
|
|
572
866
|
'Non POJO are different'() {
|
|
573
867
|
class Thing extends Object {
|