@whitesev/utils 2.7.1 → 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 +260 -409
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +260 -409
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +260 -409
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +260 -409
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +260 -409
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +260 -409
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/ColorConversion.d.ts +3 -8
- package/dist/types/src/Dictionary.d.ts +21 -14
- package/dist/types/src/GBKEncoder.d.ts +1 -2
- package/dist/types/src/Hooks.d.ts +1 -2
- package/dist/types/src/Httpx.d.ts +45 -46
- package/dist/types/src/LockFunction.d.ts +1 -2
- package/dist/types/src/Log.d.ts +1 -2
- package/dist/types/src/Progress.d.ts +1 -2
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/UtilsGMMenu.d.ts +1 -2
- package/dist/types/src/WindowApi.d.ts +1 -2
- package/dist/types/src/indexedDB.d.ts +1 -2
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +75 -86
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/dist/types/src/types/env.d.ts +2 -0
- package/dist/types/src/types/global.d.ts +3 -0
- package/package.json +1 -1
- package/src/ColorConversion.ts +13 -37
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -24
- package/src/Dictionary.ts +37 -38
- package/src/GBKEncoder.ts +9 -18
- package/src/Hooks.ts +2 -7
- package/src/Httpx.ts +257 -412
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +8 -26
- package/src/Progress.ts +3 -13
- package/src/TryCatch.ts +4 -12
- package/src/Utils.ts +233 -595
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +29 -51
- package/src/Vue.ts +6 -18
- package/src/WindowApi.ts +2 -5
- package/src/indexedDB.ts +11 -20
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +75 -86
- package/src/types/ajaxHooker.d.ts +1 -5
- package/src/types/env.d.ts +2 -0
- package/src/types/global.d.ts +3 -0
package/src/Dictionary.ts
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
import { CommonUtil } from "./CommonUtil";
|
|
2
2
|
|
|
3
|
-
class UtilsDictionary<K, V> {
|
|
3
|
+
export class UtilsDictionary<K extends string | number | symbol, V extends unknown> {
|
|
4
4
|
private items: {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} = {};
|
|
5
|
+
[key: string | number | symbol]: V;
|
|
6
|
+
};
|
|
8
7
|
constructor();
|
|
9
8
|
constructor(key: K, value: V);
|
|
10
9
|
constructor(key?: K, value?: V) {
|
|
10
|
+
this.items = {};
|
|
11
11
|
if (key != null) {
|
|
12
12
|
this.set(key, value!);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* 获取字典的长度,同this.size
|
|
17
|
+
*/
|
|
18
|
+
get length() {
|
|
19
|
+
return this.size();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 迭代器
|
|
23
|
+
*/
|
|
24
|
+
get entries() {
|
|
25
|
+
let that = this;
|
|
26
|
+
return function* (): IterableIterator<[K, V]> {
|
|
27
|
+
let itemKeys = Object.keys(that.getItems());
|
|
28
|
+
for (const keyName of itemKeys) {
|
|
29
|
+
yield [keyName as K, that.get(keyName as K) as V];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 是否可遍历
|
|
35
|
+
*/
|
|
36
|
+
get [Symbol.iterator]() {
|
|
37
|
+
let that = this;
|
|
38
|
+
return function () {
|
|
39
|
+
return that.entries();
|
|
40
|
+
};
|
|
41
|
+
}
|
|
15
42
|
/**
|
|
16
43
|
* 检查是否有某一个键
|
|
17
44
|
* @param key 键
|
|
@@ -111,8 +138,7 @@ class UtilsDictionary<K, V> {
|
|
|
111
138
|
/**
|
|
112
139
|
* 返回字典本身
|
|
113
140
|
*/
|
|
114
|
-
getItems()
|
|
115
|
-
// @ts-ignore
|
|
141
|
+
getItems() {
|
|
116
142
|
return this.items;
|
|
117
143
|
}
|
|
118
144
|
/**
|
|
@@ -122,40 +148,13 @@ class UtilsDictionary<K, V> {
|
|
|
122
148
|
concat(data: UtilsDictionary<K, V>) {
|
|
123
149
|
this.items = CommonUtil.assign(this.items, data.getItems());
|
|
124
150
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
151
|
+
/**
|
|
152
|
+
* 迭代字典
|
|
153
|
+
* @param callbackfn 回调函数
|
|
154
|
+
*/
|
|
155
|
+
forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
|
|
128
156
|
for (const key in this.getItems()) {
|
|
129
157
|
callbackfn(this.get(key as any) as V, key as K, this.getItems() as any);
|
|
130
158
|
}
|
|
131
159
|
}
|
|
132
|
-
/**
|
|
133
|
-
* 获取字典的长度,同this.size
|
|
134
|
-
*/
|
|
135
|
-
get length() {
|
|
136
|
-
return this.size();
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* 迭代器
|
|
140
|
-
*/
|
|
141
|
-
get entries() {
|
|
142
|
-
let that = this;
|
|
143
|
-
return function* (): IterableIterator<[K, V]> {
|
|
144
|
-
let itemKeys = Object.keys(that.getItems());
|
|
145
|
-
for (const keyName of itemKeys) {
|
|
146
|
-
yield [keyName as K, that.get(keyName as K) as V];
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* 是否可遍历
|
|
152
|
-
*/
|
|
153
|
-
get [Symbol.iterator]() {
|
|
154
|
-
let that = this;
|
|
155
|
-
return function () {
|
|
156
|
-
return that.entries();
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
160
|
}
|
|
160
|
-
|
|
161
|
-
export { UtilsDictionary };
|
package/src/GBKEncoder.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UtilsOwnObject } from "./types/global";
|
|
2
2
|
|
|
3
|
-
class GBKEncoder {
|
|
3
|
+
export class GBKEncoder {
|
|
4
4
|
#data: RegExpMatchArray = [] as any;
|
|
5
5
|
#U2Ghash: UtilsOwnObject<string> = {};
|
|
6
6
|
#G2Uhash: UtilsOwnObject<string> = {};
|
|
@@ -13,12 +13,7 @@ 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) {
|
|
@@ -93,16 +88,15 @@ class GBKEncoder {
|
|
|
93
88
|
* @param str
|
|
94
89
|
*/
|
|
95
90
|
decode(str: string) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
let that = this;
|
|
91
|
+
let GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
|
|
92
|
+
let UTFMatcher = /%[0-9A-F]{2}/;
|
|
93
|
+
// let gbk = true;
|
|
94
|
+
let utf = true;
|
|
95
|
+
const that = this;
|
|
102
96
|
while (utf) {
|
|
103
97
|
let gbkMatch = str.match(GBKMatcher);
|
|
104
98
|
let utfMatch = str.match(UTFMatcher);
|
|
105
|
-
gbk = Boolean(gbkMatch);
|
|
99
|
+
// gbk = Boolean(gbkMatch);
|
|
106
100
|
utf = Boolean(utfMatch);
|
|
107
101
|
if (gbkMatch && (gbkMatch as any) in that.#G2Uhash) {
|
|
108
102
|
str = str.replace(
|
|
@@ -110,12 +104,9 @@ class GBKEncoder {
|
|
|
110
104
|
String.fromCharCode(("0x" + that.#G2Uhash[gbkMatch as any]) as any)
|
|
111
105
|
);
|
|
112
106
|
} else {
|
|
113
|
-
|
|
114
|
-
str = str.replace(utfMatch, decodeURIComponent(utfMatch));
|
|
107
|
+
str = str.replace(utfMatch as any, decodeURIComponent(utfMatch as any));
|
|
115
108
|
}
|
|
116
109
|
}
|
|
117
110
|
return str;
|
|
118
111
|
}
|
|
119
112
|
}
|
|
120
|
-
|
|
121
|
-
export { GBKEncoder };
|
package/src/Hooks.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Hooks {
|
|
1
|
+
export class Hooks {
|
|
2
2
|
/**
|
|
3
3
|
* 在Function原型上添加自定义方法.hook和.unhook
|
|
4
4
|
*/
|
|
@@ -15,10 +15,7 @@ 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
|
}
|
|
@@ -82,5 +79,3 @@ class Hooks {
|
|
|
82
79
|
return true;
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
|
-
|
|
86
|
-
export { Hooks };
|