mol_time_all 1.1.24 → 1.1.25

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
@@ -1037,23 +1037,16 @@ var $;
1037
1037
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
1038
1038
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
1039
1039
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
1040
- },
1041
- 'Number'() {
1042
1040
  $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
1043
- $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
1044
1041
  $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
1045
1042
  },
1046
- 'empty POJOs'() {
1043
+ 'POJO'() {
1047
1044
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
1048
- },
1049
- 'different POJOs'() {
1050
1045
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
1051
- },
1052
- 'different POJOs with same keys but different values'() {
1053
1046
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
1054
- },
1055
- 'different POJOs with different keys but same values'() {
1056
1047
  $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
1048
+ $.$mol_assert_ok($.$mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
1049
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
1057
1050
  },
1058
1051
  'Array'() {
1059
1052
  $.$mol_assert_ok($.$mol_compare_deep([], []));
@@ -1061,17 +1054,12 @@ var $;
1061
1054
  $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
1062
1055
  $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
1063
1056
  },
1064
- 'same POJO trees'() {
1065
- $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
1066
- },
1067
- 'different classes with same values'() {
1068
- class Obj {
1069
- foo = 1;
1057
+ 'Non POJO are different'() {
1058
+ class Thing extends Object {
1070
1059
  }
1071
- const a = new Obj;
1072
- const b = new class extends Obj {
1073
- };
1074
- $.$mol_assert_not($.$mol_compare_deep(a, b));
1060
+ $.$mol_assert_not($.$mol_compare_deep(new Thing, new Thing));
1061
+ $.$mol_assert_not($.$mol_compare_deep(() => 1, () => 1));
1062
+ $.$mol_assert_not($.$mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
1075
1063
  },
1076
1064
  'same POJOs with cyclic reference'() {
1077
1065
  const a = { foo: {} };
@@ -1080,41 +1068,6 @@ var $;
1080
1068
  b['self'] = b;
1081
1069
  $.$mol_assert_ok($.$mol_compare_deep(a, b));
1082
1070
  },
1083
- 'empty Element'() {
1084
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
1085
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
1086
- },
1087
- 'Element with attributes'() {
1088
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
1089
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
1090
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
1091
- },
1092
- 'Element with styles'() {
1093
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
1094
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
1095
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
1096
- },
1097
- 'Element with content'() {
1098
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
1099
- "foo",
1100
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
1101
- "foo",
1102
- $.$mol_jsx("br", null))));
1103
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
1104
- "foo",
1105
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
1106
- "bar",
1107
- $.$mol_jsx("br", null))));
1108
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
1109
- "foo",
1110
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
1111
- "foo",
1112
- $.$mol_jsx("hr", null))));
1113
- },
1114
- 'Element with handlers'() {
1115
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
1116
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
1117
- },
1118
1071
  'Date'() {
1119
1072
  $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
1120
1073
  $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
@@ -1126,8 +1079,9 @@ var $;
1126
1079
  },
1127
1080
  'Map'() {
1128
1081
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
1129
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
1082
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
1130
1083
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
1084
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
1131
1085
  },
1132
1086
  'Set'() {
1133
1087
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -1146,97 +1100,118 @@ var $;
1146
1100
  "use strict";
1147
1101
  var $;
1148
1102
  (function ($) {
1149
- const a_stack = [];
1150
- const b_stack = [];
1151
- let cache = null;
1152
- function $mol_compare_deep(a, b) {
1153
- if (Object.is(a, b))
1103
+ let cache = new WeakMap();
1104
+ function $mol_compare_deep(left, right) {
1105
+ if (Object.is(left, right))
1154
1106
  return true;
1155
- const a_type = typeof a;
1156
- const b_type = typeof b;
1157
- if (a_type !== b_type)
1107
+ if (left === null)
1158
1108
  return false;
1159
- if (a_type === 'function')
1160
- return a['toString']() === b['toString']();
1161
- if (a_type !== 'object')
1109
+ if (right === null)
1162
1110
  return false;
1163
- if (!a || !b)
1111
+ if (typeof left !== 'object')
1164
1112
  return false;
1165
- if (a instanceof Error)
1113
+ if (typeof right !== 'object')
1166
1114
  return false;
1167
- if (a['constructor'] !== b['constructor'])
1115
+ const left_proto = Reflect.getPrototypeOf(left);
1116
+ const right_proto = Reflect.getPrototypeOf(right);
1117
+ if (left_proto !== right_proto)
1168
1118
  return false;
1169
- if (a instanceof RegExp)
1170
- return a.toString() === b['toString']();
1171
- const ref = a_stack.indexOf(a);
1172
- if (ref >= 0) {
1173
- return Object.is(b_stack[ref], b);
1174
- }
1175
- if (!cache)
1176
- cache = new WeakMap;
1177
- let a_cache = cache.get(a);
1178
- if (a_cache) {
1179
- const b_cache = a_cache.get(b);
1180
- if (typeof b_cache === 'boolean')
1181
- return b_cache;
1119
+ if (left instanceof Boolean)
1120
+ return Object.is(left.valueOf(), right['valueOf']());
1121
+ if (left instanceof Number)
1122
+ return Object.is(left.valueOf(), right['valueOf']());
1123
+ if (left instanceof String)
1124
+ return Object.is(left.valueOf(), right['valueOf']());
1125
+ if (left instanceof Date)
1126
+ return Object.is(left.valueOf(), right['valueOf']());
1127
+ if (left instanceof RegExp)
1128
+ return left.source === right['source'] && left.flags === right['flags'];
1129
+ let left_cache = cache.get(left);
1130
+ if (left_cache) {
1131
+ const right_cache = left_cache.get(right);
1132
+ if (typeof right_cache === 'boolean')
1133
+ return right_cache;
1182
1134
  }
1183
1135
  else {
1184
- a_cache = new WeakMap();
1185
- cache.set(a, a_cache);
1136
+ left_cache = new WeakMap([[right, true]]);
1137
+ cache.set(left, left_cache);
1186
1138
  }
1187
- a_stack.push(a);
1188
- b_stack.push(b);
1189
1139
  let result;
1190
1140
  try {
1191
- if (Symbol.iterator in a) {
1192
- const a_iter = a[Symbol.iterator]();
1193
- const b_iter = b[Symbol.iterator]();
1194
- while (true) {
1195
- const a_next = a_iter.next();
1196
- const b_next = b_iter.next();
1197
- if (a_next.done !== b_next.done)
1198
- return result = false;
1199
- if (a_next.done)
1200
- break;
1201
- if (!$mol_compare_deep(a_next.value, b_next.value))
1202
- return result = false;
1203
- }
1204
- return result = true;
1205
- }
1206
- let count = 0;
1207
- for (let key in a) {
1208
- try {
1209
- if (!$mol_compare_deep(a[key], b[key]))
1210
- return result = false;
1211
- }
1212
- catch (error) {
1213
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
1214
- }
1215
- ++count;
1216
- }
1217
- for (let key in b) {
1218
- --count;
1219
- if (count < 0)
1220
- return result = false;
1221
- }
1222
- if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
1223
- if (!Object.is(a['valueOf'](), b['valueOf']()))
1224
- return result = false;
1225
- }
1226
- return result = true;
1141
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
1142
+ result = compare_pojo(left, right);
1143
+ else if (Array.isArray(left))
1144
+ result = compare_array(left, right);
1145
+ else if (left instanceof Set)
1146
+ result = compare_set(left, right);
1147
+ else if (left instanceof Map)
1148
+ result = compare_map(left, right);
1149
+ else if (ArrayBuffer.isView(left))
1150
+ result = compare_buffer(left, right);
1151
+ else
1152
+ result = false;
1227
1153
  }
1228
1154
  finally {
1229
- a_stack.pop();
1230
- b_stack.pop();
1231
- if (a_stack.length === 0) {
1232
- cache = null;
1233
- }
1234
- else {
1235
- a_cache.set(b, result);
1236
- }
1155
+ left_cache.set(right, result);
1237
1156
  }
1157
+ return result;
1238
1158
  }
1239
1159
  $.$mol_compare_deep = $mol_compare_deep;
1160
+ function compare_array(left, right) {
1161
+ const len = left.length;
1162
+ if (len !== right.length)
1163
+ return false;
1164
+ for (let i = 0; i < len; ++i) {
1165
+ if (!$mol_compare_deep(left[i], right[i]))
1166
+ return false;
1167
+ }
1168
+ return true;
1169
+ }
1170
+ function compare_buffer(left, right) {
1171
+ const len = left.byteLength;
1172
+ if (len !== right.byteLength)
1173
+ return false;
1174
+ for (let i = 0; i < len; ++i) {
1175
+ if (left[i] !== right[i])
1176
+ return false;
1177
+ }
1178
+ return true;
1179
+ }
1180
+ function compare_iterator(left, right, compare) {
1181
+ while (true) {
1182
+ const left_next = left.next();
1183
+ const right_next = right.next();
1184
+ if (left_next.done !== right_next.done)
1185
+ return false;
1186
+ if (left_next.done)
1187
+ break;
1188
+ if (!compare(left_next.value, right_next.value))
1189
+ return false;
1190
+ }
1191
+ return true;
1192
+ }
1193
+ function compare_set(left, right) {
1194
+ if (left.size !== right.size)
1195
+ return false;
1196
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
1197
+ }
1198
+ function compare_map(left, right) {
1199
+ if (left.size !== right.size)
1200
+ return false;
1201
+ return compare_iterator(left.keys(), right.keys(), Object.is)
1202
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
1203
+ }
1204
+ function compare_pojo(left, right) {
1205
+ const left_keys = Object.getOwnPropertyNames(left);
1206
+ const right_keys = Object.getOwnPropertyNames(right);
1207
+ if (left_keys.length !== right_keys.length)
1208
+ return false;
1209
+ for (let key of left_keys) {
1210
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
1211
+ return false;
1212
+ }
1213
+ return true;
1214
+ }
1240
1215
  })($ || ($ = {}));
1241
1216
  //deep.js.map
1242
1217
  ;
@@ -2204,91 +2179,5 @@ var $;
2204
2179
  ;
2205
2180
  "use strict";
2206
2181
  //equals.js.map
2207
- ;
2208
- "use strict";
2209
- var $;
2210
- (function ($) {
2211
- $.$mol_test({
2212
- 'equal paths'() {
2213
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]);
2214
- $.$mol_assert_like(diff, {
2215
- prefix: [1, 2, 3, 4],
2216
- suffix: [[], [], []],
2217
- });
2218
- },
2219
- 'different suffix'() {
2220
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 5, 4]);
2221
- $.$mol_assert_like(diff, {
2222
- prefix: [1, 2],
2223
- suffix: [[3, 4], [3, 5], [5, 4]],
2224
- });
2225
- },
2226
- 'one contains other'() {
2227
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2], [1, 2, 3]);
2228
- $.$mol_assert_like(diff, {
2229
- prefix: [1, 2],
2230
- suffix: [[3, 4], [], [3]],
2231
- });
2232
- },
2233
- 'fully different'() {
2234
- const diff = $.$mol_diff_path([1, 2], [3, 4], [5, 6]);
2235
- $.$mol_assert_like(diff, {
2236
- prefix: [],
2237
- suffix: [[1, 2], [3, 4], [5, 6]],
2238
- });
2239
- },
2240
- });
2241
- })($ || ($ = {}));
2242
- //path.test.js.map
2243
- ;
2244
- "use strict";
2245
- var $;
2246
- (function ($) {
2247
- function $mol_diff_path(...paths) {
2248
- const limit = Math.min(...paths.map(path => path.length));
2249
- lookup: for (var i = 0; i < limit; ++i) {
2250
- const first = paths[0][i];
2251
- for (let j = 1; j < paths.length; ++j) {
2252
- if (paths[j][i] !== first)
2253
- break lookup;
2254
- }
2255
- }
2256
- return {
2257
- prefix: paths[0].slice(0, i),
2258
- suffix: paths.map(path => path.slice(i)),
2259
- };
2260
- }
2261
- $.$mol_diff_path = $mol_diff_path;
2262
- })($ || ($ = {}));
2263
- //path.js.map
2264
- ;
2265
- "use strict";
2266
- var $;
2267
- (function ($) {
2268
- class $mol_error_mix extends Error {
2269
- errors;
2270
- constructor(message, ...errors) {
2271
- super(message);
2272
- this.errors = errors;
2273
- if (errors.length) {
2274
- const stacks = [...errors.map(error => error.stack), this.stack];
2275
- const diff = $.$mol_diff_path(...stacks.map(stack => {
2276
- if (!stack)
2277
- return [];
2278
- return stack.split('\n').reverse();
2279
- }));
2280
- const head = diff.prefix.reverse().join('\n');
2281
- const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
2282
- this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
2283
- this.message += errors.map(error => '\n' + error.message).join('');
2284
- }
2285
- }
2286
- toJSON() {
2287
- return this.message;
2288
- }
2289
- }
2290
- $.$mol_error_mix = $mol_error_mix;
2291
- })($ || ($ = {}));
2292
- //mix.js.map
2293
2182
 
2294
2183
  //# sourceMappingURL=node.test.js.map