wenay-common 1.0.170 → 1.0.172
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/lib/Common/Listen.d.ts +6 -3
- package/lib/Common/Listen.js +29 -8
- package/package.json +1 -1
package/lib/Common/Listen.d.ts
CHANGED
|
@@ -68,9 +68,12 @@ type obj = {
|
|
|
68
68
|
[k: string]: any;
|
|
69
69
|
};
|
|
70
70
|
export declare function CompareKeys<T extends obj, T2 extends obj>(obj1: T, obj2: T2): boolean;
|
|
71
|
-
export declare function
|
|
72
|
-
export declare function
|
|
73
|
-
export declare function
|
|
71
|
+
export declare function CompareKeys2<T extends obj>(obj1: T, keys: string[]): boolean;
|
|
72
|
+
export declare function DeepCompareKeys2<T, T3 extends unknown>(obj1: T, keys: string[], func: (a: any) => T3): any;
|
|
73
|
+
export declare function DeepCompareKeys<T, T2 extends obj, T3 extends unknown>(obj1: T, obj2: T2, func: (a: T2) => T3): {
|
|
74
|
+
[k: string]: any;
|
|
75
|
+
} | T3 | NonNullable<T> | null;
|
|
76
|
+
export declare function deepModifyByListenSocket<T>(obj: T, status: () => boolean): tDeepKeys<T, ReturnType<typeof funcListenCallbackBase>, ReturnType<typeof funcListenBySocket1>>;
|
|
74
77
|
export declare const funcListenBySocketObj: typeof deepModifyByListenSocket;
|
|
75
78
|
export declare function PromiseArrayListen<T extends any = unknown>(array: ((() => Promise<T>) | (() => any) | Promise<T>)[]): {
|
|
76
79
|
listenOk: (a: (...d: [data: T, i: number, countOk: number, countError: number, count: number]) => any) => () => void;
|
package/lib/Common/Listen.js
CHANGED
|
@@ -9,9 +9,10 @@ exports.funcListenBySocket2 = funcListenBySocket2;
|
|
|
9
9
|
exports.funcListenBySocket = funcListenBySocket;
|
|
10
10
|
exports.UseListen = UseListen;
|
|
11
11
|
exports.CompareKeys = CompareKeys;
|
|
12
|
+
exports.CompareKeys2 = CompareKeys2;
|
|
13
|
+
exports.DeepCompareKeys2 = DeepCompareKeys2;
|
|
12
14
|
exports.DeepCompareKeys = DeepCompareKeys;
|
|
13
15
|
exports.deepModifyByListenSocket = deepModifyByListenSocket;
|
|
14
|
-
exports.deepModifyByListenSocket2 = deepModifyByListenSocket2;
|
|
15
16
|
exports.PromiseArrayListen = PromiseArrayListen;
|
|
16
17
|
exports.socketBuffer3 = socketBuffer3;
|
|
17
18
|
exports.funcListenCallbackSnapshot = funcListenCallbackSnapshot;
|
|
@@ -154,24 +155,44 @@ function UseListen(data) {
|
|
|
154
155
|
return [(...e) => t?.(...e), a];
|
|
155
156
|
}
|
|
156
157
|
function CompareKeys(obj1, obj2) {
|
|
157
|
-
|
|
158
|
+
const k1 = Object.keys(obj1);
|
|
159
|
+
const k2 = Object.keys(obj2);
|
|
160
|
+
return k1.length == k2.length && ((new Set([...k1, ...k2])).size == k2.length);
|
|
161
|
+
}
|
|
162
|
+
function CompareKeys2(obj1, keys) {
|
|
163
|
+
const k1 = Object.keys(obj1);
|
|
164
|
+
return k1.length == keys.length && ((new Set([...k1, ...keys])).size == keys.length);
|
|
165
|
+
}
|
|
166
|
+
function DeepCompareKeys2(obj1, keys, func) {
|
|
167
|
+
if (obj1 == null)
|
|
168
|
+
return null;
|
|
169
|
+
if (typeof obj1 == "function")
|
|
170
|
+
return obj1;
|
|
171
|
+
if (obj1 instanceof Function)
|
|
172
|
+
return obj1;
|
|
173
|
+
if (typeof obj1 != "object")
|
|
174
|
+
return obj1;
|
|
175
|
+
if (CompareKeys2(obj1, keys)) {
|
|
176
|
+
return func(obj1);
|
|
177
|
+
}
|
|
178
|
+
return Object.fromEntries(Object.entries(obj1).map(([k, v]) => [k, DeepCompareKeys2(v, keys, func)]));
|
|
158
179
|
}
|
|
159
180
|
function DeepCompareKeys(obj1, obj2, func) {
|
|
160
181
|
if (obj1 == null)
|
|
161
182
|
return null;
|
|
162
183
|
if (typeof obj1 == "function")
|
|
163
184
|
return obj1;
|
|
185
|
+
if (obj1 instanceof Function)
|
|
186
|
+
return obj1;
|
|
164
187
|
if (typeof obj1 != "object")
|
|
165
188
|
return obj1;
|
|
166
|
-
|
|
189
|
+
const keys = Object.keys(obj2);
|
|
190
|
+
if (CompareKeys2(obj1, keys))
|
|
167
191
|
return func(obj1);
|
|
168
|
-
return Object.fromEntries(Object.entries(obj1).map(([k, v]) => [k,
|
|
192
|
+
return Object.fromEntries(Object.entries(obj1).map(([k, v]) => [k, DeepCompareKeys2(v, keys, func)]));
|
|
169
193
|
}
|
|
170
194
|
function deepModifyByListenSocket(obj, status) {
|
|
171
|
-
return DeepCompareKeys(obj,
|
|
172
|
-
}
|
|
173
|
-
function deepModifyByListenSocket2(obj, status) {
|
|
174
|
-
return DeepCompareKeys(obj, UseListen()[1], e => (0, exports.funcListenBySocket1)(e, status));
|
|
195
|
+
return DeepCompareKeys(obj, funcListenCallbackBase(e => { }), e => (0, exports.funcListenBySocket1)(e, status));
|
|
175
196
|
}
|
|
176
197
|
exports.funcListenBySocketObj = deepModifyByListenSocket;
|
|
177
198
|
function PromiseArrayListen(array) {
|