mol_crypto_lib 0.0.152 → 0.0.156

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 CHANGED
@@ -588,7 +588,8 @@ var $;
588
588
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
589
589
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
590
590
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
591
- $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(1)));
591
+ $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
592
+ $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
592
593
  },
593
594
  'POJO'() {
594
595
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
@@ -629,8 +630,9 @@ var $;
629
630
  },
630
631
  'Map'() {
631
632
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
632
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
633
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
633
634
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
635
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
634
636
  },
635
637
  'Set'() {
636
638
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -642,6 +644,21 @@ var $;
642
644
  $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
643
645
  $.$mol_assert_not($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
644
646
  },
647
+ 'Custom comparator'() {
648
+ class User {
649
+ name;
650
+ rand;
651
+ constructor(name, rand = Math.random()) {
652
+ this.name = name;
653
+ this.rand = rand;
654
+ }
655
+ [Symbol.toPrimitive](mode) {
656
+ return this.name;
657
+ }
658
+ }
659
+ $.$mol_assert_ok($.$mol_compare_deep(new User('Jin'), new User('Jin')));
660
+ $.$mol_assert_not($.$mol_compare_deep(new User('Jin'), new User('John')));
661
+ },
645
662
  });
646
663
  })($ || ($ = {}));
647
664
  //deep.test.js.map
@@ -661,8 +678,20 @@ var $;
661
678
  return false;
662
679
  if (typeof right !== 'object')
663
680
  return false;
664
- if (left['constructor'] !== right['constructor'])
681
+ const left_proto = Reflect.getPrototypeOf(left);
682
+ const right_proto = Reflect.getPrototypeOf(right);
683
+ if (left_proto !== right_proto)
665
684
  return false;
685
+ if (left instanceof Boolean)
686
+ return Object.is(left.valueOf(), right['valueOf']());
687
+ if (left instanceof Number)
688
+ return Object.is(left.valueOf(), right['valueOf']());
689
+ if (left instanceof String)
690
+ return Object.is(left.valueOf(), right['valueOf']());
691
+ if (left instanceof Date)
692
+ return Object.is(left.valueOf(), right['valueOf']());
693
+ if (left instanceof RegExp)
694
+ return left.source === right['source'] && left.flags === right['flags'];
666
695
  let left_cache = cache.get(left);
667
696
  if (left_cache) {
668
697
  const right_cache = left_cache.get(right);
@@ -670,56 +699,90 @@ var $;
670
699
  return right_cache;
671
700
  }
672
701
  else {
673
- left_cache = new WeakMap();
702
+ left_cache = new WeakMap([[right, true]]);
674
703
  cache.set(left, left_cache);
675
- left_cache.set(right, true);
676
704
  }
677
- if (left instanceof RegExp)
678
- return left.toString() === right['toString']();
679
- if (left instanceof Date)
680
- return Object.is(left.valueOf(), right['valueOf']());
681
705
  let result;
682
706
  try {
683
- if (Symbol.iterator in left) {
684
- const left_iter = left[Symbol.iterator]();
685
- const right_iter = right[Symbol.iterator]();
686
- while (true) {
687
- const left_next = left_iter.next();
688
- const right_next = right_iter.next();
689
- if (left_next.done !== right_next.done)
690
- return result = false;
691
- if (left_next.done)
692
- break;
693
- if (!$mol_compare_deep(left_next.value, right_next.value))
694
- return result = false;
695
- }
696
- return result = true;
697
- }
698
- if (left['constructor'] !== ({}).constructor)
699
- return result = false;
700
- let count = 0;
701
- for (let key in left) {
702
- try {
703
- if (!$mol_compare_deep(left[key], right[key]))
704
- return result = false;
705
- }
706
- catch (error) {
707
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${left} and ${right}`, error));
708
- }
709
- ++count;
710
- }
711
- for (let key in right) {
712
- --count;
713
- if (count < 0)
714
- return result = false;
715
- }
716
- return result = true;
707
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
708
+ result = compare_pojo(left, right);
709
+ else if (Array.isArray(left))
710
+ result = compare_array(left, right);
711
+ else if (left instanceof Set)
712
+ result = compare_set(left, right);
713
+ else if (left instanceof Map)
714
+ result = compare_map(left, right);
715
+ else if (ArrayBuffer.isView(left))
716
+ result = compare_buffer(left, right);
717
+ else if (Symbol.toPrimitive in left)
718
+ result = compare_primitive(left, right);
719
+ else
720
+ result = false;
717
721
  }
718
722
  finally {
719
723
  left_cache.set(right, result);
720
724
  }
725
+ return result;
721
726
  }
722
727
  $.$mol_compare_deep = $mol_compare_deep;
728
+ function compare_array(left, right) {
729
+ const len = left.length;
730
+ if (len !== right.length)
731
+ return false;
732
+ for (let i = 0; i < len; ++i) {
733
+ if (!$mol_compare_deep(left[i], right[i]))
734
+ return false;
735
+ }
736
+ return true;
737
+ }
738
+ function compare_buffer(left, right) {
739
+ const len = left.byteLength;
740
+ if (len !== right.byteLength)
741
+ return false;
742
+ for (let i = 0; i < len; ++i) {
743
+ if (left[i] !== right[i])
744
+ return false;
745
+ }
746
+ return true;
747
+ }
748
+ function compare_iterator(left, right, compare) {
749
+ while (true) {
750
+ const left_next = left.next();
751
+ const right_next = right.next();
752
+ if (left_next.done !== right_next.done)
753
+ return false;
754
+ if (left_next.done)
755
+ break;
756
+ if (!compare(left_next.value, right_next.value))
757
+ return false;
758
+ }
759
+ return true;
760
+ }
761
+ function compare_set(left, right) {
762
+ if (left.size !== right.size)
763
+ return false;
764
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
765
+ }
766
+ function compare_map(left, right) {
767
+ if (left.size !== right.size)
768
+ return false;
769
+ return compare_iterator(left.keys(), right.keys(), Object.is)
770
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
771
+ }
772
+ function compare_pojo(left, right) {
773
+ const left_keys = Object.getOwnPropertyNames(left);
774
+ const right_keys = Object.getOwnPropertyNames(right);
775
+ if (left_keys.length !== right_keys.length)
776
+ return false;
777
+ for (let key of left_keys) {
778
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
779
+ return false;
780
+ }
781
+ return true;
782
+ }
783
+ function compare_primitive(left, right) {
784
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
785
+ }
723
786
  })($ || ($ = {}));
724
787
  //deep.js.map
725
788
  ;
@@ -1700,91 +1763,5 @@ var $;
1700
1763
  ;
1701
1764
  "use strict";
1702
1765
  //equals.js.map
1703
- ;
1704
- "use strict";
1705
- var $;
1706
- (function ($) {
1707
- $.$mol_test({
1708
- 'equal paths'() {
1709
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]);
1710
- $.$mol_assert_like(diff, {
1711
- prefix: [1, 2, 3, 4],
1712
- suffix: [[], [], []],
1713
- });
1714
- },
1715
- 'different suffix'() {
1716
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 5, 4]);
1717
- $.$mol_assert_like(diff, {
1718
- prefix: [1, 2],
1719
- suffix: [[3, 4], [3, 5], [5, 4]],
1720
- });
1721
- },
1722
- 'one contains other'() {
1723
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2], [1, 2, 3]);
1724
- $.$mol_assert_like(diff, {
1725
- prefix: [1, 2],
1726
- suffix: [[3, 4], [], [3]],
1727
- });
1728
- },
1729
- 'fully different'() {
1730
- const diff = $.$mol_diff_path([1, 2], [3, 4], [5, 6]);
1731
- $.$mol_assert_like(diff, {
1732
- prefix: [],
1733
- suffix: [[1, 2], [3, 4], [5, 6]],
1734
- });
1735
- },
1736
- });
1737
- })($ || ($ = {}));
1738
- //path.test.js.map
1739
- ;
1740
- "use strict";
1741
- var $;
1742
- (function ($) {
1743
- function $mol_diff_path(...paths) {
1744
- const limit = Math.min(...paths.map(path => path.length));
1745
- lookup: for (var i = 0; i < limit; ++i) {
1746
- const first = paths[0][i];
1747
- for (let j = 1; j < paths.length; ++j) {
1748
- if (paths[j][i] !== first)
1749
- break lookup;
1750
- }
1751
- }
1752
- return {
1753
- prefix: paths[0].slice(0, i),
1754
- suffix: paths.map(path => path.slice(i)),
1755
- };
1756
- }
1757
- $.$mol_diff_path = $mol_diff_path;
1758
- })($ || ($ = {}));
1759
- //path.js.map
1760
- ;
1761
- "use strict";
1762
- var $;
1763
- (function ($) {
1764
- class $mol_error_mix extends Error {
1765
- errors;
1766
- constructor(message, ...errors) {
1767
- super(message);
1768
- this.errors = errors;
1769
- if (errors.length) {
1770
- const stacks = [...errors.map(error => error.stack), this.stack];
1771
- const diff = $.$mol_diff_path(...stacks.map(stack => {
1772
- if (!stack)
1773
- return [];
1774
- return stack.split('\n').reverse();
1775
- }));
1776
- const head = diff.prefix.reverse().join('\n');
1777
- const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
1778
- this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
1779
- this.message += errors.map(error => '\n' + error.message).join('');
1780
- }
1781
- }
1782
- toJSON() {
1783
- return this.message;
1784
- }
1785
- }
1786
- $.$mol_error_mix = $mol_error_mix;
1787
- })($ || ($ = {}));
1788
- //mix.js.map
1789
1766
 
1790
1767
  //# sourceMappingURL=node.test.js.map