mol_data_all 1.1.152 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mol_data_all",
3
- "version": "1.1.152",
3
+ "version": "1.1.156",
4
4
  "main": "node.js",
5
5
  "module": "node.esm.js",
6
6
  "browser": "web.js",
package/web.test.js CHANGED
@@ -339,7 +339,8 @@ var $;
339
339
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
340
340
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
341
341
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
342
- $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(1)));
342
+ $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
343
+ $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
343
344
  },
344
345
  'POJO'() {
345
346
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
@@ -380,8 +381,9 @@ var $;
380
381
  },
381
382
  'Map'() {
382
383
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
383
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
384
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
384
385
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
386
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
385
387
  },
386
388
  'Set'() {
387
389
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -393,6 +395,21 @@ var $;
393
395
  $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
394
396
  $.$mol_assert_not($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
395
397
  },
398
+ 'Custom comparator'() {
399
+ class User {
400
+ name;
401
+ rand;
402
+ constructor(name, rand = Math.random()) {
403
+ this.name = name;
404
+ this.rand = rand;
405
+ }
406
+ [Symbol.toPrimitive](mode) {
407
+ return this.name;
408
+ }
409
+ }
410
+ $.$mol_assert_ok($.$mol_compare_deep(new User('Jin'), new User('Jin')));
411
+ $.$mol_assert_not($.$mol_compare_deep(new User('Jin'), new User('John')));
412
+ },
396
413
  });
397
414
  })($ || ($ = {}));
398
415
  //deep.test.js.map
@@ -412,8 +429,20 @@ var $;
412
429
  return false;
413
430
  if (typeof right !== 'object')
414
431
  return false;
415
- if (left['constructor'] !== right['constructor'])
432
+ const left_proto = Reflect.getPrototypeOf(left);
433
+ const right_proto = Reflect.getPrototypeOf(right);
434
+ if (left_proto !== right_proto)
416
435
  return false;
436
+ if (left instanceof Boolean)
437
+ return Object.is(left.valueOf(), right['valueOf']());
438
+ if (left instanceof Number)
439
+ return Object.is(left.valueOf(), right['valueOf']());
440
+ if (left instanceof String)
441
+ return Object.is(left.valueOf(), right['valueOf']());
442
+ if (left instanceof Date)
443
+ return Object.is(left.valueOf(), right['valueOf']());
444
+ if (left instanceof RegExp)
445
+ return left.source === right['source'] && left.flags === right['flags'];
417
446
  let left_cache = cache.get(left);
418
447
  if (left_cache) {
419
448
  const right_cache = left_cache.get(right);
@@ -421,56 +450,90 @@ var $;
421
450
  return right_cache;
422
451
  }
423
452
  else {
424
- left_cache = new WeakMap();
453
+ left_cache = new WeakMap([[right, true]]);
425
454
  cache.set(left, left_cache);
426
- left_cache.set(right, true);
427
455
  }
428
- if (left instanceof RegExp)
429
- return left.toString() === right['toString']();
430
- if (left instanceof Date)
431
- return Object.is(left.valueOf(), right['valueOf']());
432
456
  let result;
433
457
  try {
434
- if (Symbol.iterator in left) {
435
- const left_iter = left[Symbol.iterator]();
436
- const right_iter = right[Symbol.iterator]();
437
- while (true) {
438
- const left_next = left_iter.next();
439
- const right_next = right_iter.next();
440
- if (left_next.done !== right_next.done)
441
- return result = false;
442
- if (left_next.done)
443
- break;
444
- if (!$mol_compare_deep(left_next.value, right_next.value))
445
- return result = false;
446
- }
447
- return result = true;
448
- }
449
- if (left['constructor'] !== ({}).constructor)
450
- return result = false;
451
- let count = 0;
452
- for (let key in left) {
453
- try {
454
- if (!$mol_compare_deep(left[key], right[key]))
455
- return result = false;
456
- }
457
- catch (error) {
458
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${left} and ${right}`, error));
459
- }
460
- ++count;
461
- }
462
- for (let key in right) {
463
- --count;
464
- if (count < 0)
465
- return result = false;
466
- }
467
- return result = true;
458
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
459
+ result = compare_pojo(left, right);
460
+ else if (Array.isArray(left))
461
+ result = compare_array(left, right);
462
+ else if (left instanceof Set)
463
+ result = compare_set(left, right);
464
+ else if (left instanceof Map)
465
+ result = compare_map(left, right);
466
+ else if (ArrayBuffer.isView(left))
467
+ result = compare_buffer(left, right);
468
+ else if (Symbol.toPrimitive in left)
469
+ result = compare_primitive(left, right);
470
+ else
471
+ result = false;
468
472
  }
469
473
  finally {
470
474
  left_cache.set(right, result);
471
475
  }
476
+ return result;
472
477
  }
473
478
  $.$mol_compare_deep = $mol_compare_deep;
479
+ function compare_array(left, right) {
480
+ const len = left.length;
481
+ if (len !== right.length)
482
+ return false;
483
+ for (let i = 0; i < len; ++i) {
484
+ if (!$mol_compare_deep(left[i], right[i]))
485
+ return false;
486
+ }
487
+ return true;
488
+ }
489
+ function compare_buffer(left, right) {
490
+ const len = left.byteLength;
491
+ if (len !== right.byteLength)
492
+ return false;
493
+ for (let i = 0; i < len; ++i) {
494
+ if (left[i] !== right[i])
495
+ return false;
496
+ }
497
+ return true;
498
+ }
499
+ function compare_iterator(left, right, compare) {
500
+ while (true) {
501
+ const left_next = left.next();
502
+ const right_next = right.next();
503
+ if (left_next.done !== right_next.done)
504
+ return false;
505
+ if (left_next.done)
506
+ break;
507
+ if (!compare(left_next.value, right_next.value))
508
+ return false;
509
+ }
510
+ return true;
511
+ }
512
+ function compare_set(left, right) {
513
+ if (left.size !== right.size)
514
+ return false;
515
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
516
+ }
517
+ function compare_map(left, right) {
518
+ if (left.size !== right.size)
519
+ return false;
520
+ return compare_iterator(left.keys(), right.keys(), Object.is)
521
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
522
+ }
523
+ function compare_pojo(left, right) {
524
+ const left_keys = Object.getOwnPropertyNames(left);
525
+ const right_keys = Object.getOwnPropertyNames(right);
526
+ if (left_keys.length !== right_keys.length)
527
+ return false;
528
+ for (let key of left_keys) {
529
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
530
+ return false;
531
+ }
532
+ return true;
533
+ }
534
+ function compare_primitive(left, right) {
535
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
536
+ }
474
537
  })($ || ($ = {}));
475
538
  //deep.js.map
476
539
  ;
@@ -1066,6 +1129,10 @@ var $;
1066
1129
  'format typed'() {
1067
1130
  $.$mol_assert_equal(new $.$mol_time_duration('P1Y2M3DT4h5m6s').toString('P#Y#M#DT#h#m#s'), 'P1Y2M3DT4H5M6S');
1068
1131
  },
1132
+ 'comparison'() {
1133
+ const iso = 'P1Y1M1DT1h1m1s';
1134
+ $.$mol_assert_like(new $.$mol_time_duration(iso), new $.$mol_time_duration(iso));
1135
+ },
1069
1136
  });
1070
1137
  })($ || ($ = {}));
1071
1138
  //duration.test.js.map
@@ -1165,6 +1232,9 @@ var $;
1165
1232
  toString(pattern = 'P#Y#M#DT#h#m#s') {
1166
1233
  return super.toString(pattern);
1167
1234
  }
1235
+ [Symbol.toPrimitive](mode) {
1236
+ return mode === 'number' ? this.valueOf() : this.toString();
1237
+ }
1168
1238
  static patterns = {
1169
1239
  '#Y': (duration) => {
1170
1240
  if (!duration.year)