mol_data_all 1.1.149 → 1.1.153

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.149",
3
+ "version": "1.1.153",
4
4
  "main": "node.js",
5
5
  "module": "node.esm.js",
6
6
  "browser": "web.js",
package/web.test.js CHANGED
@@ -339,23 +339,16 @@ 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
- },
343
- 'Number'() {
344
342
  $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
345
- $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
346
343
  $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
347
344
  },
348
- 'empty POJOs'() {
345
+ 'POJO'() {
349
346
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
350
- },
351
- 'different POJOs'() {
352
347
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
353
- },
354
- 'different POJOs with same keys but different values'() {
355
348
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
356
- },
357
- 'different POJOs with different keys but same values'() {
358
349
  $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
350
+ $.$mol_assert_ok($.$mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
351
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
359
352
  },
360
353
  'Array'() {
361
354
  $.$mol_assert_ok($.$mol_compare_deep([], []));
@@ -363,17 +356,12 @@ var $;
363
356
  $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
364
357
  $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
365
358
  },
366
- 'same POJO trees'() {
367
- $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
368
- },
369
- 'different classes with same values'() {
370
- class Obj {
371
- foo = 1;
359
+ 'Non POJO are different'() {
360
+ class Thing extends Object {
372
361
  }
373
- const a = new Obj;
374
- const b = new class extends Obj {
375
- };
376
- $.$mol_assert_not($.$mol_compare_deep(a, b));
362
+ $.$mol_assert_not($.$mol_compare_deep(new Thing, new Thing));
363
+ $.$mol_assert_not($.$mol_compare_deep(() => 1, () => 1));
364
+ $.$mol_assert_not($.$mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
377
365
  },
378
366
  'same POJOs with cyclic reference'() {
379
367
  const a = { foo: {} };
@@ -382,41 +370,6 @@ var $;
382
370
  b['self'] = b;
383
371
  $.$mol_assert_ok($.$mol_compare_deep(a, b));
384
372
  },
385
- 'empty Element'() {
386
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
387
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
388
- },
389
- 'Element with attributes'() {
390
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
391
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
392
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
393
- },
394
- 'Element with styles'() {
395
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
396
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
397
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
398
- },
399
- 'Element with content'() {
400
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
401
- "foo",
402
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
403
- "foo",
404
- $.$mol_jsx("br", null))));
405
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
406
- "foo",
407
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
408
- "bar",
409
- $.$mol_jsx("br", null))));
410
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
411
- "foo",
412
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
413
- "foo",
414
- $.$mol_jsx("hr", null))));
415
- },
416
- 'Element with handlers'() {
417
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
418
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
419
- },
420
373
  'Date'() {
421
374
  $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
422
375
  $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
@@ -428,8 +381,9 @@ var $;
428
381
  },
429
382
  'Map'() {
430
383
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
431
- $.$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]]])));
432
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]])));
433
387
  },
434
388
  'Set'() {
435
389
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -448,97 +402,118 @@ var $;
448
402
  "use strict";
449
403
  var $;
450
404
  (function ($) {
451
- const a_stack = [];
452
- const b_stack = [];
453
- let cache = null;
454
- function $mol_compare_deep(a, b) {
455
- if (Object.is(a, b))
405
+ let cache = new WeakMap();
406
+ function $mol_compare_deep(left, right) {
407
+ if (Object.is(left, right))
456
408
  return true;
457
- const a_type = typeof a;
458
- const b_type = typeof b;
459
- if (a_type !== b_type)
409
+ if (left === null)
460
410
  return false;
461
- if (a_type === 'function')
462
- return a['toString']() === b['toString']();
463
- if (a_type !== 'object')
411
+ if (right === null)
464
412
  return false;
465
- if (!a || !b)
413
+ if (typeof left !== 'object')
466
414
  return false;
467
- if (a instanceof Error)
415
+ if (typeof right !== 'object')
468
416
  return false;
469
- if (a['constructor'] !== b['constructor'])
417
+ const left_proto = Reflect.getPrototypeOf(left);
418
+ const right_proto = Reflect.getPrototypeOf(right);
419
+ if (left_proto !== right_proto)
470
420
  return false;
471
- if (a instanceof RegExp)
472
- return a.toString() === b['toString']();
473
- const ref = a_stack.indexOf(a);
474
- if (ref >= 0) {
475
- return Object.is(b_stack[ref], b);
476
- }
477
- if (!cache)
478
- cache = new WeakMap;
479
- let a_cache = cache.get(a);
480
- if (a_cache) {
481
- const b_cache = a_cache.get(b);
482
- if (typeof b_cache === 'boolean')
483
- return b_cache;
421
+ if (left instanceof Boolean)
422
+ return Object.is(left.valueOf(), right['valueOf']());
423
+ if (left instanceof Number)
424
+ return Object.is(left.valueOf(), right['valueOf']());
425
+ if (left instanceof String)
426
+ return Object.is(left.valueOf(), right['valueOf']());
427
+ if (left instanceof Date)
428
+ return Object.is(left.valueOf(), right['valueOf']());
429
+ if (left instanceof RegExp)
430
+ return left.source === right['source'] && left.flags === right['flags'];
431
+ let left_cache = cache.get(left);
432
+ if (left_cache) {
433
+ const right_cache = left_cache.get(right);
434
+ if (typeof right_cache === 'boolean')
435
+ return right_cache;
484
436
  }
485
437
  else {
486
- a_cache = new WeakMap();
487
- cache.set(a, a_cache);
438
+ left_cache = new WeakMap([[right, true]]);
439
+ cache.set(left, left_cache);
488
440
  }
489
- a_stack.push(a);
490
- b_stack.push(b);
491
441
  let result;
492
442
  try {
493
- if (Symbol.iterator in a) {
494
- const a_iter = a[Symbol.iterator]();
495
- const b_iter = b[Symbol.iterator]();
496
- while (true) {
497
- const a_next = a_iter.next();
498
- const b_next = b_iter.next();
499
- if (a_next.done !== b_next.done)
500
- return result = false;
501
- if (a_next.done)
502
- break;
503
- if (!$mol_compare_deep(a_next.value, b_next.value))
504
- return result = false;
505
- }
506
- return result = true;
507
- }
508
- let count = 0;
509
- for (let key in a) {
510
- try {
511
- if (!$mol_compare_deep(a[key], b[key]))
512
- return result = false;
513
- }
514
- catch (error) {
515
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
516
- }
517
- ++count;
518
- }
519
- for (let key in b) {
520
- --count;
521
- if (count < 0)
522
- return result = false;
523
- }
524
- if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
525
- if (!Object.is(a['valueOf'](), b['valueOf']()))
526
- return result = false;
527
- }
528
- return result = true;
443
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
444
+ result = compare_pojo(left, right);
445
+ else if (Array.isArray(left))
446
+ result = compare_array(left, right);
447
+ else if (left instanceof Set)
448
+ result = compare_set(left, right);
449
+ else if (left instanceof Map)
450
+ result = compare_map(left, right);
451
+ else if (ArrayBuffer.isView(left))
452
+ result = compare_buffer(left, right);
453
+ else
454
+ result = false;
529
455
  }
530
456
  finally {
531
- a_stack.pop();
532
- b_stack.pop();
533
- if (a_stack.length === 0) {
534
- cache = null;
535
- }
536
- else {
537
- a_cache.set(b, result);
538
- }
457
+ left_cache.set(right, result);
539
458
  }
459
+ return result;
540
460
  }
541
461
  $.$mol_compare_deep = $mol_compare_deep;
462
+ function compare_array(left, right) {
463
+ const len = left.length;
464
+ if (len !== right.length)
465
+ return false;
466
+ for (let i = 0; i < len; ++i) {
467
+ if (!$mol_compare_deep(left[i], right[i]))
468
+ return false;
469
+ }
470
+ return true;
471
+ }
472
+ function compare_buffer(left, right) {
473
+ const len = left.byteLength;
474
+ if (len !== right.byteLength)
475
+ return false;
476
+ for (let i = 0; i < len; ++i) {
477
+ if (left[i] !== right[i])
478
+ return false;
479
+ }
480
+ return true;
481
+ }
482
+ function compare_iterator(left, right, compare) {
483
+ while (true) {
484
+ const left_next = left.next();
485
+ const right_next = right.next();
486
+ if (left_next.done !== right_next.done)
487
+ return false;
488
+ if (left_next.done)
489
+ break;
490
+ if (!compare(left_next.value, right_next.value))
491
+ return false;
492
+ }
493
+ return true;
494
+ }
495
+ function compare_set(left, right) {
496
+ if (left.size !== right.size)
497
+ return false;
498
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
499
+ }
500
+ function compare_map(left, right) {
501
+ if (left.size !== right.size)
502
+ return false;
503
+ return compare_iterator(left.keys(), right.keys(), Object.is)
504
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
505
+ }
506
+ function compare_pojo(left, right) {
507
+ const left_keys = Object.getOwnPropertyNames(left);
508
+ const right_keys = Object.getOwnPropertyNames(right);
509
+ if (left_keys.length !== right_keys.length)
510
+ return false;
511
+ for (let key of left_keys) {
512
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
513
+ return false;
514
+ }
515
+ return true;
516
+ }
542
517
  })($ || ($ = {}));
543
518
  //deep.js.map
544
519
  ;
@@ -1335,7 +1310,8 @@ var $;
1335
1310
  }
1336
1311
  }
1337
1312
  const boxify = $.$mol_data_pipe((input) => input.toString(), Box);
1338
- $.$mol_assert_like(boxify(5), new Box('5'));
1313
+ $.$mol_assert_ok(boxify(5) instanceof Box);
1314
+ $.$mol_assert_like(boxify(5).value, '5');
1339
1315
  },
1340
1316
  });
1341
1317
  })($ || ($ = {}));