mol_mutable 0.0.274 → 0.0.276
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
|
@@ -431,6 +431,298 @@ var $;
|
|
|
431
431
|
;
|
|
432
432
|
"use strict";
|
|
433
433
|
var $;
|
|
434
|
+
(function ($) {
|
|
435
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
436
|
+
for (;;) {
|
|
437
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
438
|
+
if (exists(id))
|
|
439
|
+
continue;
|
|
440
|
+
return id;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
$.$mol_guid = $mol_guid;
|
|
444
|
+
})($ || ($ = {}));
|
|
445
|
+
//mol/guid/guid.ts
|
|
446
|
+
;
|
|
447
|
+
"use strict";
|
|
448
|
+
var $;
|
|
449
|
+
(function ($) {
|
|
450
|
+
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
451
|
+
return new Proxy(new $mol_range2_array(), {
|
|
452
|
+
get(target, field) {
|
|
453
|
+
if (typeof field === 'string') {
|
|
454
|
+
if (field === 'length')
|
|
455
|
+
return size();
|
|
456
|
+
const index = Number(field);
|
|
457
|
+
if (index < 0)
|
|
458
|
+
return undefined;
|
|
459
|
+
if (index >= size())
|
|
460
|
+
return undefined;
|
|
461
|
+
if (index === Math.trunc(index))
|
|
462
|
+
return item(index);
|
|
463
|
+
}
|
|
464
|
+
return target[field];
|
|
465
|
+
},
|
|
466
|
+
set(target, field) {
|
|
467
|
+
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
468
|
+
},
|
|
469
|
+
ownKeys(target) {
|
|
470
|
+
return [...Array(size())].map((v, i) => String(i)).concat('length');
|
|
471
|
+
},
|
|
472
|
+
getOwnPropertyDescriptor(target, field) {
|
|
473
|
+
if (field === "length")
|
|
474
|
+
return {
|
|
475
|
+
value: size(),
|
|
476
|
+
writable: true,
|
|
477
|
+
enumerable: false,
|
|
478
|
+
configurable: false,
|
|
479
|
+
};
|
|
480
|
+
const index = Number(field);
|
|
481
|
+
if (index === Math.trunc(index))
|
|
482
|
+
return {
|
|
483
|
+
get: () => this.get(target, field, this),
|
|
484
|
+
enumerable: true,
|
|
485
|
+
configurable: true,
|
|
486
|
+
};
|
|
487
|
+
return Object.getOwnPropertyDescriptor(target, field);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
$.$mol_range2 = $mol_range2;
|
|
492
|
+
class $mol_range2_array extends Array {
|
|
493
|
+
concat(...tail) {
|
|
494
|
+
if (tail.length === 0)
|
|
495
|
+
return this;
|
|
496
|
+
if (tail.length > 1) {
|
|
497
|
+
let list = this;
|
|
498
|
+
for (let item of tail)
|
|
499
|
+
list = list.concat(item);
|
|
500
|
+
return list;
|
|
501
|
+
}
|
|
502
|
+
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
503
|
+
}
|
|
504
|
+
filter(check, context) {
|
|
505
|
+
const filtered = new $mol_range2_array();
|
|
506
|
+
for (let index = 0; index < this.length; ++index) {
|
|
507
|
+
const item = this[index];
|
|
508
|
+
if (check.call(context, item, index, this))
|
|
509
|
+
filtered.push(item);
|
|
510
|
+
}
|
|
511
|
+
return filtered;
|
|
512
|
+
}
|
|
513
|
+
forEach(proceed, context) {
|
|
514
|
+
for (let [key, value] of this.entries())
|
|
515
|
+
proceed.call(context, value, key, this);
|
|
516
|
+
}
|
|
517
|
+
map(proceed, context) {
|
|
518
|
+
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
519
|
+
}
|
|
520
|
+
reduce(merge, result) {
|
|
521
|
+
let index = 0;
|
|
522
|
+
if (arguments.length === 1) {
|
|
523
|
+
result = this[index++];
|
|
524
|
+
}
|
|
525
|
+
for (; index < this.length; ++index) {
|
|
526
|
+
result = merge(result, this[index], index, this);
|
|
527
|
+
}
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
toReversed() {
|
|
531
|
+
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
532
|
+
}
|
|
533
|
+
slice(from = 0, to = this.length) {
|
|
534
|
+
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
535
|
+
}
|
|
536
|
+
some(check, context) {
|
|
537
|
+
for (let index = 0; index < this.length; ++index) {
|
|
538
|
+
if (check.call(context, this[index], index, this))
|
|
539
|
+
return true;
|
|
540
|
+
}
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
every(check, context) {
|
|
544
|
+
for (let index = 0; index < this.length; ++index) {
|
|
545
|
+
if (!check.call(context, this[index], index, this))
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
reverse() {
|
|
551
|
+
return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
|
|
552
|
+
}
|
|
553
|
+
sort() {
|
|
554
|
+
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
|
|
555
|
+
}
|
|
556
|
+
[Symbol.toPrimitive]() {
|
|
557
|
+
return $mol_guid();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
$.$mol_range2_array = $mol_range2_array;
|
|
561
|
+
})($ || ($ = {}));
|
|
562
|
+
//mol/range2/range2.ts
|
|
563
|
+
;
|
|
564
|
+
"use strict";
|
|
565
|
+
var $;
|
|
566
|
+
(function ($) {
|
|
567
|
+
$mol_test({
|
|
568
|
+
'lazy calls'() {
|
|
569
|
+
let calls = 0;
|
|
570
|
+
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
571
|
+
$mol_assert_ok(list instanceof Array);
|
|
572
|
+
$mol_assert_equal(list.length, 10);
|
|
573
|
+
$mol_assert_equal(list[-1], undefined);
|
|
574
|
+
$mol_assert_equal(list[0], 0);
|
|
575
|
+
$mol_assert_equal(list[9], 9);
|
|
576
|
+
$mol_assert_equal(list[9.5], undefined);
|
|
577
|
+
$mol_assert_equal(list[10], undefined);
|
|
578
|
+
$mol_assert_equal(calls, 2);
|
|
579
|
+
},
|
|
580
|
+
'infinity list'() {
|
|
581
|
+
let calls = 0;
|
|
582
|
+
const list = $mol_range2(index => (++calls, index));
|
|
583
|
+
$mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
|
|
584
|
+
$mol_assert_equal(list[0], 0);
|
|
585
|
+
$mol_assert_equal(list[4], 4);
|
|
586
|
+
$mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
|
|
587
|
+
$mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
|
|
588
|
+
$mol_assert_equal(calls, 3);
|
|
589
|
+
},
|
|
590
|
+
'stringify'() {
|
|
591
|
+
const list = $mol_range2(i => i, () => 5);
|
|
592
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
593
|
+
$mol_assert_equal(list.join(';'), '0;1;2;3;4');
|
|
594
|
+
},
|
|
595
|
+
'for-of'() {
|
|
596
|
+
let log = '';
|
|
597
|
+
for (let i of $mol_range2(i => i + 1, () => 5)) {
|
|
598
|
+
log += i;
|
|
599
|
+
}
|
|
600
|
+
$mol_assert_equal(log, '12345');
|
|
601
|
+
},
|
|
602
|
+
'for-in'() {
|
|
603
|
+
let log = '';
|
|
604
|
+
for (let i in $mol_range2(i => i, () => 5)) {
|
|
605
|
+
log += i;
|
|
606
|
+
}
|
|
607
|
+
$mol_assert_equal(log, '01234');
|
|
608
|
+
},
|
|
609
|
+
'forEach'() {
|
|
610
|
+
let log = '';
|
|
611
|
+
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
612
|
+
$mol_assert_equal(log, '01234');
|
|
613
|
+
},
|
|
614
|
+
'lazy concat'() {
|
|
615
|
+
let calls1 = 0;
|
|
616
|
+
let calls2 = 0;
|
|
617
|
+
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
618
|
+
$mol_assert_ok(list instanceof Array);
|
|
619
|
+
$mol_assert_equal(list.length, 15);
|
|
620
|
+
$mol_assert_equal(list[0], 0);
|
|
621
|
+
$mol_assert_equal(list[4], 4);
|
|
622
|
+
$mol_assert_equal(list[5], 0);
|
|
623
|
+
$mol_assert_equal(list[9], 4);
|
|
624
|
+
$mol_assert_equal(list[10], 0);
|
|
625
|
+
$mol_assert_equal(list[14], 4);
|
|
626
|
+
$mol_assert_equal(list[15], undefined);
|
|
627
|
+
$mol_assert_equal(calls1, 2);
|
|
628
|
+
$mol_assert_equal(calls2, 2);
|
|
629
|
+
},
|
|
630
|
+
'filter'() {
|
|
631
|
+
let calls = 0;
|
|
632
|
+
const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
|
|
633
|
+
$mol_assert_ok(list instanceof Array);
|
|
634
|
+
$mol_assert_equal(list.length, 3);
|
|
635
|
+
$mol_assert_equal(list[0], 1);
|
|
636
|
+
$mol_assert_equal(list[2], 5);
|
|
637
|
+
$mol_assert_equal(list[3], undefined);
|
|
638
|
+
$mol_assert_equal(calls, 10);
|
|
639
|
+
},
|
|
640
|
+
'reverse'() {
|
|
641
|
+
let calls = 0;
|
|
642
|
+
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
643
|
+
$mol_assert_ok(list instanceof Array);
|
|
644
|
+
$mol_assert_equal(list.length, 3);
|
|
645
|
+
$mol_assert_equal(list[0], 9);
|
|
646
|
+
$mol_assert_equal(list[2], 7);
|
|
647
|
+
$mol_assert_equal(list[3], undefined);
|
|
648
|
+
$mol_assert_equal(calls, 2);
|
|
649
|
+
},
|
|
650
|
+
'reduce'() {
|
|
651
|
+
let calls = 0;
|
|
652
|
+
const list = $mol_range2().slice(1, 6);
|
|
653
|
+
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
654
|
+
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
655
|
+
},
|
|
656
|
+
'lazy map'() {
|
|
657
|
+
let calls1 = 0;
|
|
658
|
+
let calls2 = 0;
|
|
659
|
+
const source = $mol_range2(index => (++calls1, index), () => 5);
|
|
660
|
+
const target = source.map((item, index, self) => {
|
|
661
|
+
++calls2;
|
|
662
|
+
$mol_assert_equal(source, self);
|
|
663
|
+
return index + 10;
|
|
664
|
+
}, () => 5);
|
|
665
|
+
$mol_assert_ok(target instanceof Array);
|
|
666
|
+
$mol_assert_equal(target.length, 5);
|
|
667
|
+
$mol_assert_equal(target[0], 10);
|
|
668
|
+
$mol_assert_equal(target[4], 14);
|
|
669
|
+
$mol_assert_equal(target[5], undefined);
|
|
670
|
+
$mol_assert_equal(calls1, 2);
|
|
671
|
+
$mol_assert_equal(calls2, 2);
|
|
672
|
+
},
|
|
673
|
+
'lazy slice'() {
|
|
674
|
+
let calls = 0;
|
|
675
|
+
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
676
|
+
$mol_assert_ok(list instanceof Array);
|
|
677
|
+
$mol_assert_equal(list.length, 4);
|
|
678
|
+
$mol_assert_equal(list[0], 3);
|
|
679
|
+
$mol_assert_equal(list[3], 6);
|
|
680
|
+
$mol_assert_equal(list[4], undefined);
|
|
681
|
+
$mol_assert_equal(calls, 2);
|
|
682
|
+
},
|
|
683
|
+
'lazy some'() {
|
|
684
|
+
let calls = 0;
|
|
685
|
+
$mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
686
|
+
$mol_assert_equal(calls, 3);
|
|
687
|
+
$mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
|
|
688
|
+
$mol_assert_ok($mol_range2(i => i).some(v => v > 5));
|
|
689
|
+
},
|
|
690
|
+
'lazy every'() {
|
|
691
|
+
let calls = 0;
|
|
692
|
+
$mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
693
|
+
$mol_assert_equal(calls, 3);
|
|
694
|
+
$mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
|
|
695
|
+
$mol_assert_not($mol_range2(i => i).every(v => v < 5));
|
|
696
|
+
},
|
|
697
|
+
'lazyfy'() {
|
|
698
|
+
let calls = 0;
|
|
699
|
+
const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
700
|
+
$mol_assert_ok(list instanceof Array);
|
|
701
|
+
$mol_assert_equal(list.length, 4);
|
|
702
|
+
$mol_assert_equal(calls, 0);
|
|
703
|
+
$mol_assert_equal(list[0], 12);
|
|
704
|
+
$mol_assert_equal(list[3], 15);
|
|
705
|
+
$mol_assert_equal(list[4], undefined);
|
|
706
|
+
$mol_assert_equal(calls, 2);
|
|
707
|
+
},
|
|
708
|
+
'prevent modification'() {
|
|
709
|
+
const list = $mol_range2(i => i, () => 5);
|
|
710
|
+
$mol_assert_fail(() => list.push(4), TypeError);
|
|
711
|
+
$mol_assert_fail(() => list.pop(), TypeError);
|
|
712
|
+
$mol_assert_fail(() => list.unshift(4), TypeError);
|
|
713
|
+
$mol_assert_fail(() => list.shift(), TypeError);
|
|
714
|
+
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
|
715
|
+
$mol_assert_fail(() => list[1] = 2, TypeError);
|
|
716
|
+
$mol_assert_fail(() => list.reverse(), TypeError);
|
|
717
|
+
$mol_assert_fail(() => list.sort(), TypeError);
|
|
718
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
})($ || ($ = {}));
|
|
722
|
+
//mol/range2/range2.test.ts
|
|
723
|
+
;
|
|
724
|
+
"use strict";
|
|
725
|
+
var $;
|
|
434
726
|
(function ($) {
|
|
435
727
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
436
728
|
function $mol_compare_deep(left, right) {
|
|
@@ -476,6 +768,8 @@ var $;
|
|
|
476
768
|
result = compare_pojo(left, right);
|
|
477
769
|
else if (!Reflect.getPrototypeOf(left_proto))
|
|
478
770
|
result = compare_pojo(left, right);
|
|
771
|
+
else if (Symbol.toPrimitive in left)
|
|
772
|
+
result = compare_primitive(left, right);
|
|
479
773
|
else if (Array.isArray(left))
|
|
480
774
|
result = compare_array(left, right);
|
|
481
775
|
else if (left instanceof Set)
|
|
@@ -486,8 +780,6 @@ var $;
|
|
|
486
780
|
result = compare_buffer(left, right);
|
|
487
781
|
else if (Symbol.iterator in left)
|
|
488
782
|
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
|
489
|
-
else if (Symbol.toPrimitive in left)
|
|
490
|
-
result = compare_primitive(left, right);
|
|
491
783
|
else
|
|
492
784
|
result = false;
|
|
493
785
|
}
|
|
@@ -597,6 +889,8 @@ var $;
|
|
|
597
889
|
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
598
890
|
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
599
891
|
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
892
|
+
$mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
|
|
893
|
+
$mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
|
|
600
894
|
},
|
|
601
895
|
'Non POJO are different'() {
|
|
602
896
|
class Thing extends Object {
|