mol_regexp 0.0.201 → 0.0.205

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_regexp",
3
- "version": "0.0.201",
3
+ "version": "0.0.205",
4
4
  "main": "node.js",
5
5
  "module": "node.esm.js",
6
6
  "browser": "web.js",
package/web.test.js CHANGED
@@ -349,23 +349,16 @@ var $;
349
349
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
350
350
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
351
351
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
352
- },
353
- 'Number'() {
354
352
  $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
355
- $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
356
353
  $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
357
354
  },
358
- 'empty POJOs'() {
355
+ 'POJO'() {
359
356
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
360
- },
361
- 'different POJOs'() {
362
357
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
363
- },
364
- 'different POJOs with same keys but different values'() {
365
358
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
366
- },
367
- 'different POJOs with different keys but same values'() {
368
359
  $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
360
+ $.$mol_assert_ok($.$mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
361
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
369
362
  },
370
363
  'Array'() {
371
364
  $.$mol_assert_ok($.$mol_compare_deep([], []));
@@ -373,17 +366,12 @@ var $;
373
366
  $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
374
367
  $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
375
368
  },
376
- 'same POJO trees'() {
377
- $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
378
- },
379
- 'different classes with same values'() {
380
- class Obj {
381
- foo = 1;
369
+ 'Non POJO are different'() {
370
+ class Thing extends Object {
382
371
  }
383
- const a = new Obj;
384
- const b = new class extends Obj {
385
- };
386
- $.$mol_assert_not($.$mol_compare_deep(a, b));
372
+ $.$mol_assert_not($.$mol_compare_deep(new Thing, new Thing));
373
+ $.$mol_assert_not($.$mol_compare_deep(() => 1, () => 1));
374
+ $.$mol_assert_not($.$mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
387
375
  },
388
376
  'same POJOs with cyclic reference'() {
389
377
  const a = { foo: {} };
@@ -392,41 +380,6 @@ var $;
392
380
  b['self'] = b;
393
381
  $.$mol_assert_ok($.$mol_compare_deep(a, b));
394
382
  },
395
- 'empty Element'() {
396
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
397
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
398
- },
399
- 'Element with attributes'() {
400
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
401
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
402
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
403
- },
404
- 'Element with styles'() {
405
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
406
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
407
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
408
- },
409
- 'Element with content'() {
410
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
411
- "foo",
412
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
413
- "foo",
414
- $.$mol_jsx("br", null))));
415
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
416
- "foo",
417
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
418
- "bar",
419
- $.$mol_jsx("br", null))));
420
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
421
- "foo",
422
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
423
- "foo",
424
- $.$mol_jsx("hr", null))));
425
- },
426
- 'Element with handlers'() {
427
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
428
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
429
- },
430
383
  'Date'() {
431
384
  $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
432
385
  $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
@@ -438,8 +391,9 @@ var $;
438
391
  },
439
392
  'Map'() {
440
393
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
441
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
394
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
442
395
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
396
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
443
397
  },
444
398
  'Set'() {
445
399
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -451,6 +405,21 @@ var $;
451
405
  $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
452
406
  $.$mol_assert_not($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
453
407
  },
408
+ 'Custom comparator'() {
409
+ class User {
410
+ name;
411
+ rand;
412
+ constructor(name, rand = Math.random()) {
413
+ this.name = name;
414
+ this.rand = rand;
415
+ }
416
+ [Symbol.toPrimitive](mode) {
417
+ return this.name;
418
+ }
419
+ }
420
+ $.$mol_assert_ok($.$mol_compare_deep(new User('Jin'), new User('Jin')));
421
+ $.$mol_assert_not($.$mol_compare_deep(new User('Jin'), new User('John')));
422
+ },
454
423
  });
455
424
  })($ || ($ = {}));
456
425
  //deep.test.js.map
@@ -458,97 +427,123 @@ var $;
458
427
  "use strict";
459
428
  var $;
460
429
  (function ($) {
461
- const a_stack = [];
462
- const b_stack = [];
463
- let cache = null;
464
- function $mol_compare_deep(a, b) {
465
- if (Object.is(a, b))
430
+ let cache = new WeakMap();
431
+ function $mol_compare_deep(left, right) {
432
+ if (Object.is(left, right))
466
433
  return true;
467
- const a_type = typeof a;
468
- const b_type = typeof b;
469
- if (a_type !== b_type)
434
+ if (left === null)
470
435
  return false;
471
- if (a_type === 'function')
472
- return a['toString']() === b['toString']();
473
- if (a_type !== 'object')
436
+ if (right === null)
474
437
  return false;
475
- if (!a || !b)
438
+ if (typeof left !== 'object')
476
439
  return false;
477
- if (a instanceof Error)
440
+ if (typeof right !== 'object')
478
441
  return false;
479
- if (a['constructor'] !== b['constructor'])
442
+ const left_proto = Reflect.getPrototypeOf(left);
443
+ const right_proto = Reflect.getPrototypeOf(right);
444
+ if (left_proto !== right_proto)
480
445
  return false;
481
- if (a instanceof RegExp)
482
- return a.toString() === b['toString']();
483
- const ref = a_stack.indexOf(a);
484
- if (ref >= 0) {
485
- return Object.is(b_stack[ref], b);
486
- }
487
- if (!cache)
488
- cache = new WeakMap;
489
- let a_cache = cache.get(a);
490
- if (a_cache) {
491
- const b_cache = a_cache.get(b);
492
- if (typeof b_cache === 'boolean')
493
- return b_cache;
446
+ if (left instanceof Boolean)
447
+ return Object.is(left.valueOf(), right['valueOf']());
448
+ if (left instanceof Number)
449
+ return Object.is(left.valueOf(), right['valueOf']());
450
+ if (left instanceof String)
451
+ return Object.is(left.valueOf(), right['valueOf']());
452
+ if (left instanceof Date)
453
+ return Object.is(left.valueOf(), right['valueOf']());
454
+ if (left instanceof RegExp)
455
+ return left.source === right['source'] && left.flags === right['flags'];
456
+ let left_cache = cache.get(left);
457
+ if (left_cache) {
458
+ const right_cache = left_cache.get(right);
459
+ if (typeof right_cache === 'boolean')
460
+ return right_cache;
494
461
  }
495
462
  else {
496
- a_cache = new WeakMap();
497
- cache.set(a, a_cache);
463
+ left_cache = new WeakMap([[right, true]]);
464
+ cache.set(left, left_cache);
498
465
  }
499
- a_stack.push(a);
500
- b_stack.push(b);
501
466
  let result;
502
467
  try {
503
- if (Symbol.iterator in a) {
504
- const a_iter = a[Symbol.iterator]();
505
- const b_iter = b[Symbol.iterator]();
506
- while (true) {
507
- const a_next = a_iter.next();
508
- const b_next = b_iter.next();
509
- if (a_next.done !== b_next.done)
510
- return result = false;
511
- if (a_next.done)
512
- break;
513
- if (!$mol_compare_deep(a_next.value, b_next.value))
514
- return result = false;
515
- }
516
- return result = true;
517
- }
518
- let count = 0;
519
- for (let key in a) {
520
- try {
521
- if (!$mol_compare_deep(a[key], b[key]))
522
- return result = false;
523
- }
524
- catch (error) {
525
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
526
- }
527
- ++count;
528
- }
529
- for (let key in b) {
530
- --count;
531
- if (count < 0)
532
- return result = false;
533
- }
534
- if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
535
- if (!Object.is(a['valueOf'](), b['valueOf']()))
536
- return result = false;
537
- }
538
- return result = true;
468
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
469
+ result = compare_pojo(left, right);
470
+ else if (Array.isArray(left))
471
+ result = compare_array(left, right);
472
+ else if (left instanceof Set)
473
+ result = compare_set(left, right);
474
+ else if (left instanceof Map)
475
+ result = compare_map(left, right);
476
+ else if (ArrayBuffer.isView(left))
477
+ result = compare_buffer(left, right);
478
+ else if (Symbol.toPrimitive in left)
479
+ result = compare_primitive(left, right);
480
+ else
481
+ result = false;
539
482
  }
540
483
  finally {
541
- a_stack.pop();
542
- b_stack.pop();
543
- if (a_stack.length === 0) {
544
- cache = null;
545
- }
546
- else {
547
- a_cache.set(b, result);
548
- }
484
+ left_cache.set(right, result);
549
485
  }
486
+ return result;
550
487
  }
551
488
  $.$mol_compare_deep = $mol_compare_deep;
489
+ function compare_array(left, right) {
490
+ const len = left.length;
491
+ if (len !== right.length)
492
+ return false;
493
+ for (let i = 0; i < len; ++i) {
494
+ if (!$mol_compare_deep(left[i], right[i]))
495
+ return false;
496
+ }
497
+ return true;
498
+ }
499
+ function compare_buffer(left, right) {
500
+ const len = left.byteLength;
501
+ if (len !== right.byteLength)
502
+ return false;
503
+ for (let i = 0; i < len; ++i) {
504
+ if (left[i] !== right[i])
505
+ return false;
506
+ }
507
+ return true;
508
+ }
509
+ function compare_iterator(left, right, compare) {
510
+ while (true) {
511
+ const left_next = left.next();
512
+ const right_next = right.next();
513
+ if (left_next.done !== right_next.done)
514
+ return false;
515
+ if (left_next.done)
516
+ break;
517
+ if (!compare(left_next.value, right_next.value))
518
+ return false;
519
+ }
520
+ return true;
521
+ }
522
+ function compare_set(left, right) {
523
+ if (left.size !== right.size)
524
+ return false;
525
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
526
+ }
527
+ function compare_map(left, right) {
528
+ if (left.size !== right.size)
529
+ return false;
530
+ return compare_iterator(left.keys(), right.keys(), Object.is)
531
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
532
+ }
533
+ function compare_pojo(left, right) {
534
+ const left_keys = Object.getOwnPropertyNames(left);
535
+ const right_keys = Object.getOwnPropertyNames(right);
536
+ if (left_keys.length !== right_keys.length)
537
+ return false;
538
+ for (let key of left_keys) {
539
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
540
+ return false;
541
+ }
542
+ return true;
543
+ }
544
+ function compare_primitive(left, right) {
545
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
546
+ }
552
547
  })($ || ($ = {}));
553
548
  //deep.js.map
554
549
  ;
@@ -1034,91 +1029,5 @@ var $;
1034
1029
  $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
1035
1030
  })($ || ($ = {}));
1036
1031
  //log3.web.js.map
1037
- ;
1038
- "use strict";
1039
- var $;
1040
- (function ($) {
1041
- $.$mol_test({
1042
- 'equal paths'() {
1043
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]);
1044
- $.$mol_assert_like(diff, {
1045
- prefix: [1, 2, 3, 4],
1046
- suffix: [[], [], []],
1047
- });
1048
- },
1049
- 'different suffix'() {
1050
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 5, 4]);
1051
- $.$mol_assert_like(diff, {
1052
- prefix: [1, 2],
1053
- suffix: [[3, 4], [3, 5], [5, 4]],
1054
- });
1055
- },
1056
- 'one contains other'() {
1057
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2], [1, 2, 3]);
1058
- $.$mol_assert_like(diff, {
1059
- prefix: [1, 2],
1060
- suffix: [[3, 4], [], [3]],
1061
- });
1062
- },
1063
- 'fully different'() {
1064
- const diff = $.$mol_diff_path([1, 2], [3, 4], [5, 6]);
1065
- $.$mol_assert_like(diff, {
1066
- prefix: [],
1067
- suffix: [[1, 2], [3, 4], [5, 6]],
1068
- });
1069
- },
1070
- });
1071
- })($ || ($ = {}));
1072
- //path.test.js.map
1073
- ;
1074
- "use strict";
1075
- var $;
1076
- (function ($) {
1077
- function $mol_diff_path(...paths) {
1078
- const limit = Math.min(...paths.map(path => path.length));
1079
- lookup: for (var i = 0; i < limit; ++i) {
1080
- const first = paths[0][i];
1081
- for (let j = 1; j < paths.length; ++j) {
1082
- if (paths[j][i] !== first)
1083
- break lookup;
1084
- }
1085
- }
1086
- return {
1087
- prefix: paths[0].slice(0, i),
1088
- suffix: paths.map(path => path.slice(i)),
1089
- };
1090
- }
1091
- $.$mol_diff_path = $mol_diff_path;
1092
- })($ || ($ = {}));
1093
- //path.js.map
1094
- ;
1095
- "use strict";
1096
- var $;
1097
- (function ($) {
1098
- class $mol_error_mix extends Error {
1099
- errors;
1100
- constructor(message, ...errors) {
1101
- super(message);
1102
- this.errors = errors;
1103
- if (errors.length) {
1104
- const stacks = [...errors.map(error => error.stack), this.stack];
1105
- const diff = $.$mol_diff_path(...stacks.map(stack => {
1106
- if (!stack)
1107
- return [];
1108
- return stack.split('\n').reverse();
1109
- }));
1110
- const head = diff.prefix.reverse().join('\n');
1111
- const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
1112
- this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
1113
- this.message += errors.map(error => '\n' + error.message).join('');
1114
- }
1115
- }
1116
- toJSON() {
1117
- return this.message;
1118
- }
1119
- }
1120
- $.$mol_error_mix = $mol_error_mix;
1121
- })($ || ($ = {}));
1122
- //mix.js.map
1123
1032
 
1124
1033
  //# sourceMappingURL=web.test.js.map