@whitesev/utils 2.9.12 → 2.10.0

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.
Files changed (73) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +206 -117
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +1 -1
  5. package/dist/index.amd.min.js.map +1 -1
  6. package/dist/index.cjs.js +206 -117
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +1 -1
  9. package/dist/index.cjs.min.js.map +1 -1
  10. package/dist/index.esm.js +206 -117
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +1 -1
  13. package/dist/index.esm.min.js.map +1 -1
  14. package/dist/index.iife.js +206 -117
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +1 -1
  17. package/dist/index.iife.min.js.map +1 -1
  18. package/dist/index.system.js +206 -117
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +1 -1
  21. package/dist/index.system.min.js.map +1 -1
  22. package/dist/index.umd.js +206 -117
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +1 -1
  25. package/dist/index.umd.min.js.map +1 -1
  26. package/dist/types/src/Dictionary.d.ts +2 -0
  27. package/dist/types/src/Utils.d.ts +9 -2
  28. package/dist/types/src/types/Httpx.d.ts +1344 -1344
  29. package/dist/types/src/types/Log.d.ts +19 -19
  30. package/dist/types/src/types/Progress.d.ts +20 -20
  31. package/dist/types/src/types/React.d.ts +119 -119
  32. package/dist/types/src/types/TryCatch.d.ts +9 -9
  33. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  34. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  35. package/dist/types/src/types/Vue2.d.ts +166 -166
  36. package/dist/types/src/types/WindowApi.d.ts +14 -14
  37. package/dist/types/src/types/ajaxHooker.d.ts +155 -155
  38. package/dist/types/src/types/env.d.ts +7 -7
  39. package/dist/types/src/types/global.d.ts +31 -31
  40. package/package.json +26 -24
  41. package/src/ColorConversion.ts +118 -118
  42. package/src/CommonUtil.ts +301 -301
  43. package/src/DOMUtils.ts +251 -251
  44. package/src/Dictionary.ts +205 -199
  45. package/src/GBKEncoder.ts +108 -108
  46. package/src/Hooks.ts +73 -73
  47. package/src/Httpx.ts +1457 -1457
  48. package/src/LockFunction.ts +65 -62
  49. package/src/Log.ts +233 -233
  50. package/src/ModuleRaid.js +378 -360
  51. package/src/Progress.ts +108 -108
  52. package/src/TryCatch.ts +86 -86
  53. package/src/Utils.ts +3907 -3852
  54. package/src/UtilsCommon.ts +14 -14
  55. package/src/UtilsGMCookie.ts +273 -273
  56. package/src/UtilsGMMenu.ts +460 -460
  57. package/src/Vue.ts +233 -233
  58. package/src/WindowApi.ts +59 -59
  59. package/src/ajaxHooker/ajaxHooker.js +606 -538
  60. package/src/ajaxHooker/ajaxHooker1.2.4.js +440 -438
  61. package/src/indexedDB.ts +497 -497
  62. package/src/types/Httpx.d.ts +1344 -1344
  63. package/src/types/Log.d.ts +19 -19
  64. package/src/types/Progress.d.ts +20 -20
  65. package/src/types/React.d.ts +119 -119
  66. package/src/types/TryCatch.d.ts +9 -9
  67. package/src/types/UtilsGMCookie.d.ts +93 -93
  68. package/src/types/UtilsGMMenu.d.ts +77 -77
  69. package/src/types/Vue2.d.ts +166 -166
  70. package/src/types/WindowApi.d.ts +14 -14
  71. package/src/types/ajaxHooker.d.ts +155 -155
  72. package/src/types/env.d.ts +7 -7
  73. package/src/types/global.d.ts +31 -31
package/src/Dictionary.ts CHANGED
@@ -1,199 +1,205 @@
1
- export class UtilsDictionary<K, V> {
2
- private items: Map<K, V>;
3
- /**
4
- * @example
5
- * new utils.Dictionary();
6
- * @example
7
- * new utils.Dictionary(1, 2);
8
- * @example
9
- * new utils.Dictionary([1, 2], [3, 4], [5, 6]);
10
- * @example
11
- * new utils.Dictionary({1:2, 3:4, "5":"6"});
12
- */
13
- constructor();
14
- constructor(dataList: [key: K, value: V][]);
15
- constructor(data: { [key: string | symbol]: V });
16
- constructor(key: K, value: V);
17
- constructor(...args: any[]) {
18
- this.items = new Map();
19
- if (args.length === 1) {
20
- // 数组|对象
21
- const data = args[0];
22
- if (Array.isArray(data)) {
23
- // 数组
24
- // [[1,2], [3,4], ...]
25
- for (let index = 0; index < data.length; index++) {
26
- const item = data[index];
27
- if (Array.isArray(item)) {
28
- const [key, value] = item;
29
- this.set(key, value);
30
- }
31
- }
32
- } else if (typeof data === "object" && data != null) {
33
- // 对象
34
- // {1:2, 3:4}
35
- for (const key in data) {
36
- if (Reflect.has(data, key)) {
37
- this.set(key as K, data[key] as V);
38
- }
39
- }
40
- }
41
- } else if (args.length === 2) {
42
- // 键、值
43
- const [key, value] = args;
44
- this.set(key, value);
45
- }
46
- }
47
- /**
48
- * 获取字典的长度,同this.size
49
- */
50
- get length() {
51
- return this.size();
52
- }
53
- /**
54
- * 迭代器
55
- */
56
- get entries() {
57
- const that = this;
58
- return function* (): IterableIterator<[K, V]> {
59
- const itemKeys = that.keys();
60
- for (const keyName of itemKeys) {
61
- yield [keyName as K, that.get(keyName as K) as V];
62
- }
63
- };
64
- }
65
- /**
66
- * 是否可遍历
67
- */
68
- get [Symbol.iterator]() {
69
- return () => {
70
- return this.entries();
71
- };
72
- }
73
- /**
74
- * 检查是否有某一个键
75
- * @param key
76
- */
77
- has(key: K): boolean {
78
- return this.items.has(key);
79
- }
80
- /**
81
- * 获取某个键的值
82
- * https://github.com/microsoft/TypeScript/issues/9619
83
- * 微软到现在都没有实现has和get的联动
84
- * @param key
85
- */
86
- get(key: K): V {
87
- return this.items.get(key) as V;
88
- }
89
- /**
90
- * 为字典添加某一个值
91
- * @param key 键
92
- * @param val 值,默认为""
93
- */
94
- set(key: K, val: V): void {
95
- if (key === void 0) {
96
- throw new Error("Utils.Dictionary().set 参数 key 不能为undefined");
97
- }
98
- this.items.set(key, val);
99
- }
100
- /**
101
- * 删除某一个键
102
- * @param key
103
- * @returns
104
- * + true:键存在且成功删除
105
- * + false:键不存在
106
- */
107
- delete(key: K): boolean {
108
- if (this.has(key)) {
109
- return this.items.delete(key);
110
- }
111
- return false;
112
- }
113
- /**
114
- * 获取字典所有的键
115
- */
116
- keys(): K[] {
117
- const keys = this.items.keys();
118
- if (typeof keys.toArray === "function") {
119
- return keys.toArray();
120
- } else {
121
- return [...keys];
122
- }
123
- }
124
- /**
125
- * 返回字典中的所有值
126
- */
127
- values(): V[] {
128
- const values = this.items.values();
129
- if (typeof values.toArray === "function") {
130
- return values.toArray();
131
- } else {
132
- return [...values];
133
- }
134
- }
135
- /**
136
- * 清空字典
137
- */
138
- clear() {
139
- this.items.clear();
140
- }
141
- /**
142
- * 获取字典的长度
143
- */
144
- size(): number {
145
- return this.items.size;
146
- }
147
- /**
148
- * 返回字典本身
149
- */
150
- getItems() {
151
- return this.items;
152
- }
153
- /**
154
- * 合并另一个字典
155
- * @param data 需要合并的字典
156
- */
157
- concat(data: UtilsDictionary<K, V>) {
158
- data.forEach((value, key) => {
159
- this.items.set(key, value);
160
- });
161
- }
162
- /**
163
- * 迭代字典
164
- * @param callbackfn 回调函数
165
- */
166
- forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
167
- this.items.forEach((value, key) => {
168
- callbackfn(value, key, this);
169
- });
170
- }
171
- /**
172
- * 检查已有的键中是否以xx开头
173
- * @param key 需要匹配的键
174
- */
175
- startsWith(key: string): boolean {
176
- const keys = this.keys();
177
- for (const keyName of keys) {
178
- if (String(keyName).startsWith(key)) {
179
- return true;
180
- }
181
- }
182
- return false;
183
- }
184
- /**
185
- * 获取以xx开头的键的值
186
- * @param key 需要匹配的键
187
- */
188
- getStartsWith(key: K): V | undefined {
189
- let result: V | undefined = void 0;
190
- const keys = this.keys();
191
- for (const keyName of keys) {
192
- if (String(keyName).startsWith(String(key))) {
193
- result = this.get(keyName as K);
194
- break;
195
- }
196
- }
197
- return result;
198
- }
199
- }
1
+ export class UtilsDictionary<K, V> {
2
+ private items: Map<K, V>;
3
+ /**
4
+ * @example
5
+ * new utils.Dictionary();
6
+ * @example
7
+ * new utils.Dictionary(1, 2);
8
+ * @example
9
+ * new utils.Dictionary([1, 2], [3, 4], [5, 6]);
10
+ * @example
11
+ * new utils.Dictionary({1:2, 3:4, "5":"6"});
12
+ */
13
+ constructor();
14
+ constructor(dataList: [key: K, value: V][]);
15
+ constructor(data: { [key: string | symbol]: V });
16
+ constructor(key: K, value: V);
17
+ constructor(...args: any[]) {
18
+ this.items = new Map();
19
+ if (args.length === 1) {
20
+ // 数组|对象
21
+ const data = args[0];
22
+ if (Array.isArray(data)) {
23
+ // 数组
24
+ // [[1,2], [3,4], ...]
25
+ for (let index = 0; index < data.length; index++) {
26
+ const item = data[index];
27
+ if (Array.isArray(item)) {
28
+ const [key, value] = item;
29
+ this.set(key, value);
30
+ }
31
+ }
32
+ } else if (typeof data === "object" && data != null) {
33
+ // 对象
34
+ // {1:2, 3:4}
35
+ for (const key in data) {
36
+ if (Reflect.has(data, key)) {
37
+ this.set(key as K, data[key] as V);
38
+ }
39
+ }
40
+ }
41
+ } else if (args.length === 2) {
42
+ // 键、值
43
+ const [key, value] = args;
44
+ this.set(key, value);
45
+ }
46
+ }
47
+ [Symbol.dispose]() {
48
+ this.clear();
49
+ }
50
+ async [Symbol.asyncDispose]() {
51
+ this.clear();
52
+ }
53
+ /**
54
+ * 获取字典的长度,同this.size
55
+ */
56
+ get length() {
57
+ return this.size();
58
+ }
59
+ /**
60
+ * 迭代器
61
+ */
62
+ get entries() {
63
+ const that = this;
64
+ return function* (): IterableIterator<[K, V]> {
65
+ const itemKeys = that.keys();
66
+ for (const keyName of itemKeys) {
67
+ yield [keyName as K, that.get(keyName as K) as V];
68
+ }
69
+ };
70
+ }
71
+ /**
72
+ * 是否可遍历
73
+ */
74
+ get [Symbol.iterator]() {
75
+ return () => {
76
+ return this.entries();
77
+ };
78
+ }
79
+ /**
80
+ * 检查是否有某一个键
81
+ * @param key 键
82
+ */
83
+ has(key: K): boolean {
84
+ return this.items.has(key);
85
+ }
86
+ /**
87
+ * 获取某个键的值
88
+ * https://github.com/microsoft/TypeScript/issues/9619
89
+ * 微软到现在都没有实现has和get的联动
90
+ * @param key 键
91
+ */
92
+ get(key: K): V {
93
+ return this.items.get(key) as V;
94
+ }
95
+ /**
96
+ * 为字典添加某一个值
97
+ * @param key 键
98
+ * @param val 值,默认为""
99
+ */
100
+ set(key: K, val: V): void {
101
+ if (key === void 0) {
102
+ throw new Error("Utils.Dictionary().set 参数 key 不能为undefined");
103
+ }
104
+ this.items.set(key, val);
105
+ }
106
+ /**
107
+ * 删除某一个键
108
+ * @param key
109
+ * @returns
110
+ * + true:键存在且成功删除
111
+ * + false:键不存在
112
+ */
113
+ delete(key: K): boolean {
114
+ if (this.has(key)) {
115
+ return this.items.delete(key);
116
+ }
117
+ return false;
118
+ }
119
+ /**
120
+ * 获取字典所有的键
121
+ */
122
+ keys(): K[] {
123
+ const keys = this.items.keys();
124
+ if (typeof keys.toArray === "function") {
125
+ return keys.toArray();
126
+ } else {
127
+ return [...keys];
128
+ }
129
+ }
130
+ /**
131
+ * 返回字典中的所有值
132
+ */
133
+ values(): V[] {
134
+ const values = this.items.values();
135
+ if (typeof values.toArray === "function") {
136
+ return values.toArray();
137
+ } else {
138
+ return [...values];
139
+ }
140
+ }
141
+ /**
142
+ * 清空字典
143
+ */
144
+ clear() {
145
+ this.items.clear();
146
+ }
147
+ /**
148
+ * 获取字典的长度
149
+ */
150
+ size(): number {
151
+ return this.items.size;
152
+ }
153
+ /**
154
+ * 返回字典本身
155
+ */
156
+ getItems() {
157
+ return this.items;
158
+ }
159
+ /**
160
+ * 合并另一个字典
161
+ * @param data 需要合并的字典
162
+ */
163
+ concat(data: UtilsDictionary<K, V>) {
164
+ data.forEach((value, key) => {
165
+ this.items.set(key, value);
166
+ });
167
+ }
168
+ /**
169
+ * 迭代字典
170
+ * @param callbackfn 回调函数
171
+ */
172
+ forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
173
+ this.items.forEach((value, key) => {
174
+ callbackfn(value, key, this);
175
+ });
176
+ }
177
+ /**
178
+ * 检查已有的键中是否以xx开头
179
+ * @param key 需要匹配的键
180
+ */
181
+ startsWith(key: string): boolean {
182
+ const keys = this.keys();
183
+ for (const keyName of keys) {
184
+ if (String(keyName).startsWith(key)) {
185
+ return true;
186
+ }
187
+ }
188
+ return false;
189
+ }
190
+ /**
191
+ * 获取以xx开头的键的值
192
+ * @param key 需要匹配的键
193
+ */
194
+ getStartsWith(key: K): V | undefined {
195
+ let result: V | undefined = void 0;
196
+ const keys = this.keys();
197
+ for (const keyName of keys) {
198
+ if (String(keyName).startsWith(String(key))) {
199
+ result = this.get(keyName as K);
200
+ break;
201
+ }
202
+ }
203
+ return result;
204
+ }
205
+ }