@tanstack/pacer 0.8.0 → 0.9.1
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/dist/cjs/async-batcher.cjs +163 -0
- package/dist/cjs/async-batcher.cjs.map +1 -0
- package/dist/cjs/async-batcher.d.cts +273 -0
- package/dist/cjs/async-debouncer.cjs +149 -162
- package/dist/cjs/async-debouncer.cjs.map +1 -1
- package/dist/cjs/async-debouncer.d.cts +76 -57
- package/dist/cjs/async-queuer.cjs +282 -343
- package/dist/cjs/async-queuer.cjs.map +1 -1
- package/dist/cjs/async-queuer.d.cts +121 -100
- package/dist/cjs/async-rate-limiter.cjs +128 -185
- package/dist/cjs/async-rate-limiter.cjs.map +1 -1
- package/dist/cjs/async-rate-limiter.d.cts +72 -61
- package/dist/cjs/async-throttler.cjs +168 -178
- package/dist/cjs/async-throttler.cjs.map +1 -1
- package/dist/cjs/async-throttler.d.cts +97 -69
- package/dist/cjs/batcher.cjs +110 -119
- package/dist/cjs/batcher.cjs.map +1 -1
- package/dist/cjs/batcher.d.cts +76 -51
- package/dist/cjs/debouncer.cjs +97 -85
- package/dist/cjs/debouncer.cjs.map +1 -1
- package/dist/cjs/debouncer.d.cts +54 -26
- package/dist/cjs/index.cjs +3 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/queuer.cjs +247 -294
- package/dist/cjs/queuer.cjs.map +1 -1
- package/dist/cjs/queuer.d.cts +102 -81
- package/dist/cjs/rate-limiter.cjs +97 -130
- package/dist/cjs/rate-limiter.cjs.map +1 -1
- package/dist/cjs/rate-limiter.d.cts +50 -37
- package/dist/cjs/throttler.cjs +107 -123
- package/dist/cjs/throttler.cjs.map +1 -1
- package/dist/cjs/throttler.d.cts +59 -35
- package/dist/cjs/utils.cjs +0 -13
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +0 -1
- package/dist/esm/async-batcher.d.ts +273 -0
- package/dist/esm/async-batcher.js +163 -0
- package/dist/esm/async-batcher.js.map +1 -0
- package/dist/esm/async-debouncer.d.ts +76 -57
- package/dist/esm/async-debouncer.js +149 -162
- package/dist/esm/async-debouncer.js.map +1 -1
- package/dist/esm/async-queuer.d.ts +121 -100
- package/dist/esm/async-queuer.js +282 -343
- package/dist/esm/async-queuer.js.map +1 -1
- package/dist/esm/async-rate-limiter.d.ts +72 -61
- package/dist/esm/async-rate-limiter.js +128 -185
- package/dist/esm/async-rate-limiter.js.map +1 -1
- package/dist/esm/async-throttler.d.ts +97 -69
- package/dist/esm/async-throttler.js +168 -178
- package/dist/esm/async-throttler.js.map +1 -1
- package/dist/esm/batcher.d.ts +76 -51
- package/dist/esm/batcher.js +110 -119
- package/dist/esm/batcher.js.map +1 -1
- package/dist/esm/debouncer.d.ts +54 -26
- package/dist/esm/debouncer.js +97 -85
- package/dist/esm/debouncer.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -7
- package/dist/esm/queuer.d.ts +102 -81
- package/dist/esm/queuer.js +247 -294
- package/dist/esm/queuer.js.map +1 -1
- package/dist/esm/rate-limiter.d.ts +50 -37
- package/dist/esm/rate-limiter.js +97 -130
- package/dist/esm/rate-limiter.js.map +1 -1
- package/dist/esm/throttler.d.ts +59 -35
- package/dist/esm/throttler.js +107 -123
- package/dist/esm/throttler.js.map +1 -1
- package/dist/esm/utils.d.ts +0 -1
- package/dist/esm/utils.js +0 -13
- package/dist/esm/utils.js.map +1 -1
- package/package.json +14 -11
- package/src/async-batcher.ts +475 -0
- package/src/async-debouncer.ts +201 -121
- package/src/async-queuer.ts +337 -216
- package/src/async-rate-limiter.ts +176 -136
- package/src/async-throttler.ts +233 -139
- package/src/batcher.ts +158 -92
- package/src/debouncer.ts +135 -52
- package/src/index.ts +1 -1
- package/src/queuer.ts +349 -226
- package/src/rate-limiter.ts +125 -80
- package/src/throttler.ts +152 -78
- package/src/utils.ts +0 -15
- package/dist/cjs/compare.cjs +0 -72
- package/dist/cjs/compare.cjs.map +0 -1
- package/dist/cjs/compare.d.cts +0 -12
- package/dist/esm/compare.d.ts +0 -12
- package/dist/esm/compare.js +0 -72
- package/dist/esm/compare.js.map +0 -1
- package/src/compare.ts +0 -105
package/dist/cjs/compare.cjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function replaceEqualDeep(a, b) {
|
|
4
|
-
if (a === b) {
|
|
5
|
-
return a;
|
|
6
|
-
}
|
|
7
|
-
const array = isPlainArray(a) && isPlainArray(b);
|
|
8
|
-
if (array || isPlainObject(a) && isPlainObject(b)) {
|
|
9
|
-
const aItems = array ? a : Object.keys(a);
|
|
10
|
-
const aSize = aItems.length;
|
|
11
|
-
const bItems = array ? b : Object.keys(b);
|
|
12
|
-
const bSize = bItems.length;
|
|
13
|
-
const copy = array ? [] : {};
|
|
14
|
-
let equalItems = 0;
|
|
15
|
-
for (let i = 0; i < bSize; i++) {
|
|
16
|
-
const key = array ? i : bItems[i];
|
|
17
|
-
if ((!array && aItems.includes(key) || array) && a[key] === void 0 && b[key] === void 0) {
|
|
18
|
-
copy[key] = void 0;
|
|
19
|
-
equalItems++;
|
|
20
|
-
} else {
|
|
21
|
-
copy[key] = replaceEqualDeep(a[key], b[key]);
|
|
22
|
-
if (copy[key] === a[key] && a[key] !== void 0) {
|
|
23
|
-
equalItems++;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
28
|
-
}
|
|
29
|
-
return b;
|
|
30
|
-
}
|
|
31
|
-
function shallowEqualObjects(a, b) {
|
|
32
|
-
if (!b || Object.keys(a).length !== Object.keys(b).length) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
for (const key in a) {
|
|
36
|
-
if (a[key] !== b[key]) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
function isPlainArray(value) {
|
|
43
|
-
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
44
|
-
}
|
|
45
|
-
function isPlainObject(o) {
|
|
46
|
-
if (!hasObjectPrototype(o)) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
const ctor = o.constructor;
|
|
50
|
-
if (ctor === void 0) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
const prot = ctor.prototype;
|
|
54
|
-
if (!hasObjectPrototype(prot)) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
if (Object.getPrototypeOf(o) !== Object.prototype) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
function hasObjectPrototype(o) {
|
|
66
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
67
|
-
}
|
|
68
|
-
exports.isPlainArray = isPlainArray;
|
|
69
|
-
exports.isPlainObject = isPlainObject;
|
|
70
|
-
exports.replaceEqualDeep = replaceEqualDeep;
|
|
71
|
-
exports.shallowEqualObjects = shallowEqualObjects;
|
|
72
|
-
//# sourceMappingURL=compare.cjs.map
|
package/dist/cjs/compare.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compare.cjs","sources":["../../src/compare.ts"],"sourcesContent":["/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T): T\nexport function replaceEqualDeep(a: any, b: any): any {\n if (a === b) {\n return a\n }\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (array || (isPlainObject(a) && isPlainObject(b))) {\n const aItems = array ? a : Object.keys(a)\n const aSize = aItems.length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = array ? i : bItems[i]\n if (\n ((!array && aItems.includes(key)) || array) &&\n a[key] === undefined &&\n b[key] === undefined\n ) {\n copy[key] = undefined\n equalItems++\n } else {\n copy[key] = replaceEqualDeep(a[key], b[key])\n if (copy[key] === a[key] && a[key] !== undefined) {\n equalItems++\n }\n }\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n }\n\n return b\n}\n\n/**\n * Shallow compare objects.\n */\nexport function shallowEqualObjects<T extends Record<string, any>>(\n a: T,\n b: T | undefined,\n): boolean {\n if (!b || Object.keys(a).length !== Object.keys(b).length) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nexport function isPlainObject(o: any): o is Object {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has no constructor\n const ctor = o.constructor\n if (ctor === undefined) {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Handles Objects created by Object.create(<arbitrary prototype>)\n if (Object.getPrototypeOf(o) !== Object.prototype) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n"],"names":[],"mappings":";;AAMgB,SAAA,iBAAiB,GAAQ,GAAa;AACpD,MAAI,MAAM,GAAG;AACJ,WAAA;AAAA,EAAA;AAGT,QAAM,QAAQ,aAAa,CAAC,KAAK,aAAa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AAE;AACf,MAAI,SAAS,QAAW;AACf,WAAA;AAAA,EAAA;AAIT,QAAM,OAAO,KAAK;AACd,MAAA,CAAC,mBAAmB,IAAI,GAAG;AACtB,WAAA;AAAA,EAAA;AAIT,MAAI,CAAC,KAAK,eAAe,eAAe,GAAG;AAClC,WAAA;AAAA,EAAA;AAIT,MAAI,OAAO,eAAe,CAAC,MAAM,OAAO,WAAW;AAC1C,WAAA;AAAA,EAAA;AAIF,SAAA;AACT;AAEA,SAAS,mBAAmB,GAAiB;AAC3C,SAAO,OAAO,UAAU,SAAS,KAAK,CAAC,MAAM;AAC/C;;;;;"}
|
package/dist/cjs/compare.d.cts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This function returns `a` if `b` is deeply equal.
|
|
3
|
-
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
4
|
-
* This can be used for structural sharing between JSON values for example.
|
|
5
|
-
*/
|
|
6
|
-
export declare function replaceEqualDeep<T>(a: unknown, b: T): T;
|
|
7
|
-
/**
|
|
8
|
-
* Shallow compare objects.
|
|
9
|
-
*/
|
|
10
|
-
export declare function shallowEqualObjects<T extends Record<string, any>>(a: T, b: T | undefined): boolean;
|
|
11
|
-
export declare function isPlainArray(value: unknown): boolean;
|
|
12
|
-
export declare function isPlainObject(o: any): o is Object;
|
package/dist/esm/compare.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This function returns `a` if `b` is deeply equal.
|
|
3
|
-
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
4
|
-
* This can be used for structural sharing between JSON values for example.
|
|
5
|
-
*/
|
|
6
|
-
export declare function replaceEqualDeep<T>(a: unknown, b: T): T;
|
|
7
|
-
/**
|
|
8
|
-
* Shallow compare objects.
|
|
9
|
-
*/
|
|
10
|
-
export declare function shallowEqualObjects<T extends Record<string, any>>(a: T, b: T | undefined): boolean;
|
|
11
|
-
export declare function isPlainArray(value: unknown): boolean;
|
|
12
|
-
export declare function isPlainObject(o: any): o is Object;
|
package/dist/esm/compare.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
function replaceEqualDeep(a, b) {
|
|
2
|
-
if (a === b) {
|
|
3
|
-
return a;
|
|
4
|
-
}
|
|
5
|
-
const array = isPlainArray(a) && isPlainArray(b);
|
|
6
|
-
if (array || isPlainObject(a) && isPlainObject(b)) {
|
|
7
|
-
const aItems = array ? a : Object.keys(a);
|
|
8
|
-
const aSize = aItems.length;
|
|
9
|
-
const bItems = array ? b : Object.keys(b);
|
|
10
|
-
const bSize = bItems.length;
|
|
11
|
-
const copy = array ? [] : {};
|
|
12
|
-
let equalItems = 0;
|
|
13
|
-
for (let i = 0; i < bSize; i++) {
|
|
14
|
-
const key = array ? i : bItems[i];
|
|
15
|
-
if ((!array && aItems.includes(key) || array) && a[key] === void 0 && b[key] === void 0) {
|
|
16
|
-
copy[key] = void 0;
|
|
17
|
-
equalItems++;
|
|
18
|
-
} else {
|
|
19
|
-
copy[key] = replaceEqualDeep(a[key], b[key]);
|
|
20
|
-
if (copy[key] === a[key] && a[key] !== void 0) {
|
|
21
|
-
equalItems++;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
26
|
-
}
|
|
27
|
-
return b;
|
|
28
|
-
}
|
|
29
|
-
function shallowEqualObjects(a, b) {
|
|
30
|
-
if (!b || Object.keys(a).length !== Object.keys(b).length) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
for (const key in a) {
|
|
34
|
-
if (a[key] !== b[key]) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
function isPlainArray(value) {
|
|
41
|
-
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
42
|
-
}
|
|
43
|
-
function isPlainObject(o) {
|
|
44
|
-
if (!hasObjectPrototype(o)) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
const ctor = o.constructor;
|
|
48
|
-
if (ctor === void 0) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
const prot = ctor.prototype;
|
|
52
|
-
if (!hasObjectPrototype(prot)) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
if (Object.getPrototypeOf(o) !== Object.prototype) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
function hasObjectPrototype(o) {
|
|
64
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
65
|
-
}
|
|
66
|
-
export {
|
|
67
|
-
isPlainArray,
|
|
68
|
-
isPlainObject,
|
|
69
|
-
replaceEqualDeep,
|
|
70
|
-
shallowEqualObjects
|
|
71
|
-
};
|
|
72
|
-
//# sourceMappingURL=compare.js.map
|
package/dist/esm/compare.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compare.js","sources":["../../src/compare.ts"],"sourcesContent":["/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T): T\nexport function replaceEqualDeep(a: any, b: any): any {\n if (a === b) {\n return a\n }\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (array || (isPlainObject(a) && isPlainObject(b))) {\n const aItems = array ? a : Object.keys(a)\n const aSize = aItems.length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = array ? i : bItems[i]\n if (\n ((!array && aItems.includes(key)) || array) &&\n a[key] === undefined &&\n b[key] === undefined\n ) {\n copy[key] = undefined\n equalItems++\n } else {\n copy[key] = replaceEqualDeep(a[key], b[key])\n if (copy[key] === a[key] && a[key] !== undefined) {\n equalItems++\n }\n }\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n }\n\n return b\n}\n\n/**\n * Shallow compare objects.\n */\nexport function shallowEqualObjects<T extends Record<string, any>>(\n a: T,\n b: T | undefined,\n): boolean {\n if (!b || Object.keys(a).length !== Object.keys(b).length) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nexport function isPlainObject(o: any): o is Object {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has no constructor\n const ctor = o.constructor\n if (ctor === undefined) {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Handles Objects created by Object.create(<arbitrary prototype>)\n if (Object.getPrototypeOf(o) !== Object.prototype) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n"],"names":[],"mappings":"AAMgB,SAAA,iBAAiB,GAAQ,GAAa;AACpD,MAAI,MAAM,GAAG;AACJ,WAAA;AAAA,EAAA;AAGT,QAAM,QAAQ,aAAa,CAAC,KAAK,aAAa,CAAC;AAE/C,MAAI,SAAU,cAAc,CAAC,KAAK,cAAc,CAAC,GAAI;AACnD,UAAM,SAAS,QAAQ,IAAI,OAAO,KAAK,CAAC;AACxC,UAAM,QAAQ,OAAO;AACrB,UAAM,SAAS,QAAQ,IAAI,OAAO,KAAK,CAAC;AACxC,UAAM,QAAQ,OAAO;AACrB,UAAM,OAAY,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C,MAAM,OAAO,WAAW;AAC1C,WAAA;AAAA,EAAA;AAIF,SAAA;AACT;AAEA,SAAS,mBAAmB,GAAiB;AAC3C,SAAO,OAAO,UAAU,SAAS,KAAK,CAAC,MAAM;AAC/C;"}
|
package/src/compare.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This function returns `a` if `b` is deeply equal.
|
|
3
|
-
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
4
|
-
* This can be used for structural sharing between JSON values for example.
|
|
5
|
-
*/
|
|
6
|
-
export function replaceEqualDeep<T>(a: unknown, b: T): T
|
|
7
|
-
export function replaceEqualDeep(a: any, b: any): any {
|
|
8
|
-
if (a === b) {
|
|
9
|
-
return a
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const array = isPlainArray(a) && isPlainArray(b)
|
|
13
|
-
|
|
14
|
-
if (array || (isPlainObject(a) && isPlainObject(b))) {
|
|
15
|
-
const aItems = array ? a : Object.keys(a)
|
|
16
|
-
const aSize = aItems.length
|
|
17
|
-
const bItems = array ? b : Object.keys(b)
|
|
18
|
-
const bSize = bItems.length
|
|
19
|
-
const copy: any = array ? [] : {}
|
|
20
|
-
|
|
21
|
-
let equalItems = 0
|
|
22
|
-
|
|
23
|
-
for (let i = 0; i < bSize; i++) {
|
|
24
|
-
const key = array ? i : bItems[i]
|
|
25
|
-
if (
|
|
26
|
-
((!array && aItems.includes(key)) || array) &&
|
|
27
|
-
a[key] === undefined &&
|
|
28
|
-
b[key] === undefined
|
|
29
|
-
) {
|
|
30
|
-
copy[key] = undefined
|
|
31
|
-
equalItems++
|
|
32
|
-
} else {
|
|
33
|
-
copy[key] = replaceEqualDeep(a[key], b[key])
|
|
34
|
-
if (copy[key] === a[key] && a[key] !== undefined) {
|
|
35
|
-
equalItems++
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return aSize === bSize && equalItems === aSize ? a : copy
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return b
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Shallow compare objects.
|
|
48
|
-
*/
|
|
49
|
-
export function shallowEqualObjects<T extends Record<string, any>>(
|
|
50
|
-
a: T,
|
|
51
|
-
b: T | undefined,
|
|
52
|
-
): boolean {
|
|
53
|
-
if (!b || Object.keys(a).length !== Object.keys(b).length) {
|
|
54
|
-
return false
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
for (const key in a) {
|
|
58
|
-
if (a[key] !== b[key]) {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return true
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function isPlainArray(value: unknown) {
|
|
67
|
-
return Array.isArray(value) && value.length === Object.keys(value).length
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
|
|
72
|
-
export function isPlainObject(o: any): o is Object {
|
|
73
|
-
if (!hasObjectPrototype(o)) {
|
|
74
|
-
return false
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// If has no constructor
|
|
78
|
-
const ctor = o.constructor
|
|
79
|
-
if (ctor === undefined) {
|
|
80
|
-
return true
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// If has modified prototype
|
|
84
|
-
const prot = ctor.prototype
|
|
85
|
-
if (!hasObjectPrototype(prot)) {
|
|
86
|
-
return false
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// If constructor does not have an Object-specific method
|
|
90
|
-
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
91
|
-
return false
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Handles Objects created by Object.create(<arbitrary prototype>)
|
|
95
|
-
if (Object.getPrototypeOf(o) !== Object.prototype) {
|
|
96
|
-
return false
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Most likely a plain Object
|
|
100
|
-
return true
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function hasObjectPrototype(o: any): boolean {
|
|
104
|
-
return Object.prototype.toString.call(o) === '[object Object]'
|
|
105
|
-
}
|