mol_data_all 1.1.150 → 1.1.154

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
@@ -792,23 +792,16 @@ var $;
792
792
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
793
793
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
794
794
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
795
- },
796
- 'Number'() {
797
795
  $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
798
- $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
799
796
  $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
800
797
  },
801
- 'empty POJOs'() {
798
+ 'POJO'() {
802
799
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
803
- },
804
- 'different POJOs'() {
805
800
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
806
- },
807
- 'different POJOs with same keys but different values'() {
808
801
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
809
- },
810
- 'different POJOs with different keys but same values'() {
811
802
  $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
803
+ $.$mol_assert_ok($.$mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
804
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
812
805
  },
813
806
  'Array'() {
814
807
  $.$mol_assert_ok($.$mol_compare_deep([], []));
@@ -816,17 +809,12 @@ var $;
816
809
  $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
817
810
  $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
818
811
  },
819
- 'same POJO trees'() {
820
- $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
821
- },
822
- 'different classes with same values'() {
823
- class Obj {
824
- foo = 1;
812
+ 'Non POJO are different'() {
813
+ class Thing extends Object {
825
814
  }
826
- const a = new Obj;
827
- const b = new class extends Obj {
828
- };
829
- $.$mol_assert_not($.$mol_compare_deep(a, b));
815
+ $.$mol_assert_not($.$mol_compare_deep(new Thing, new Thing));
816
+ $.$mol_assert_not($.$mol_compare_deep(() => 1, () => 1));
817
+ $.$mol_assert_not($.$mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
830
818
  },
831
819
  'same POJOs with cyclic reference'() {
832
820
  const a = { foo: {} };
@@ -835,41 +823,6 @@ var $;
835
823
  b['self'] = b;
836
824
  $.$mol_assert_ok($.$mol_compare_deep(a, b));
837
825
  },
838
- 'empty Element'() {
839
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
840
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
841
- },
842
- 'Element with attributes'() {
843
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
844
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
845
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
846
- },
847
- 'Element with styles'() {
848
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
849
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
850
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
851
- },
852
- 'Element with content'() {
853
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
854
- "foo",
855
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
856
- "foo",
857
- $.$mol_jsx("br", null))));
858
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
859
- "foo",
860
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
861
- "bar",
862
- $.$mol_jsx("br", null))));
863
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
864
- "foo",
865
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
866
- "foo",
867
- $.$mol_jsx("hr", null))));
868
- },
869
- 'Element with handlers'() {
870
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
871
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
872
- },
873
826
  'Date'() {
874
827
  $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
875
828
  $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
@@ -881,8 +834,9 @@ var $;
881
834
  },
882
835
  'Map'() {
883
836
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
884
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
837
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
885
838
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
839
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
886
840
  },
887
841
  'Set'() {
888
842
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -894,6 +848,21 @@ var $;
894
848
  $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
895
849
  $.$mol_assert_not($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
896
850
  },
851
+ 'Custom comparator'() {
852
+ class User {
853
+ name;
854
+ rand;
855
+ constructor(name, rand = Math.random()) {
856
+ this.name = name;
857
+ this.rand = rand;
858
+ }
859
+ [Symbol.toPrimitive](mode) {
860
+ return this.name;
861
+ }
862
+ }
863
+ $.$mol_assert_ok($.$mol_compare_deep(new User('Jin'), new User('Jin')));
864
+ $.$mol_assert_not($.$mol_compare_deep(new User('Jin'), new User('John')));
865
+ },
897
866
  });
898
867
  })($ || ($ = {}));
899
868
  //deep.test.js.map
@@ -901,97 +870,123 @@ var $;
901
870
  "use strict";
902
871
  var $;
903
872
  (function ($) {
904
- const a_stack = [];
905
- const b_stack = [];
906
- let cache = null;
907
- function $mol_compare_deep(a, b) {
908
- if (Object.is(a, b))
873
+ let cache = new WeakMap();
874
+ function $mol_compare_deep(left, right) {
875
+ if (Object.is(left, right))
909
876
  return true;
910
- const a_type = typeof a;
911
- const b_type = typeof b;
912
- if (a_type !== b_type)
877
+ if (left === null)
913
878
  return false;
914
- if (a_type === 'function')
915
- return a['toString']() === b['toString']();
916
- if (a_type !== 'object')
879
+ if (right === null)
917
880
  return false;
918
- if (!a || !b)
881
+ if (typeof left !== 'object')
919
882
  return false;
920
- if (a instanceof Error)
883
+ if (typeof right !== 'object')
921
884
  return false;
922
- if (a['constructor'] !== b['constructor'])
885
+ const left_proto = Reflect.getPrototypeOf(left);
886
+ const right_proto = Reflect.getPrototypeOf(right);
887
+ if (left_proto !== right_proto)
923
888
  return false;
924
- if (a instanceof RegExp)
925
- return a.toString() === b['toString']();
926
- const ref = a_stack.indexOf(a);
927
- if (ref >= 0) {
928
- return Object.is(b_stack[ref], b);
929
- }
930
- if (!cache)
931
- cache = new WeakMap;
932
- let a_cache = cache.get(a);
933
- if (a_cache) {
934
- const b_cache = a_cache.get(b);
935
- if (typeof b_cache === 'boolean')
936
- return b_cache;
889
+ if (left instanceof Boolean)
890
+ return Object.is(left.valueOf(), right['valueOf']());
891
+ if (left instanceof Number)
892
+ return Object.is(left.valueOf(), right['valueOf']());
893
+ if (left instanceof String)
894
+ return Object.is(left.valueOf(), right['valueOf']());
895
+ if (left instanceof Date)
896
+ return Object.is(left.valueOf(), right['valueOf']());
897
+ if (left instanceof RegExp)
898
+ return left.source === right['source'] && left.flags === right['flags'];
899
+ let left_cache = cache.get(left);
900
+ if (left_cache) {
901
+ const right_cache = left_cache.get(right);
902
+ if (typeof right_cache === 'boolean')
903
+ return right_cache;
937
904
  }
938
905
  else {
939
- a_cache = new WeakMap();
940
- cache.set(a, a_cache);
906
+ left_cache = new WeakMap([[right, true]]);
907
+ cache.set(left, left_cache);
941
908
  }
942
- a_stack.push(a);
943
- b_stack.push(b);
944
909
  let result;
945
910
  try {
946
- if (Symbol.iterator in a) {
947
- const a_iter = a[Symbol.iterator]();
948
- const b_iter = b[Symbol.iterator]();
949
- while (true) {
950
- const a_next = a_iter.next();
951
- const b_next = b_iter.next();
952
- if (a_next.done !== b_next.done)
953
- return result = false;
954
- if (a_next.done)
955
- break;
956
- if (!$mol_compare_deep(a_next.value, b_next.value))
957
- return result = false;
958
- }
959
- return result = true;
960
- }
961
- let count = 0;
962
- for (let key in a) {
963
- try {
964
- if (!$mol_compare_deep(a[key], b[key]))
965
- return result = false;
966
- }
967
- catch (error) {
968
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
969
- }
970
- ++count;
971
- }
972
- for (let key in b) {
973
- --count;
974
- if (count < 0)
975
- return result = false;
976
- }
977
- if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
978
- if (!Object.is(a['valueOf'](), b['valueOf']()))
979
- return result = false;
980
- }
981
- return result = true;
911
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
912
+ result = compare_pojo(left, right);
913
+ else if (Array.isArray(left))
914
+ result = compare_array(left, right);
915
+ else if (left instanceof Set)
916
+ result = compare_set(left, right);
917
+ else if (left instanceof Map)
918
+ result = compare_map(left, right);
919
+ else if (ArrayBuffer.isView(left))
920
+ result = compare_buffer(left, right);
921
+ else if (Symbol.toPrimitive in left)
922
+ result = compare_primitive(left, right);
923
+ else
924
+ result = false;
982
925
  }
983
926
  finally {
984
- a_stack.pop();
985
- b_stack.pop();
986
- if (a_stack.length === 0) {
987
- cache = null;
988
- }
989
- else {
990
- a_cache.set(b, result);
991
- }
927
+ left_cache.set(right, result);
992
928
  }
929
+ return result;
993
930
  }
994
931
  $.$mol_compare_deep = $mol_compare_deep;
932
+ function compare_array(left, right) {
933
+ const len = left.length;
934
+ if (len !== right.length)
935
+ return false;
936
+ for (let i = 0; i < len; ++i) {
937
+ if (!$mol_compare_deep(left[i], right[i]))
938
+ return false;
939
+ }
940
+ return true;
941
+ }
942
+ function compare_buffer(left, right) {
943
+ const len = left.byteLength;
944
+ if (len !== right.byteLength)
945
+ return false;
946
+ for (let i = 0; i < len; ++i) {
947
+ if (left[i] !== right[i])
948
+ return false;
949
+ }
950
+ return true;
951
+ }
952
+ function compare_iterator(left, right, compare) {
953
+ while (true) {
954
+ const left_next = left.next();
955
+ const right_next = right.next();
956
+ if (left_next.done !== right_next.done)
957
+ return false;
958
+ if (left_next.done)
959
+ break;
960
+ if (!compare(left_next.value, right_next.value))
961
+ return false;
962
+ }
963
+ return true;
964
+ }
965
+ function compare_set(left, right) {
966
+ if (left.size !== right.size)
967
+ return false;
968
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
969
+ }
970
+ function compare_map(left, right) {
971
+ if (left.size !== right.size)
972
+ return false;
973
+ return compare_iterator(left.keys(), right.keys(), Object.is)
974
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
975
+ }
976
+ function compare_pojo(left, right) {
977
+ const left_keys = Object.getOwnPropertyNames(left);
978
+ const right_keys = Object.getOwnPropertyNames(right);
979
+ if (left_keys.length !== right_keys.length)
980
+ return false;
981
+ for (let key of left_keys) {
982
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
983
+ return false;
984
+ }
985
+ return true;
986
+ }
987
+ function compare_primitive(left, right) {
988
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
989
+ }
995
990
  })($ || ($ = {}));
996
991
  //deep.js.map
997
992
  ;
@@ -1587,6 +1582,10 @@ var $;
1587
1582
  'format typed'() {
1588
1583
  $.$mol_assert_equal(new $.$mol_time_duration('P1Y2M3DT4h5m6s').toString('P#Y#M#DT#h#m#s'), 'P1Y2M3DT4H5M6S');
1589
1584
  },
1585
+ 'comparison'() {
1586
+ const iso = 'P1Y1M1DT1h1m1s';
1587
+ $.$mol_assert_like(new $.$mol_time_duration(iso), new $.$mol_time_duration(iso));
1588
+ },
1590
1589
  });
1591
1590
  })($ || ($ = {}));
1592
1591
  //duration.test.js.map
@@ -1686,6 +1685,9 @@ var $;
1686
1685
  toString(pattern = 'P#Y#M#DT#h#m#s') {
1687
1686
  return super.toString(pattern);
1688
1687
  }
1688
+ [Symbol.toPrimitive](mode) {
1689
+ return mode === 'number' ? this.valueOf() : this.toString();
1690
+ }
1689
1691
  static patterns = {
1690
1692
  '#Y': (duration) => {
1691
1693
  if (!duration.year)
@@ -1788,7 +1790,8 @@ var $;
1788
1790
  }
1789
1791
  }
1790
1792
  const boxify = $.$mol_data_pipe((input) => input.toString(), Box);
1791
- $.$mol_assert_like(boxify(5), new Box('5'));
1793
+ $.$mol_assert_ok(boxify(5) instanceof Box);
1794
+ $.$mol_assert_like(boxify(5).value, '5');
1792
1795
  },
1793
1796
  });
1794
1797
  })($ || ($ = {}));