mol_dump_lib 0.0.91 → 0.0.93
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
|
@@ -944,6 +944,8 @@ var $;
|
|
|
944
944
|
result = compare_pojo(left, right);
|
|
945
945
|
else if (!Reflect.getPrototypeOf(left_proto))
|
|
946
946
|
result = compare_pojo(left, right);
|
|
947
|
+
else if (Symbol.toPrimitive in left)
|
|
948
|
+
result = compare_primitive(left, right);
|
|
947
949
|
else if (Array.isArray(left))
|
|
948
950
|
result = compare_array(left, right);
|
|
949
951
|
else if (left instanceof Set)
|
|
@@ -954,8 +956,6 @@ var $;
|
|
|
954
956
|
result = compare_buffer(left, right);
|
|
955
957
|
else if (Symbol.iterator in left)
|
|
956
958
|
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
|
|
957
|
-
else if (Symbol.toPrimitive in left)
|
|
958
|
-
result = compare_primitive(left, right);
|
|
959
959
|
else
|
|
960
960
|
result = false;
|
|
961
961
|
}
|
package/web.test.js
CHANGED
|
@@ -321,6 +321,283 @@ var $;
|
|
|
321
321
|
;
|
|
322
322
|
"use strict";
|
|
323
323
|
var $;
|
|
324
|
+
(function ($) {
|
|
325
|
+
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
326
|
+
return new Proxy(new $mol_range2_array(), {
|
|
327
|
+
get(target, field) {
|
|
328
|
+
if (typeof field === 'string') {
|
|
329
|
+
if (field === 'length')
|
|
330
|
+
return size();
|
|
331
|
+
const index = Number(field);
|
|
332
|
+
if (index < 0)
|
|
333
|
+
return undefined;
|
|
334
|
+
if (index >= size())
|
|
335
|
+
return undefined;
|
|
336
|
+
if (index === Math.trunc(index))
|
|
337
|
+
return item(index);
|
|
338
|
+
}
|
|
339
|
+
return target[field];
|
|
340
|
+
},
|
|
341
|
+
set(target, field) {
|
|
342
|
+
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
|
|
343
|
+
},
|
|
344
|
+
ownKeys(target) {
|
|
345
|
+
return [...Array(size())].map((v, i) => String(i)).concat('length');
|
|
346
|
+
},
|
|
347
|
+
getOwnPropertyDescriptor(target, field) {
|
|
348
|
+
if (field === "length")
|
|
349
|
+
return {
|
|
350
|
+
value: size(),
|
|
351
|
+
writable: true,
|
|
352
|
+
enumerable: false,
|
|
353
|
+
configurable: false,
|
|
354
|
+
};
|
|
355
|
+
const index = Number(field);
|
|
356
|
+
if (index === Math.trunc(index))
|
|
357
|
+
return {
|
|
358
|
+
get: () => this.get(target, field, this),
|
|
359
|
+
enumerable: true,
|
|
360
|
+
configurable: true,
|
|
361
|
+
};
|
|
362
|
+
return Object.getOwnPropertyDescriptor(target, field);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
$.$mol_range2 = $mol_range2;
|
|
367
|
+
class $mol_range2_array extends Array {
|
|
368
|
+
concat(...tail) {
|
|
369
|
+
if (tail.length === 0)
|
|
370
|
+
return this;
|
|
371
|
+
if (tail.length > 1) {
|
|
372
|
+
let list = this;
|
|
373
|
+
for (let item of tail)
|
|
374
|
+
list = list.concat(item);
|
|
375
|
+
return list;
|
|
376
|
+
}
|
|
377
|
+
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
378
|
+
}
|
|
379
|
+
filter(check, context) {
|
|
380
|
+
const filtered = new $mol_range2_array();
|
|
381
|
+
for (let index = 0; index < this.length; ++index) {
|
|
382
|
+
const item = this[index];
|
|
383
|
+
if (check.call(context, item, index, this))
|
|
384
|
+
filtered.push(item);
|
|
385
|
+
}
|
|
386
|
+
return filtered;
|
|
387
|
+
}
|
|
388
|
+
forEach(proceed, context) {
|
|
389
|
+
for (let [key, value] of this.entries())
|
|
390
|
+
proceed.call(context, value, key, this);
|
|
391
|
+
}
|
|
392
|
+
map(proceed, context) {
|
|
393
|
+
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
394
|
+
}
|
|
395
|
+
reduce(merge, result) {
|
|
396
|
+
let index = 0;
|
|
397
|
+
if (arguments.length === 1) {
|
|
398
|
+
result = this[index++];
|
|
399
|
+
}
|
|
400
|
+
for (; index < this.length; ++index) {
|
|
401
|
+
result = merge(result, this[index], index, this);
|
|
402
|
+
}
|
|
403
|
+
return result;
|
|
404
|
+
}
|
|
405
|
+
toReversed() {
|
|
406
|
+
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
407
|
+
}
|
|
408
|
+
slice(from = 0, to = this.length) {
|
|
409
|
+
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
410
|
+
}
|
|
411
|
+
some(check, context) {
|
|
412
|
+
for (let index = 0; index < this.length; ++index) {
|
|
413
|
+
if (check.call(context, this[index], index, this))
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
every(check, context) {
|
|
419
|
+
for (let index = 0; index < this.length; ++index) {
|
|
420
|
+
if (!check.call(context, this[index], index, this))
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
reverse() {
|
|
426
|
+
return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
|
|
427
|
+
}
|
|
428
|
+
sort() {
|
|
429
|
+
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
|
|
430
|
+
}
|
|
431
|
+
[Symbol.toPrimitive]() {
|
|
432
|
+
return $mol_guid();
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
$.$mol_range2_array = $mol_range2_array;
|
|
436
|
+
})($ || ($ = {}));
|
|
437
|
+
//mol/range2/range2.ts
|
|
438
|
+
;
|
|
439
|
+
"use strict";
|
|
440
|
+
var $;
|
|
441
|
+
(function ($) {
|
|
442
|
+
$mol_test({
|
|
443
|
+
'lazy calls'() {
|
|
444
|
+
let calls = 0;
|
|
445
|
+
const list = $mol_range2(index => (++calls, index), () => 10);
|
|
446
|
+
$mol_assert_ok(list instanceof Array);
|
|
447
|
+
$mol_assert_equal(list.length, 10);
|
|
448
|
+
$mol_assert_equal(list[-1], undefined);
|
|
449
|
+
$mol_assert_equal(list[0], 0);
|
|
450
|
+
$mol_assert_equal(list[9], 9);
|
|
451
|
+
$mol_assert_equal(list[9.5], undefined);
|
|
452
|
+
$mol_assert_equal(list[10], undefined);
|
|
453
|
+
$mol_assert_equal(calls, 2);
|
|
454
|
+
},
|
|
455
|
+
'infinity list'() {
|
|
456
|
+
let calls = 0;
|
|
457
|
+
const list = $mol_range2(index => (++calls, index));
|
|
458
|
+
$mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
|
|
459
|
+
$mol_assert_equal(list[0], 0);
|
|
460
|
+
$mol_assert_equal(list[4], 4);
|
|
461
|
+
$mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
|
|
462
|
+
$mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
|
|
463
|
+
$mol_assert_equal(calls, 3);
|
|
464
|
+
},
|
|
465
|
+
'stringify'() {
|
|
466
|
+
const list = $mol_range2(i => i, () => 5);
|
|
467
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
468
|
+
$mol_assert_equal(list.join(';'), '0;1;2;3;4');
|
|
469
|
+
},
|
|
470
|
+
'for-of'() {
|
|
471
|
+
let log = '';
|
|
472
|
+
for (let i of $mol_range2(i => i + 1, () => 5)) {
|
|
473
|
+
log += i;
|
|
474
|
+
}
|
|
475
|
+
$mol_assert_equal(log, '12345');
|
|
476
|
+
},
|
|
477
|
+
'for-in'() {
|
|
478
|
+
let log = '';
|
|
479
|
+
for (let i in $mol_range2(i => i, () => 5)) {
|
|
480
|
+
log += i;
|
|
481
|
+
}
|
|
482
|
+
$mol_assert_equal(log, '01234');
|
|
483
|
+
},
|
|
484
|
+
'forEach'() {
|
|
485
|
+
let log = '';
|
|
486
|
+
$mol_range2(i => i, () => 5).forEach(i => log += i);
|
|
487
|
+
$mol_assert_equal(log, '01234');
|
|
488
|
+
},
|
|
489
|
+
'lazy concat'() {
|
|
490
|
+
let calls1 = 0;
|
|
491
|
+
let calls2 = 0;
|
|
492
|
+
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
|
|
493
|
+
$mol_assert_ok(list instanceof Array);
|
|
494
|
+
$mol_assert_equal(list.length, 15);
|
|
495
|
+
$mol_assert_equal(list[0], 0);
|
|
496
|
+
$mol_assert_equal(list[4], 4);
|
|
497
|
+
$mol_assert_equal(list[5], 0);
|
|
498
|
+
$mol_assert_equal(list[9], 4);
|
|
499
|
+
$mol_assert_equal(list[10], 0);
|
|
500
|
+
$mol_assert_equal(list[14], 4);
|
|
501
|
+
$mol_assert_equal(list[15], undefined);
|
|
502
|
+
$mol_assert_equal(calls1, 2);
|
|
503
|
+
$mol_assert_equal(calls2, 2);
|
|
504
|
+
},
|
|
505
|
+
'filter'() {
|
|
506
|
+
let calls = 0;
|
|
507
|
+
const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
|
|
508
|
+
$mol_assert_ok(list instanceof Array);
|
|
509
|
+
$mol_assert_equal(list.length, 3);
|
|
510
|
+
$mol_assert_equal(list[0], 1);
|
|
511
|
+
$mol_assert_equal(list[2], 5);
|
|
512
|
+
$mol_assert_equal(list[3], undefined);
|
|
513
|
+
$mol_assert_equal(calls, 10);
|
|
514
|
+
},
|
|
515
|
+
'reverse'() {
|
|
516
|
+
let calls = 0;
|
|
517
|
+
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
|
|
518
|
+
$mol_assert_ok(list instanceof Array);
|
|
519
|
+
$mol_assert_equal(list.length, 3);
|
|
520
|
+
$mol_assert_equal(list[0], 9);
|
|
521
|
+
$mol_assert_equal(list[2], 7);
|
|
522
|
+
$mol_assert_equal(list[3], undefined);
|
|
523
|
+
$mol_assert_equal(calls, 2);
|
|
524
|
+
},
|
|
525
|
+
'reduce'() {
|
|
526
|
+
let calls = 0;
|
|
527
|
+
const list = $mol_range2().slice(1, 6);
|
|
528
|
+
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
|
|
529
|
+
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
|
|
530
|
+
},
|
|
531
|
+
'lazy map'() {
|
|
532
|
+
let calls1 = 0;
|
|
533
|
+
let calls2 = 0;
|
|
534
|
+
const source = $mol_range2(index => (++calls1, index), () => 5);
|
|
535
|
+
const target = source.map((item, index, self) => {
|
|
536
|
+
++calls2;
|
|
537
|
+
$mol_assert_equal(source, self);
|
|
538
|
+
return index + 10;
|
|
539
|
+
}, () => 5);
|
|
540
|
+
$mol_assert_ok(target instanceof Array);
|
|
541
|
+
$mol_assert_equal(target.length, 5);
|
|
542
|
+
$mol_assert_equal(target[0], 10);
|
|
543
|
+
$mol_assert_equal(target[4], 14);
|
|
544
|
+
$mol_assert_equal(target[5], undefined);
|
|
545
|
+
$mol_assert_equal(calls1, 2);
|
|
546
|
+
$mol_assert_equal(calls2, 2);
|
|
547
|
+
},
|
|
548
|
+
'lazy slice'() {
|
|
549
|
+
let calls = 0;
|
|
550
|
+
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
|
|
551
|
+
$mol_assert_ok(list instanceof Array);
|
|
552
|
+
$mol_assert_equal(list.length, 4);
|
|
553
|
+
$mol_assert_equal(list[0], 3);
|
|
554
|
+
$mol_assert_equal(list[3], 6);
|
|
555
|
+
$mol_assert_equal(list[4], undefined);
|
|
556
|
+
$mol_assert_equal(calls, 2);
|
|
557
|
+
},
|
|
558
|
+
'lazy some'() {
|
|
559
|
+
let calls = 0;
|
|
560
|
+
$mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
|
|
561
|
+
$mol_assert_equal(calls, 3);
|
|
562
|
+
$mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
|
|
563
|
+
$mol_assert_ok($mol_range2(i => i).some(v => v > 5));
|
|
564
|
+
},
|
|
565
|
+
'lazy every'() {
|
|
566
|
+
let calls = 0;
|
|
567
|
+
$mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
|
|
568
|
+
$mol_assert_equal(calls, 3);
|
|
569
|
+
$mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
|
|
570
|
+
$mol_assert_not($mol_range2(i => i).every(v => v < 5));
|
|
571
|
+
},
|
|
572
|
+
'lazyfy'() {
|
|
573
|
+
let calls = 0;
|
|
574
|
+
const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
|
|
575
|
+
$mol_assert_ok(list instanceof Array);
|
|
576
|
+
$mol_assert_equal(list.length, 4);
|
|
577
|
+
$mol_assert_equal(calls, 0);
|
|
578
|
+
$mol_assert_equal(list[0], 12);
|
|
579
|
+
$mol_assert_equal(list[3], 15);
|
|
580
|
+
$mol_assert_equal(list[4], undefined);
|
|
581
|
+
$mol_assert_equal(calls, 2);
|
|
582
|
+
},
|
|
583
|
+
'prevent modification'() {
|
|
584
|
+
const list = $mol_range2(i => i, () => 5);
|
|
585
|
+
$mol_assert_fail(() => list.push(4), TypeError);
|
|
586
|
+
$mol_assert_fail(() => list.pop(), TypeError);
|
|
587
|
+
$mol_assert_fail(() => list.unshift(4), TypeError);
|
|
588
|
+
$mol_assert_fail(() => list.shift(), TypeError);
|
|
589
|
+
$mol_assert_fail(() => list.splice(1, 2), TypeError);
|
|
590
|
+
$mol_assert_fail(() => list[1] = 2, TypeError);
|
|
591
|
+
$mol_assert_fail(() => list.reverse(), TypeError);
|
|
592
|
+
$mol_assert_fail(() => list.sort(), TypeError);
|
|
593
|
+
$mol_assert_equal(list.toString(), '0,1,2,3,4');
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
})($ || ($ = {}));
|
|
597
|
+
//mol/range2/range2.test.ts
|
|
598
|
+
;
|
|
599
|
+
"use strict";
|
|
600
|
+
var $;
|
|
324
601
|
(function ($) {
|
|
325
602
|
$mol_test({
|
|
326
603
|
'nulls & undefineds'() {
|
|
@@ -350,6 +627,8 @@ var $;
|
|
|
350
627
|
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
351
628
|
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
352
629
|
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
630
|
+
$mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
|
|
631
|
+
$mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
|
|
353
632
|
},
|
|
354
633
|
'Non POJO are different'() {
|
|
355
634
|
class Thing extends Object {
|