@etsoo/shared 1.2.76 → 1.2.79
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/.github/workflows/main.yml +3 -3
- package/README.md +0 -1
- package/__tests__/DataTypes.ts +190 -0
- package/__tests__/DomUtils.ts +3 -38
- package/__tests__/Utils.ts +3 -3
- package/lib/cjs/ArrayUtils.js +3 -6
- package/lib/cjs/DataTypes.d.ts +8 -0
- package/lib/cjs/DataTypes.js +58 -0
- package/lib/cjs/StorageUtils.js +3 -3
- package/lib/cjs/Utils.d.ts +4 -11
- package/lib/cjs/Utils.js +7 -34
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.js +3 -0
- package/lib/cjs/node/{Storage.d.ts → NodeStorage.d.ts} +1 -1
- package/lib/cjs/test/MockDOMRect.d.ts +15 -0
- package/lib/cjs/test/MockDOMRect.js +31 -0
- package/lib/cjs/test/MockResizeObserver.d.ts +12 -0
- package/lib/cjs/test/MockResizeObserver.js +27 -0
- package/lib/mjs/ArrayUtils.js +3 -3
- package/lib/mjs/DataTypes.d.ts +8 -0
- package/lib/mjs/DataTypes.js +58 -0
- package/lib/mjs/StorageUtils.js +1 -1
- package/lib/mjs/Utils.d.ts +4 -11
- package/lib/mjs/Utils.js +7 -31
- package/lib/mjs/index.d.ts +3 -0
- package/lib/mjs/index.js +3 -0
- package/lib/mjs/node/{Storage.d.ts → NodeStorage.d.ts} +1 -1
- package/lib/mjs/test/MockDOMRect.d.ts +15 -0
- package/lib/mjs/test/MockDOMRect.js +27 -0
- package/lib/mjs/test/MockResizeObserver.d.ts +12 -0
- package/lib/mjs/test/MockResizeObserver.js +23 -0
- package/package.json +6 -10
- package/src/ArrayUtils.ts +4 -4
- package/src/DataTypes.ts +64 -0
- package/src/StorageUtils.ts +1 -1
- package/src/Utils.ts +7 -31
- package/src/index.ts +5 -0
- package/src/node/{Storage.ts → NodeStorage.ts} +1 -1
- package/src/test/MockDOMRect.ts +37 -0
- package/src/test/MockResizeObserver.ts +28 -0
- /package/lib/cjs/node/{Storage.js → NodeStorage.js} +0 -0
- /package/lib/mjs/node/{Storage.js → NodeStorage.js} +0 -0
|
@@ -23,13 +23,13 @@ jobs:
|
|
|
23
23
|
steps:
|
|
24
24
|
# https://github.com/actions/checkout, This action checks-out your repository under $GITHUB_WORKSPACE
|
|
25
25
|
# so your workflow can access it.
|
|
26
|
-
- uses: actions/checkout@
|
|
26
|
+
- uses: actions/checkout@v5
|
|
27
27
|
|
|
28
28
|
# Set up your GitHub Actions workflow with a specific version of node.js
|
|
29
29
|
# Setup .npmrc file to publish to npm
|
|
30
|
-
- uses: actions/setup-node@
|
|
30
|
+
- uses: actions/setup-node@v6
|
|
31
31
|
with:
|
|
32
|
-
node-version: "latest
|
|
32
|
+
node-version: "24.11" # latest
|
|
33
33
|
registry-url: "https://registry.npmjs.org"
|
|
34
34
|
|
|
35
35
|
# Named after Continuous Integration, installs dependencies directly from package-lock.json
|
package/README.md
CHANGED
|
@@ -302,7 +302,6 @@ String and other related utilities
|
|
|
302
302
|
| charsToNumber | Base64 chars to number |
|
|
303
303
|
| containChinese | Check the input string contains Chinese character or not |
|
|
304
304
|
| correctTypes | Correct object's property value type |
|
|
305
|
-
| equals | Two values equal |
|
|
306
305
|
| exclude | Exclude specific items |
|
|
307
306
|
| excludeAsync | Async exclude specific items |
|
|
308
307
|
| formatInitial | Format inital character to lower case or upper case |
|
package/__tests__/DataTypes.ts
CHANGED
|
@@ -272,3 +272,193 @@ test("Tests for BasicTemplate", () => {
|
|
|
272
272
|
|
|
273
273
|
expect(data.id).toBe(1);
|
|
274
274
|
});
|
|
275
|
+
|
|
276
|
+
test("Tests for isDeepEqual - Primitive values", () => {
|
|
277
|
+
// Same values
|
|
278
|
+
expect(DataTypes.isDeepEqual(1, 1)).toBeTruthy();
|
|
279
|
+
expect(DataTypes.isDeepEqual("hello", "hello")).toBeTruthy();
|
|
280
|
+
expect(DataTypes.isDeepEqual(true, true)).toBeTruthy();
|
|
281
|
+
expect(DataTypes.isDeepEqual(false, false)).toBeTruthy();
|
|
282
|
+
|
|
283
|
+
// Different values
|
|
284
|
+
expect(DataTypes.isDeepEqual(1, 2)).toBeFalsy();
|
|
285
|
+
expect(DataTypes.isDeepEqual("hello", "world")).toBeFalsy();
|
|
286
|
+
expect(DataTypes.isDeepEqual(true, false)).toBeFalsy();
|
|
287
|
+
|
|
288
|
+
// Different types
|
|
289
|
+
expect(DataTypes.isDeepEqual(1, "1")).toBeFalsy();
|
|
290
|
+
expect(DataTypes.isDeepEqual(true, 1)).toBeFalsy();
|
|
291
|
+
expect(DataTypes.isDeepEqual(null, undefined)).toBeTruthy(); // Default strict=1
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("Tests for isDeepEqual - Null and undefined", () => {
|
|
295
|
+
// strict = undefined (default): null == undefined
|
|
296
|
+
expect(DataTypes.isDeepEqual(null, null)).toBeTruthy();
|
|
297
|
+
expect(DataTypes.isDeepEqual(undefined, undefined)).toBeTruthy();
|
|
298
|
+
expect(DataTypes.isDeepEqual(null, undefined)).toBeTruthy();
|
|
299
|
+
expect(DataTypes.isDeepEqual(undefined, null)).toBeTruthy();
|
|
300
|
+
|
|
301
|
+
// strict = 2: null !== undefined
|
|
302
|
+
expect(DataTypes.isDeepEqual(null, null, true)).toBeTruthy();
|
|
303
|
+
expect(DataTypes.isDeepEqual(undefined, undefined, true)).toBeTruthy();
|
|
304
|
+
expect(DataTypes.isDeepEqual(null, undefined, true)).toBeFalsy();
|
|
305
|
+
expect(DataTypes.isDeepEqual(undefined, null, true)).toBeFalsy();
|
|
306
|
+
|
|
307
|
+
// With non-null values
|
|
308
|
+
expect(DataTypes.isDeepEqual(null, 0)).toBeFalsy();
|
|
309
|
+
expect(DataTypes.isDeepEqual(undefined, "")).toBeFalsy();
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test("Tests for isDeepEqual - Loose equality (strict=0)", () => {
|
|
313
|
+
// Loose equal cases
|
|
314
|
+
expect(DataTypes.isDeepEqual(1, "1", false)).toBeTruthy();
|
|
315
|
+
expect(DataTypes.isDeepEqual(0, false, false)).toBeTruthy();
|
|
316
|
+
expect(DataTypes.isDeepEqual(1, true, false)).toBeTruthy();
|
|
317
|
+
expect(DataTypes.isDeepEqual("", false, false)).toBeTruthy();
|
|
318
|
+
expect(DataTypes.isDeepEqual(null, undefined, false)).toBeTruthy();
|
|
319
|
+
|
|
320
|
+
// Still not equal
|
|
321
|
+
expect(DataTypes.isDeepEqual(1, 2, false)).toBeFalsy();
|
|
322
|
+
expect(DataTypes.isDeepEqual("hello", "world", false)).toBeFalsy();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test("Tests for isDeepEqual - BigInt values", () => {
|
|
326
|
+
expect(DataTypes.isDeepEqual(123n, 123n)).toBeTruthy();
|
|
327
|
+
expect(DataTypes.isDeepEqual(123n, 456n)).toBeFalsy();
|
|
328
|
+
expect(DataTypes.isDeepEqual(123n, 123)).toBeFalsy();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("Tests for isDeepEqual - Date objects", () => {
|
|
332
|
+
const date1 = new Date("2023-01-01");
|
|
333
|
+
const date2 = new Date("2023-01-01");
|
|
334
|
+
const date3 = new Date("2023-01-02");
|
|
335
|
+
|
|
336
|
+
expect(DataTypes.isDeepEqual(date1, date1)).toBeTruthy();
|
|
337
|
+
expect(DataTypes.isDeepEqual(date1, date2)).toBeTruthy();
|
|
338
|
+
expect(DataTypes.isDeepEqual(date1, date3)).toBeFalsy();
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test("Tests for isDeepEqual - Arrays", () => {
|
|
342
|
+
const arr1 = [1, 2, 3];
|
|
343
|
+
expect(DataTypes.isDeepEqual(arr1, arr1)).toBeTruthy();
|
|
344
|
+
|
|
345
|
+
// Different references, same content
|
|
346
|
+
expect(DataTypes.isDeepEqual([1, 2, 3], [1, 2, 3])).toBeTruthy();
|
|
347
|
+
expect(DataTypes.isDeepEqual([], [])).toBeTruthy();
|
|
348
|
+
|
|
349
|
+
// Different content
|
|
350
|
+
expect(DataTypes.isDeepEqual([1, 2, 3], [1, 2, 4])).toBeFalsy();
|
|
351
|
+
expect(DataTypes.isDeepEqual([1, 2], [1, 2, 3])).toBeFalsy();
|
|
352
|
+
|
|
353
|
+
// Nested arrays
|
|
354
|
+
expect(
|
|
355
|
+
DataTypes.isDeepEqual(
|
|
356
|
+
[
|
|
357
|
+
[1, 2],
|
|
358
|
+
[3, 4]
|
|
359
|
+
],
|
|
360
|
+
[
|
|
361
|
+
[1, 2],
|
|
362
|
+
[3, 4]
|
|
363
|
+
]
|
|
364
|
+
)
|
|
365
|
+
).toBeTruthy();
|
|
366
|
+
expect(
|
|
367
|
+
DataTypes.isDeepEqual(
|
|
368
|
+
[
|
|
369
|
+
[1, 2],
|
|
370
|
+
[3, 4]
|
|
371
|
+
],
|
|
372
|
+
[
|
|
373
|
+
[1, 2],
|
|
374
|
+
[3, 5]
|
|
375
|
+
]
|
|
376
|
+
)
|
|
377
|
+
).toBeFalsy();
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test("Tests for isDeepEqual - Objects", () => {
|
|
381
|
+
// Same reference
|
|
382
|
+
const obj1 = { a: 1, b: 2 };
|
|
383
|
+
expect(DataTypes.isDeepEqual(obj1, obj1)).toBeTruthy();
|
|
384
|
+
|
|
385
|
+
// Different references, same content
|
|
386
|
+
expect(DataTypes.isDeepEqual({ a: 1, b: 2 }, { a: 1, b: 2 })).toBeTruthy();
|
|
387
|
+
expect(DataTypes.isDeepEqual({}, {})).toBeTruthy();
|
|
388
|
+
|
|
389
|
+
// Different content
|
|
390
|
+
expect(DataTypes.isDeepEqual({ a: 1, b: 2 }, { a: 1, b: 3 })).toBeFalsy();
|
|
391
|
+
expect(DataTypes.isDeepEqual({ a: 1 }, { a: 1, b: 2 })).toBeFalsy();
|
|
392
|
+
|
|
393
|
+
expect(
|
|
394
|
+
DataTypes.isDeepEqual({ a: 1, b: "2" }, { a: 1, b: 2 }, false)
|
|
395
|
+
).toBeTruthy();
|
|
396
|
+
expect(DataTypes.isDeepEqual({ a: 1 }, { a: 1, b: null })).toBeTruthy();
|
|
397
|
+
expect(
|
|
398
|
+
DataTypes.isDeepEqual({ a: 1, c: true }, { a: 1, b: null })
|
|
399
|
+
).toBeFalsy();
|
|
400
|
+
expect(DataTypes.isDeepEqual({ a: 1 }, { a: 1, b: null }, true)).toBeFalsy();
|
|
401
|
+
|
|
402
|
+
// Nested objects
|
|
403
|
+
expect(
|
|
404
|
+
DataTypes.isDeepEqual(
|
|
405
|
+
{ a: { x: 1, y: 2 }, b: 3 },
|
|
406
|
+
{ a: { x: 1, y: 2 }, b: 3 }
|
|
407
|
+
)
|
|
408
|
+
).toBeTruthy();
|
|
409
|
+
|
|
410
|
+
expect(
|
|
411
|
+
DataTypes.isDeepEqual(
|
|
412
|
+
{ a: { x: 1, y: 2 }, b: 3 },
|
|
413
|
+
{ a: { x: 1, y: 3 }, b: 3 }
|
|
414
|
+
)
|
|
415
|
+
).toBeFalsy();
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test("Tests for isDeepEqual - Mixed complex types", () => {
|
|
419
|
+
// Arrays with objects
|
|
420
|
+
expect(
|
|
421
|
+
DataTypes.isDeepEqual(
|
|
422
|
+
[
|
|
423
|
+
{ id: 1, name: "Alice" },
|
|
424
|
+
{ id: 2, name: "Bob" }
|
|
425
|
+
],
|
|
426
|
+
[
|
|
427
|
+
{ id: 1, name: "Alice" },
|
|
428
|
+
{ id: 2, name: "Bob" }
|
|
429
|
+
]
|
|
430
|
+
)
|
|
431
|
+
).toBeTruthy();
|
|
432
|
+
|
|
433
|
+
// Objects with arrays
|
|
434
|
+
expect(
|
|
435
|
+
DataTypes.isDeepEqual(
|
|
436
|
+
{ users: [1, 2, 3], active: true },
|
|
437
|
+
{ users: [1, 2, 3], active: true }
|
|
438
|
+
)
|
|
439
|
+
).toBeTruthy();
|
|
440
|
+
|
|
441
|
+
// Objects with different property order
|
|
442
|
+
expect(DataTypes.isDeepEqual({ a: 1, b: 2 }, { b: 2, a: 1 })).toBeTruthy();
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test("Tests for isDeepEqual - Edge cases", () => {
|
|
446
|
+
// Functions - should not be equal unless same reference
|
|
447
|
+
const func1 = () => {};
|
|
448
|
+
const func2 = () => {};
|
|
449
|
+
expect(DataTypes.isDeepEqual(func1, func1)).toBeTruthy();
|
|
450
|
+
expect(DataTypes.isDeepEqual(func1, func2)).toBeFalsy();
|
|
451
|
+
|
|
452
|
+
// NaN values
|
|
453
|
+
// NaN === NaN is false, but they should be considered equal
|
|
454
|
+
expect(DataTypes.isDeepEqual(NaN, NaN)).toBeTruthy();
|
|
455
|
+
|
|
456
|
+
// Infinity
|
|
457
|
+
expect(DataTypes.isDeepEqual(Infinity, Infinity)).toBeTruthy();
|
|
458
|
+
expect(DataTypes.isDeepEqual(-Infinity, -Infinity)).toBeTruthy();
|
|
459
|
+
expect(DataTypes.isDeepEqual(Infinity, -Infinity)).toBeFalsy();
|
|
460
|
+
|
|
461
|
+
// Zero variants
|
|
462
|
+
expect(DataTypes.isDeepEqual(0, -0)).toBeTruthy();
|
|
463
|
+
expect(DataTypes.isDeepEqual(+0, -0)).toBeTruthy();
|
|
464
|
+
});
|
package/__tests__/DomUtils.ts
CHANGED
|
@@ -1,44 +1,9 @@
|
|
|
1
1
|
import { DomUtils } from "../src/DomUtils";
|
|
2
2
|
import { DataTypes } from "../src/DataTypes";
|
|
3
3
|
import { DateUtils } from "../src/DateUtils";
|
|
4
|
+
import { MockDOMRect } from "../src/test/MockDOMRect";
|
|
4
5
|
import { ErrorData } from "../src/types/ErrorData";
|
|
5
6
|
|
|
6
|
-
// Implement for tests
|
|
7
|
-
class Rect implements DOMRect {
|
|
8
|
-
readonly bottom: number;
|
|
9
|
-
readonly height: number;
|
|
10
|
-
readonly left: number;
|
|
11
|
-
readonly right: number;
|
|
12
|
-
readonly top: number;
|
|
13
|
-
readonly width: number;
|
|
14
|
-
readonly x: number;
|
|
15
|
-
readonly y: number;
|
|
16
|
-
toJSON(): any {
|
|
17
|
-
return JSON.stringify({
|
|
18
|
-
bottom: this.bottom,
|
|
19
|
-
height: this.height,
|
|
20
|
-
left: this.left,
|
|
21
|
-
right: this.right,
|
|
22
|
-
top: this.top,
|
|
23
|
-
width: this.width,
|
|
24
|
-
x: this.x,
|
|
25
|
-
y: this.y
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
constructor(width: number, height: number, x: number = 0, y: number = 0) {
|
|
30
|
-
this.x = x;
|
|
31
|
-
this.y = y;
|
|
32
|
-
this.width = width;
|
|
33
|
-
this.height = height;
|
|
34
|
-
|
|
35
|
-
this.left = x;
|
|
36
|
-
this.top = y;
|
|
37
|
-
this.bottom = this.top + this.height;
|
|
38
|
-
this.right = this.left = this.width;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
7
|
describe("Tests for clearFormData", () => {
|
|
43
8
|
// Applies only to tests in this describe block
|
|
44
9
|
// Arrange
|
|
@@ -110,8 +75,8 @@ test("Tests for mergeFormData", () => {
|
|
|
110
75
|
});
|
|
111
76
|
|
|
112
77
|
test("Tests for dimensionEqual", () => {
|
|
113
|
-
const rect1: DOMRect = new
|
|
114
|
-
const rect2: DOMRect = new
|
|
78
|
+
const rect1: DOMRect = new MockDOMRect(200, 300);
|
|
79
|
+
const rect2: DOMRect = new MockDOMRect(100, 200);
|
|
115
80
|
expect(DomUtils.dimensionEqual(undefined, undefined)).toBeTruthy();
|
|
116
81
|
expect(DomUtils.dimensionEqual(rect1, undefined)).toBeFalsy();
|
|
117
82
|
expect(DomUtils.dimensionEqual(rect1, rect2)).toBeFalsy();
|
package/__tests__/Utils.ts
CHANGED
|
@@ -53,7 +53,7 @@ describe("Tests for addUrlParams", () => {
|
|
|
53
53
|
);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
globalThis.URL = undefined as any;
|
|
57
57
|
|
|
58
58
|
const result3 = url.addUrlParams(data);
|
|
59
59
|
|
|
@@ -275,9 +275,9 @@ test("Tests for objectEqual", () => {
|
|
|
275
275
|
const obj1 = { a: 1, b: "abc", c: true, d: null, f: [1, 2] };
|
|
276
276
|
const obj2 = { a: "1", b: "abc", c: true, f: [1, 2] };
|
|
277
277
|
expect(Utils.objectEqual(obj1, obj2)).toBeFalsy();
|
|
278
|
-
expect(Utils.objectEqual(obj1, obj2, [],
|
|
278
|
+
expect(Utils.objectEqual(obj1, obj2, [], false)).toBeTruthy();
|
|
279
279
|
expect(Utils.objectEqual(obj1, obj2, ["a"])).toBeTruthy();
|
|
280
|
-
expect(Utils.objectEqual(obj1, obj2, ["a"],
|
|
280
|
+
expect(Utils.objectEqual(obj1, obj2, ["a"], true)).toBeFalsy();
|
|
281
281
|
});
|
|
282
282
|
|
|
283
283
|
test("Tests for parseJsonArray", () => {
|
package/lib/cjs/ArrayUtils.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ArrayUtils = void 0;
|
|
7
|
-
const
|
|
4
|
+
const DataTypes_1 = require("./DataTypes");
|
|
8
5
|
Array.prototype.different = function (target, round) {
|
|
9
6
|
return ArrayUtils.differences(this, target, round);
|
|
10
7
|
};
|
|
@@ -19,7 +16,7 @@ Array.prototype.toggleItem = function (item, add, idField) {
|
|
|
19
16
|
return i[idField] === item;
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
return
|
|
19
|
+
return DataTypes_1.DataTypes.isDeepEqual(i, item);
|
|
23
20
|
});
|
|
24
21
|
if (add) {
|
|
25
22
|
if (index < 0) {
|
|
@@ -39,7 +36,7 @@ Array.prototype.toUnique = function () {
|
|
|
39
36
|
return Array.from(new Set(this));
|
|
40
37
|
const newArray = [];
|
|
41
38
|
this.forEach((item) => {
|
|
42
|
-
if (newArray.some((newItem) =>
|
|
39
|
+
if (newArray.some((newItem) => DataTypes_1.DataTypes.isDeepEqual(item, newItem)))
|
|
43
40
|
return;
|
|
44
41
|
newArray.push(item);
|
|
45
42
|
});
|
package/lib/cjs/DataTypes.d.ts
CHANGED
|
@@ -399,6 +399,14 @@ export declare namespace DataTypes {
|
|
|
399
399
|
* @returns Is basic type
|
|
400
400
|
*/
|
|
401
401
|
function isBasicName(name: string): name is BasicNames;
|
|
402
|
+
/**
|
|
403
|
+
* Check deep equality
|
|
404
|
+
* @param a Input a
|
|
405
|
+
* @param b Input b
|
|
406
|
+
* @param isStrict Strict or not, false: loose equal, undefined === but null equal undefined, NaN equal NaN, true: strict equal
|
|
407
|
+
* @returns Result
|
|
408
|
+
*/
|
|
409
|
+
function isDeepEqual(a: unknown, b: unknown, isStrict?: boolean): boolean;
|
|
402
410
|
/**
|
|
403
411
|
* Is the target a simple object (Type guard)
|
|
404
412
|
* @param input Test data
|
package/lib/cjs/DataTypes.js
CHANGED
|
@@ -455,6 +455,64 @@ var DataTypes;
|
|
|
455
455
|
return DataTypes.BasicArray.includes(name);
|
|
456
456
|
}
|
|
457
457
|
DataTypes.isBasicName = isBasicName;
|
|
458
|
+
/**
|
|
459
|
+
* Check deep equality
|
|
460
|
+
* @param a Input a
|
|
461
|
+
* @param b Input b
|
|
462
|
+
* @param isStrict Strict or not, false: loose equal, undefined === but null equal undefined, NaN equal NaN, true: strict equal
|
|
463
|
+
* @returns Result
|
|
464
|
+
*/
|
|
465
|
+
function isDeepEqual(a, b, isStrict) {
|
|
466
|
+
// Same object or value
|
|
467
|
+
if (a === b)
|
|
468
|
+
return true;
|
|
469
|
+
// Null and undefined case
|
|
470
|
+
if (a == null || b == null) {
|
|
471
|
+
if (!isStrict && a == b)
|
|
472
|
+
return true;
|
|
473
|
+
return a === b;
|
|
474
|
+
}
|
|
475
|
+
else if (isStrict === false) {
|
|
476
|
+
// Loose equal case
|
|
477
|
+
if (a == b)
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
// Different type
|
|
481
|
+
if (typeof a !== typeof b)
|
|
482
|
+
return false;
|
|
483
|
+
// NaN case
|
|
484
|
+
if (Number.isNaN(a) && Number.isNaN(b) && !isStrict)
|
|
485
|
+
return true;
|
|
486
|
+
if (typeof a === "object") {
|
|
487
|
+
// Date
|
|
488
|
+
if (a instanceof Date && b instanceof Date) {
|
|
489
|
+
return a.getTime() === b.getTime();
|
|
490
|
+
}
|
|
491
|
+
// Array
|
|
492
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
493
|
+
if (a.length !== b.length)
|
|
494
|
+
return false;
|
|
495
|
+
for (let i = 0; i < a.length; i++) {
|
|
496
|
+
if (!isDeepEqual(a[i], b[i], isStrict))
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
// Loop object keys
|
|
502
|
+
const aKeys = Object.keys(a);
|
|
503
|
+
const bKeys = Object.keys(b);
|
|
504
|
+
if (aKeys.length !== bKeys.length && isStrict)
|
|
505
|
+
return false;
|
|
506
|
+
const allKeys = new Set([...aKeys, ...bKeys]);
|
|
507
|
+
for (const key of allKeys) {
|
|
508
|
+
if (!isDeepEqual(Reflect.get(a, key), Reflect.get(b, key), isStrict))
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
return isStrict ? a === b : a == b;
|
|
514
|
+
}
|
|
515
|
+
DataTypes.isDeepEqual = isDeepEqual;
|
|
458
516
|
/**
|
|
459
517
|
* Is the target a simple object (Type guard)
|
|
460
518
|
* @param input Test data
|
package/lib/cjs/StorageUtils.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StorageUtils = void 0;
|
|
4
|
-
const
|
|
4
|
+
const NodeStorage_1 = require("./node/NodeStorage");
|
|
5
5
|
const Utils_1 = require("./Utils");
|
|
6
6
|
// Mock node
|
|
7
|
-
globalThis.localStorage ?? (globalThis.localStorage = new
|
|
8
|
-
globalThis.sessionStorage ?? (globalThis.sessionStorage = new
|
|
7
|
+
globalThis.localStorage ?? (globalThis.localStorage = new NodeStorage_1.NodeStorage());
|
|
8
|
+
globalThis.sessionStorage ?? (globalThis.sessionStorage = new NodeStorage_1.NodeStorage());
|
|
9
9
|
/**
|
|
10
10
|
* Storage utilities
|
|
11
11
|
* NodeStorage needs data persistance
|
package/lib/cjs/Utils.d.ts
CHANGED
|
@@ -112,13 +112,6 @@ export declare namespace Utils {
|
|
|
112
112
|
export function correctTypes<T extends object, F extends {
|
|
113
113
|
[P in keyof T]?: DataTypes.BasicNames;
|
|
114
114
|
}>(input: T, fields: F): void;
|
|
115
|
-
/**
|
|
116
|
-
* Two values equal
|
|
117
|
-
* @param v1 Value 1
|
|
118
|
-
* @param v2 Value 2
|
|
119
|
-
* @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
|
|
120
|
-
*/
|
|
121
|
-
export function equals(v1: unknown, v2: unknown, strict?: number): boolean;
|
|
122
115
|
/**
|
|
123
116
|
* Exclude specific items
|
|
124
117
|
* @param items Items
|
|
@@ -231,10 +224,10 @@ export declare namespace Utils {
|
|
|
231
224
|
* @param obj1 Object 1
|
|
232
225
|
* @param obj2 Object 2
|
|
233
226
|
* @param ignoreFields Ignored fields
|
|
234
|
-
* @param
|
|
227
|
+
* @param isStrict Strict or not, false: loose equal, undefined === but null equal undefined, NaN equal NaN, true: strict equal
|
|
235
228
|
* @returns Result
|
|
236
229
|
*/
|
|
237
|
-
export function objectEqual(obj1: object, obj2: object, ignoreFields?: string[],
|
|
230
|
+
export function objectEqual(obj1: object, obj2: object, ignoreFields?: string[], isStrict?: boolean): boolean;
|
|
238
231
|
/**
|
|
239
232
|
* Get two object's unqiue properties
|
|
240
233
|
* @param obj1 Object 1
|
|
@@ -248,10 +241,10 @@ export declare namespace Utils {
|
|
|
248
241
|
* @param objNew New object
|
|
249
242
|
* @param objPre Previous object
|
|
250
243
|
* @param ignoreFields Ignored fields
|
|
251
|
-
* @param
|
|
244
|
+
* @param isStrict Strict or not, false: loose equal, undefined === but null equal undefined, NaN equal NaN, true: strict equal
|
|
252
245
|
* @returns Updated fields
|
|
253
246
|
*/
|
|
254
|
-
export function objectUpdated(objNew: object, objPrev: object, ignoreFields?: string[],
|
|
247
|
+
export function objectUpdated(objNew: object, objPrev: object, ignoreFields?: string[], isStrict?: boolean): string[];
|
|
255
248
|
/**
|
|
256
249
|
* Try to parse JSON input to array
|
|
257
250
|
* @param input JSON input
|
package/lib/cjs/Utils.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Utils = void 0;
|
|
7
4
|
const DataTypes_1 = require("./DataTypes");
|
|
8
|
-
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
9
5
|
const DateUtils_1 = require("./DateUtils");
|
|
10
6
|
String.prototype.addUrlParam = function (name, value, arrayFormat) {
|
|
11
7
|
return this.addUrlParams({ [name]: value }, arrayFormat);
|
|
@@ -186,29 +182,6 @@ var Utils;
|
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
184
|
Utils.correctTypes = correctTypes;
|
|
189
|
-
/**
|
|
190
|
-
* Two values equal
|
|
191
|
-
* @param v1 Value 1
|
|
192
|
-
* @param v2 Value 2
|
|
193
|
-
* @param strict Strict level, 0 with ==, 1 === but null equal undefined, 2 ===
|
|
194
|
-
*/
|
|
195
|
-
function equals(v1, v2, strict = 1) {
|
|
196
|
-
// Null and undefined case
|
|
197
|
-
if (v1 == null || v2 == null) {
|
|
198
|
-
if (strict <= 1 && v1 == v2)
|
|
199
|
-
return true;
|
|
200
|
-
return v1 === v2;
|
|
201
|
-
}
|
|
202
|
-
// For date, array and object
|
|
203
|
-
if (typeof v1 === "object")
|
|
204
|
-
return (0, lodash_isequal_1.default)(v1, v2);
|
|
205
|
-
// 1 and '1' case
|
|
206
|
-
if (strict === 0)
|
|
207
|
-
return v1 == v2;
|
|
208
|
-
// Strict equal
|
|
209
|
-
return v1 === v2;
|
|
210
|
-
}
|
|
211
|
-
Utils.equals = equals;
|
|
212
185
|
/**
|
|
213
186
|
* Exclude specific items
|
|
214
187
|
* @param items Items
|
|
@@ -287,7 +260,7 @@ var Utils;
|
|
|
287
260
|
return;
|
|
288
261
|
}
|
|
289
262
|
const newValue = DataTypes_1.DataTypes.convert(value, initValue);
|
|
290
|
-
if (
|
|
263
|
+
if (DataTypes_1.DataTypes.isDeepEqual(newValue, initValue)) {
|
|
291
264
|
Reflect.deleteProperty(input, key);
|
|
292
265
|
return;
|
|
293
266
|
}
|
|
@@ -452,17 +425,17 @@ var Utils;
|
|
|
452
425
|
* @param obj1 Object 1
|
|
453
426
|
* @param obj2 Object 2
|
|
454
427
|
* @param ignoreFields Ignored fields
|
|
455
|
-
* @param
|
|
428
|
+
* @param isStrict Strict or not, false: loose equal, undefined === but null equal undefined, NaN equal NaN, true: strict equal
|
|
456
429
|
* @returns Result
|
|
457
430
|
*/
|
|
458
|
-
function objectEqual(obj1, obj2, ignoreFields = [],
|
|
431
|
+
function objectEqual(obj1, obj2, ignoreFields = [], isStrict) {
|
|
459
432
|
// Unique keys
|
|
460
433
|
const keys = Utils.objectKeys(obj1, obj2, ignoreFields);
|
|
461
434
|
for (const key of keys) {
|
|
462
435
|
// Values
|
|
463
436
|
const v1 = Reflect.get(obj1, key);
|
|
464
437
|
const v2 = Reflect.get(obj2, key);
|
|
465
|
-
if (!
|
|
438
|
+
if (!DataTypes_1.DataTypes.isDeepEqual(v1, v2, isStrict))
|
|
466
439
|
return false;
|
|
467
440
|
}
|
|
468
441
|
return true;
|
|
@@ -487,10 +460,10 @@ var Utils;
|
|
|
487
460
|
* @param objNew New object
|
|
488
461
|
* @param objPre Previous object
|
|
489
462
|
* @param ignoreFields Ignored fields
|
|
490
|
-
* @param
|
|
463
|
+
* @param isStrict Strict or not, false: loose equal, undefined === but null equal undefined, NaN equal NaN, true: strict equal
|
|
491
464
|
* @returns Updated fields
|
|
492
465
|
*/
|
|
493
|
-
function objectUpdated(objNew, objPrev, ignoreFields = [],
|
|
466
|
+
function objectUpdated(objNew, objPrev, ignoreFields = [], isStrict) {
|
|
494
467
|
// Fields
|
|
495
468
|
const fields = [];
|
|
496
469
|
// Unique keys
|
|
@@ -499,7 +472,7 @@ var Utils;
|
|
|
499
472
|
// Values
|
|
500
473
|
const vNew = Reflect.get(objNew, key);
|
|
501
474
|
const vPrev = Reflect.get(objPrev, key);
|
|
502
|
-
if (!
|
|
475
|
+
if (!DataTypes_1.DataTypes.isDeepEqual(vNew, vPrev, isStrict)) {
|
|
503
476
|
fields.push(key);
|
|
504
477
|
}
|
|
505
478
|
}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -6,8 +6,11 @@ export * from "./types/EHistory";
|
|
|
6
6
|
export * from "./types/ErrorData";
|
|
7
7
|
export * from "./types/EventClass";
|
|
8
8
|
export * from "./types/FormData";
|
|
9
|
+
export * from "./node/NodeStorage";
|
|
9
10
|
export * from "./storage/IStorage";
|
|
10
11
|
export * from "./storage/WindowStorage";
|
|
12
|
+
export * from "./test/MockDOMRect";
|
|
13
|
+
export * from "./test/MockResizeObserver";
|
|
11
14
|
export * from "./ActionResult";
|
|
12
15
|
export * from "./ArrayUtils";
|
|
13
16
|
export * from "./DataTypes";
|
package/lib/cjs/index.js
CHANGED
|
@@ -22,8 +22,11 @@ __exportStar(require("./types/EHistory"), exports);
|
|
|
22
22
|
__exportStar(require("./types/ErrorData"), exports);
|
|
23
23
|
__exportStar(require("./types/EventClass"), exports);
|
|
24
24
|
__exportStar(require("./types/FormData"), exports);
|
|
25
|
+
__exportStar(require("./node/NodeStorage"), exports);
|
|
25
26
|
__exportStar(require("./storage/IStorage"), exports);
|
|
26
27
|
__exportStar(require("./storage/WindowStorage"), exports);
|
|
28
|
+
__exportStar(require("./test/MockDOMRect"), exports);
|
|
29
|
+
__exportStar(require("./test/MockResizeObserver"), exports);
|
|
27
30
|
__exportStar(require("./ActionResult"), exports);
|
|
28
31
|
__exportStar(require("./ArrayUtils"), exports);
|
|
29
32
|
__exportStar(require("./DataTypes"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mock implementation of DOMRect for testing purposes
|
|
3
|
+
*/
|
|
4
|
+
export declare class MockDOMRect implements DOMRect {
|
|
5
|
+
readonly bottom: number;
|
|
6
|
+
readonly height: number;
|
|
7
|
+
readonly left: number;
|
|
8
|
+
readonly right: number;
|
|
9
|
+
readonly top: number;
|
|
10
|
+
readonly width: number;
|
|
11
|
+
readonly x: number;
|
|
12
|
+
readonly y: number;
|
|
13
|
+
toJSON(): any;
|
|
14
|
+
constructor(width: number, height: number, x?: number, y?: number);
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MockDOMRect = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A mock implementation of DOMRect for testing purposes
|
|
6
|
+
*/
|
|
7
|
+
class MockDOMRect {
|
|
8
|
+
toJSON() {
|
|
9
|
+
return JSON.stringify({
|
|
10
|
+
bottom: this.bottom,
|
|
11
|
+
height: this.height,
|
|
12
|
+
left: this.left,
|
|
13
|
+
right: this.right,
|
|
14
|
+
top: this.top,
|
|
15
|
+
width: this.width,
|
|
16
|
+
x: this.x,
|
|
17
|
+
y: this.y
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
constructor(width, height, x = 0, y = 0) {
|
|
21
|
+
this.x = x;
|
|
22
|
+
this.y = y;
|
|
23
|
+
this.width = width;
|
|
24
|
+
this.height = height;
|
|
25
|
+
this.left = x;
|
|
26
|
+
this.top = y;
|
|
27
|
+
this.bottom = this.top + this.height;
|
|
28
|
+
this.right = this.left = this.width;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.MockDOMRect = MockDOMRect;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock implementation of ResizeObserver for testing purposes
|
|
3
|
+
*/
|
|
4
|
+
export declare class MockResizeObserver implements ResizeObserver {
|
|
5
|
+
callbacks: Function[];
|
|
6
|
+
elements: Element[];
|
|
7
|
+
constructor(callback: Function);
|
|
8
|
+
observe(element: Element): void;
|
|
9
|
+
unobserve(element: Element): void;
|
|
10
|
+
disconnect(): void;
|
|
11
|
+
trigger(entries: ResizeObserverEntry[]): void;
|
|
12
|
+
}
|