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