@whitesev/utils 2.7.2 → 2.7.3
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/index.amd.js +98 -203
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +98 -203
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +98 -203
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +98 -203
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +98 -203
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +98 -203
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +4 -21
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/package.json +1 -1
- package/src/ColorConversion.ts +5 -18
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -22
- package/src/Dictionary.ts +2 -7
- package/src/GBKEncoder.ts +1 -6
- package/src/Hooks.ts +1 -4
- package/src/Httpx.ts +102 -277
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +7 -23
- package/src/Progress.ts +2 -10
- package/src/TryCatch.ts +3 -11
- package/src/Utils.ts +209 -555
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +10 -29
- package/src/Vue.ts +2 -11
- package/src/indexedDB.ts +3 -12
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +4 -21
- package/src/types/ajaxHooker.d.ts +1 -5
|
@@ -1763,7 +1763,24 @@ declare class Utils {
|
|
|
1763
1763
|
* @param target 待获取的对象
|
|
1764
1764
|
* @param handler 获取属性的回调
|
|
1765
1765
|
*/
|
|
1766
|
-
queryProperty(target: any, handler: (target:
|
|
1766
|
+
queryProperty<T extends any = any>(target: any, handler: (target: T) => {
|
|
1767
|
+
/**
|
|
1768
|
+
* 是否是需要的属性
|
|
1769
|
+
* + `true` 将目标值赋值给data
|
|
1770
|
+
* + `false` 不是需要的,data为下一个处理的对象
|
|
1771
|
+
*/
|
|
1772
|
+
isFind: boolean;
|
|
1773
|
+
/**
|
|
1774
|
+
* 对象/目标值
|
|
1775
|
+
*/
|
|
1776
|
+
data: any;
|
|
1777
|
+
}): any;
|
|
1778
|
+
/**
|
|
1779
|
+
* 异步-深度获取对象属性
|
|
1780
|
+
* @param target 待获取的对象
|
|
1781
|
+
* @param handler 获取属性的回调
|
|
1782
|
+
*/
|
|
1783
|
+
asyncQueryProperty<T extends any = any>(target: any, handler: (target: T) => {
|
|
1767
1784
|
/**
|
|
1768
1785
|
* 是否是需要的属性
|
|
1769
1786
|
* + true 将目标值赋值给data
|
|
@@ -1774,7 +1791,18 @@ declare class Utils {
|
|
|
1774
1791
|
* 对象/目标值
|
|
1775
1792
|
*/
|
|
1776
1793
|
data: any;
|
|
1777
|
-
}
|
|
1794
|
+
} | Promise<{
|
|
1795
|
+
/**
|
|
1796
|
+
* 是否是需要的属性
|
|
1797
|
+
* + true 将目标值赋值给data
|
|
1798
|
+
* + false 不是需要的,data为下一个处理的对象
|
|
1799
|
+
*/
|
|
1800
|
+
isFind: boolean;
|
|
1801
|
+
/**
|
|
1802
|
+
* 对象/目标值
|
|
1803
|
+
*/
|
|
1804
|
+
data: any;
|
|
1805
|
+
}>): Promise<Awaited<T>>;
|
|
1778
1806
|
/**
|
|
1779
1807
|
* 创建一个新的Utils实例
|
|
1780
1808
|
* @param option
|
|
@@ -40,8 +40,7 @@ declare interface DOMUtils_Frame_Object_Event {
|
|
|
40
40
|
scroll: Event;
|
|
41
41
|
unload: Event;
|
|
42
42
|
}
|
|
43
|
-
declare type DOMUtils_Frame_Object_EventType =
|
|
44
|
-
keyof DOMUtils_Frame_Object_Event;
|
|
43
|
+
declare type DOMUtils_Frame_Object_EventType = keyof DOMUtils_Frame_Object_Event;
|
|
45
44
|
/**
|
|
46
45
|
* 表单事件
|
|
47
46
|
*/
|
|
@@ -66,14 +66,7 @@ export type HttpxStatus =
|
|
|
66
66
|
* HTTP WebDav的请求方法
|
|
67
67
|
* + https://blog.csdn.net/weixin_48421613/article/details/128611546
|
|
68
68
|
*/
|
|
69
|
-
export type HttpxWebDavMethod =
|
|
70
|
-
| "PROPFIND"
|
|
71
|
-
| "PROPPATCH"
|
|
72
|
-
| "MKCOL"
|
|
73
|
-
| "MOVE"
|
|
74
|
-
| "COPY"
|
|
75
|
-
| "LOCK"
|
|
76
|
-
| "UNLOCK";
|
|
69
|
+
export type HttpxWebDavMethod = "PROPFIND" | "PROPPATCH" | "MKCOL" | "MOVE" | "COPY" | "LOCK" | "UNLOCK";
|
|
77
70
|
|
|
78
71
|
/**
|
|
79
72
|
* HTTP 请求方法
|
|
@@ -99,21 +92,12 @@ export type HttpxRedirect = "follow" | "error" | "manual";
|
|
|
99
92
|
/**
|
|
100
93
|
* 二进制数据
|
|
101
94
|
*/
|
|
102
|
-
export type HttpxBinary =
|
|
103
|
-
| Uint8ArrayConstructor
|
|
104
|
-
| ArrayBufferConstructor
|
|
105
|
-
| DataViewConstructor
|
|
106
|
-
| Blob
|
|
107
|
-
| File;
|
|
95
|
+
export type HttpxBinary = Uint8ArrayConstructor | ArrayBufferConstructor | DataViewConstructor | Blob | File;
|
|
108
96
|
|
|
109
97
|
/**
|
|
110
98
|
* 触发的响应函数名
|
|
111
99
|
*/
|
|
112
|
-
export type HttpxResponseCallBackType =
|
|
113
|
-
| "onload"
|
|
114
|
-
| "onerror"
|
|
115
|
-
| "ontimeout"
|
|
116
|
-
| "onabort";
|
|
100
|
+
export type HttpxResponseCallBackType = "onload" | "onerror" | "ontimeout" | "onabort";
|
|
117
101
|
|
|
118
102
|
/**
|
|
119
103
|
* 响应类型映射字典
|
|
@@ -1356,5 +1340,4 @@ export declare interface HttpxInitOption extends HttpxRequestOption {
|
|
|
1356
1340
|
logDetails?: boolean;
|
|
1357
1341
|
}
|
|
1358
1342
|
|
|
1359
|
-
export declare interface HttpxRequestOptionWithDoubleParams
|
|
1360
|
-
extends Omit<HttpxRequestOption, "url"> {}
|
|
1343
|
+
export declare interface HttpxRequestOptionWithDoubleParams extends Omit<HttpxRequestOption, "url"> {}
|
|
@@ -122,11 +122,7 @@ export declare interface UtilsAjaxHookResult {
|
|
|
122
122
|
};
|
|
123
123
|
});
|
|
124
124
|
*/
|
|
125
|
-
hook(
|
|
126
|
-
callback: (
|
|
127
|
-
request: UtilsAjaxHookRequestOptions
|
|
128
|
-
) => void | Promise<undefined>
|
|
129
|
-
): void;
|
|
125
|
+
hook(callback: (request: UtilsAjaxHookRequestOptions) => void | Promise<undefined>): void;
|
|
130
126
|
/**
|
|
131
127
|
* 过滤
|
|
132
128
|
* @example
|
package/package.json
CHANGED
package/src/ColorConversion.ts
CHANGED
|
@@ -59,11 +59,7 @@ export class ColorConversion {
|
|
|
59
59
|
* @param greenValue
|
|
60
60
|
* @param blueValue
|
|
61
61
|
*/
|
|
62
|
-
rgbToHex(
|
|
63
|
-
redValue: string | number,
|
|
64
|
-
greenValue: string | number,
|
|
65
|
-
blueValue: string | number
|
|
66
|
-
): string {
|
|
62
|
+
rgbToHex(redValue: string | number, greenValue: string | number, blueValue: string | number): string {
|
|
67
63
|
/* 验证输入的rgb值是否合法 */
|
|
68
64
|
let validPattern = /^\d{1,3}$/;
|
|
69
65
|
if (
|
|
@@ -72,13 +68,8 @@ export class ColorConversion {
|
|
|
72
68
|
!validPattern.test(blueValue.toString())
|
|
73
69
|
)
|
|
74
70
|
throw new TypeError("输入错误的rgb颜色值");
|
|
75
|
-
let hexs = [
|
|
76
|
-
|
|
77
|
-
greenValue.toString(16),
|
|
78
|
-
blueValue.toString(16),
|
|
79
|
-
];
|
|
80
|
-
for (let index = 0; index < 3; index++)
|
|
81
|
-
if (hexs[index].length == 1) hexs[index] = "0" + hexs[index];
|
|
71
|
+
let hexs = [redValue.toString(16), greenValue.toString(16), blueValue.toString(16)];
|
|
72
|
+
for (let index = 0; index < 3; index++) if (hexs[index].length == 1) hexs[index] = "0" + hexs[index];
|
|
82
73
|
return "#" + hexs.join("");
|
|
83
74
|
}
|
|
84
75
|
/**
|
|
@@ -92,9 +83,7 @@ export class ColorConversion {
|
|
|
92
83
|
}
|
|
93
84
|
let rgbc = this.hexToRgb(color);
|
|
94
85
|
for (let index = 0; index < 3; index++) {
|
|
95
|
-
(rgbc as any)[index] = Math.floor(
|
|
96
|
-
(rgbc as any)[index] * (1 - (level as any))
|
|
97
|
-
);
|
|
86
|
+
(rgbc as any)[index] = Math.floor((rgbc as any)[index] * (1 - (level as any)));
|
|
98
87
|
}
|
|
99
88
|
|
|
100
89
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
@@ -110,9 +99,7 @@ export class ColorConversion {
|
|
|
110
99
|
}
|
|
111
100
|
let rgbc = this.hexToRgb(color);
|
|
112
101
|
for (let index = 0; index < 3; index++) {
|
|
113
|
-
(rgbc as any)[index] = Math.floor(
|
|
114
|
-
(255 - (rgbc as any)[index]) * (level as any) + (rgbc as any)[index]
|
|
115
|
-
);
|
|
102
|
+
(rgbc as any)[index] = Math.floor((255 - (rgbc as any)[index]) * (level as any) + (rgbc as any)[index]);
|
|
116
103
|
}
|
|
117
104
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
118
105
|
}
|
package/src/CommonUtil.ts
CHANGED
|
@@ -49,11 +49,7 @@ class CommonUtil {
|
|
|
49
49
|
!UtilsContext.isDOM(sourceValue)
|
|
50
50
|
) {
|
|
51
51
|
/* 源端的值是object类型,且不是元素节点 */
|
|
52
|
-
(target as any)[sourceKeyName] = UtilsContext.assign(
|
|
53
|
-
targetValue,
|
|
54
|
-
sourceValue,
|
|
55
|
-
isAdd
|
|
56
|
-
);
|
|
52
|
+
(target as any)[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
57
53
|
continue;
|
|
58
54
|
}
|
|
59
55
|
(target as any)[sourceKeyName] = sourceValue;
|
|
@@ -70,11 +66,7 @@ class CommonUtil {
|
|
|
70
66
|
Object.keys(sourceValue).length
|
|
71
67
|
) {
|
|
72
68
|
/* 源端的值是object类型,且不是元素节点 */
|
|
73
|
-
(target as any)[targetKeyName] = UtilsContext.assign(
|
|
74
|
-
targetValue,
|
|
75
|
-
sourceValue,
|
|
76
|
-
isAdd
|
|
77
|
-
);
|
|
69
|
+
(target as any)[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
78
70
|
continue;
|
|
79
71
|
}
|
|
80
72
|
/* 直接赋值 */
|
|
@@ -153,10 +145,7 @@ class CommonUtil {
|
|
|
153
145
|
itemResult = objItem === 0;
|
|
154
146
|
break;
|
|
155
147
|
case "string":
|
|
156
|
-
itemResult =
|
|
157
|
-
objItem.trim() === "" ||
|
|
158
|
-
objItem === "null" ||
|
|
159
|
-
objItem === "undefined";
|
|
148
|
+
itemResult = objItem.trim() === "" || objItem === "null" || objItem === "undefined";
|
|
160
149
|
break;
|
|
161
150
|
case "boolean":
|
|
162
151
|
itemResult = !objItem;
|
|
@@ -164,9 +153,7 @@ class CommonUtil {
|
|
|
164
153
|
case "function":
|
|
165
154
|
let funcStr = objItem.toString().replace(/\s/g, "");
|
|
166
155
|
/* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
|
|
167
|
-
itemResult = Boolean(
|
|
168
|
-
funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/)
|
|
169
|
-
);
|
|
156
|
+
itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
|
|
170
157
|
break;
|
|
171
158
|
}
|
|
172
159
|
}
|
|
@@ -214,8 +201,7 @@ class CommonUtil {
|
|
|
214
201
|
if (obj === null) return null;
|
|
215
202
|
let clone = obj instanceof Array ? [] : {};
|
|
216
203
|
for (const [key, value] of Object.entries(obj)) {
|
|
217
|
-
(clone as any)[key] =
|
|
218
|
-
typeof value === "object" ? UtilsContext.deepClone(value) : value;
|
|
204
|
+
(clone as any)[key] = typeof value === "object" ? UtilsContext.deepClone(value) : value;
|
|
219
205
|
}
|
|
220
206
|
return clone;
|
|
221
207
|
}
|
|
@@ -243,14 +229,8 @@ class CommonUtil {
|
|
|
243
229
|
* Utils.toJSON("{123:123}")
|
|
244
230
|
* > {123:123}
|
|
245
231
|
*/
|
|
246
|
-
toJSON<T = any>(
|
|
247
|
-
|
|
248
|
-
errorCallBack?: (error: Error) => void
|
|
249
|
-
): T;
|
|
250
|
-
toJSON<T = any>(
|
|
251
|
-
data: string | null,
|
|
252
|
-
errorCallBack?: (error: Error) => void
|
|
253
|
-
): T {
|
|
232
|
+
toJSON<T = any>(data: string | null, errorCallBack?: (error: Error) => void): T;
|
|
233
|
+
toJSON<T = any>(data: string | null, errorCallBack?: (error: Error) => void): T {
|
|
254
234
|
let result: any = {};
|
|
255
235
|
if (typeof data === "object") {
|
|
256
236
|
return data as any;
|
|
@@ -274,10 +254,7 @@ class CommonUtil {
|
|
|
274
254
|
/^[\],:{}\s]*$/.test(
|
|
275
255
|
data
|
|
276
256
|
.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
|
|
277
|
-
.replace(
|
|
278
|
-
/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
|
|
279
|
-
"]"
|
|
280
|
-
)
|
|
257
|
+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
|
|
281
258
|
.replace(/(?:^|:|,)(?:\s*\[)+/g, "")
|
|
282
259
|
)
|
|
283
260
|
) {
|
package/src/DOMUtils.ts
CHANGED
|
@@ -88,11 +88,9 @@ class DOMUtils {
|
|
|
88
88
|
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
89
89
|
let text = textMatch![2];
|
|
90
90
|
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
91
|
-
return Array.from(parent.querySelectorAll<HTMLElement>(selector)).filter(
|
|
92
|
-
($ele
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
);
|
|
91
|
+
return Array.from(parent.querySelectorAll<HTMLElement>(selector)).filter(($ele) => {
|
|
92
|
+
return ($ele?.textContent || $ele?.innerText)?.includes(text);
|
|
93
|
+
});
|
|
96
94
|
} else if (
|
|
97
95
|
selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
|
|
98
96
|
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)
|
|
@@ -108,11 +106,9 @@ class DOMUtils {
|
|
|
108
106
|
}
|
|
109
107
|
let regexp = new RegExp(pattern, flags);
|
|
110
108
|
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
111
|
-
return Array.from(parent.querySelectorAll<HTMLElement>(selector)).filter(
|
|
112
|
-
($ele
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
);
|
|
109
|
+
return Array.from(parent.querySelectorAll<HTMLElement>(selector)).filter(($ele) => {
|
|
110
|
+
return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
|
|
111
|
+
});
|
|
116
112
|
} else {
|
|
117
113
|
// 普通语法
|
|
118
114
|
return Array.from(parent.querySelectorAll<E>(selector));
|
|
@@ -139,10 +135,7 @@ class DOMUtils {
|
|
|
139
135
|
* DOMUtils.matches("div:regexp(/^xxx/ig)")
|
|
140
136
|
* > false
|
|
141
137
|
*/
|
|
142
|
-
matches(
|
|
143
|
-
$el: HTMLElement | Element | null | undefined,
|
|
144
|
-
selector: string
|
|
145
|
-
): boolean {
|
|
138
|
+
matches($el: HTMLElement | Element | null | undefined, selector: string): boolean {
|
|
146
139
|
selector = selector.trim();
|
|
147
140
|
if ($el == null) {
|
|
148
141
|
return false;
|
|
@@ -215,14 +208,8 @@ class DOMUtils {
|
|
|
215
208
|
$el: HTMLElement | Element,
|
|
216
209
|
selector: string
|
|
217
210
|
): HTMLElementTagNameMap[K] | null;
|
|
218
|
-
closest<E extends Element = Element>(
|
|
219
|
-
|
|
220
|
-
selector: string
|
|
221
|
-
): E | null;
|
|
222
|
-
closest<E extends Element = Element>(
|
|
223
|
-
$el: HTMLElement | Element,
|
|
224
|
-
selector: string
|
|
225
|
-
): E | null {
|
|
211
|
+
closest<E extends Element = Element>($el: HTMLElement | Element, selector: string): E | null;
|
|
212
|
+
closest<E extends Element = Element>($el: HTMLElement | Element, selector: string): E | null {
|
|
226
213
|
selector = selector.trim();
|
|
227
214
|
|
|
228
215
|
if (selector.match(/[^\s]{1}:empty$/gi)) {
|
package/src/Dictionary.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { CommonUtil } from "./CommonUtil";
|
|
2
2
|
|
|
3
|
-
export class UtilsDictionary<
|
|
4
|
-
K extends string | number | symbol,
|
|
5
|
-
V extends unknown
|
|
6
|
-
> {
|
|
3
|
+
export class UtilsDictionary<K extends string | number | symbol, V extends unknown> {
|
|
7
4
|
private items: {
|
|
8
5
|
[key: string | number | symbol]: V;
|
|
9
6
|
};
|
|
@@ -155,9 +152,7 @@ export class UtilsDictionary<
|
|
|
155
152
|
* 迭代字典
|
|
156
153
|
* @param callbackfn 回调函数
|
|
157
154
|
*/
|
|
158
|
-
forEach(
|
|
159
|
-
callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void
|
|
160
|
-
) {
|
|
155
|
+
forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
|
|
161
156
|
for (const key in this.getItems()) {
|
|
162
157
|
callbackfn(this.get(key as any) as V, key as K, this.getItems() as any);
|
|
163
158
|
}
|
package/src/GBKEncoder.ts
CHANGED
|
@@ -13,12 +13,7 @@ export class GBKEncoder {
|
|
|
13
13
|
this.#data = dataText.match(/..../g) as RegExpMatchArray;
|
|
14
14
|
for (let i = 0x81; i <= 0xfe; i++) {
|
|
15
15
|
for (let j = 0x40; j <= 0xfe; j++) {
|
|
16
|
-
this.#U2Ghash[this.#data[index++]] = (
|
|
17
|
-
"%" +
|
|
18
|
-
i.toString(16) +
|
|
19
|
-
"%" +
|
|
20
|
-
j.toString(16)
|
|
21
|
-
).toUpperCase();
|
|
16
|
+
this.#U2Ghash[this.#data[index++]] = ("%" + i.toString(16) + "%" + j.toString(16)).toUpperCase();
|
|
22
17
|
}
|
|
23
18
|
}
|
|
24
19
|
for (let key in this.#U2Ghash) {
|
package/src/Hooks.ts
CHANGED
|
@@ -15,10 +15,7 @@ export class Hooks {
|
|
|
15
15
|
_funcName = getFuncName(this);
|
|
16
16
|
(_context as any)["realFunc_" + _funcName] = this;
|
|
17
17
|
|
|
18
|
-
if (
|
|
19
|
-
(_context[_funcName] as any).prototype &&
|
|
20
|
-
(_context[_funcName] as any).prototype.isHooked
|
|
21
|
-
) {
|
|
18
|
+
if ((_context[_funcName] as any).prototype && (_context[_funcName] as any).prototype.isHooked) {
|
|
22
19
|
console.log("Already has been hooked,unhook first");
|
|
23
20
|
return false;
|
|
24
21
|
}
|