@whitesev/utils 2.7.8 → 2.8.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.
Files changed (70) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +896 -877
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.cjs.js +896 -877
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.esm.js +896 -877
  7. package/dist/index.esm.js.map +1 -1
  8. package/dist/index.iife.js +896 -877
  9. package/dist/index.iife.js.map +1 -1
  10. package/dist/index.system.js +896 -877
  11. package/dist/index.system.js.map +1 -1
  12. package/dist/index.umd.js +896 -877
  13. package/dist/index.umd.js.map +1 -1
  14. package/dist/types/src/CommonUtil.d.ts +59 -59
  15. package/dist/types/src/DOMUtils.d.ts +1 -1
  16. package/dist/types/src/Dictionary.d.ts +1 -1
  17. package/dist/types/src/Httpx.d.ts +2 -2
  18. package/dist/types/src/Progress.d.ts +0 -4
  19. package/dist/types/src/TryCatch.d.ts +2 -2
  20. package/dist/types/src/Utils.d.ts +365 -365
  21. package/dist/types/src/UtilsGMCookie.d.ts +2 -2
  22. package/dist/types/src/UtilsGMMenu.d.ts +1 -1
  23. package/dist/types/src/indexedDB.d.ts +3 -3
  24. package/dist/types/src/types/Event.d.ts +188 -188
  25. package/dist/types/src/types/Httpx.d.ts +1344 -1343
  26. package/dist/types/src/types/Log.d.ts +19 -19
  27. package/dist/types/src/types/Progress.d.ts +20 -20
  28. package/dist/types/src/types/React.d.ts +119 -119
  29. package/dist/types/src/types/TryCatch.d.ts +9 -9
  30. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  31. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  32. package/dist/types/src/types/Vue2.d.ts +166 -166
  33. package/dist/types/src/types/WindowApi.d.ts +14 -14
  34. package/dist/types/src/types/ajaxHooker.d.ts +151 -151
  35. package/dist/types/src/types/env.d.ts +7 -2
  36. package/dist/types/src/types/global.d.ts +31 -31
  37. package/package.json +16 -7
  38. package/src/ColorConversion.ts +105 -106
  39. package/src/CommonUtil.ts +280 -279
  40. package/src/DOMUtils.ts +251 -272
  41. package/src/Dictionary.ts +153 -154
  42. package/src/GBKEncoder.ts +108 -112
  43. package/src/Hooks.ts +73 -81
  44. package/src/Httpx.ts +1457 -1466
  45. package/src/LockFunction.ts +62 -62
  46. package/src/Log.ts +258 -259
  47. package/src/ModuleRaid.js +1 -0
  48. package/src/Progress.ts +108 -114
  49. package/src/TryCatch.ts +86 -86
  50. package/src/Utils.ts +4772 -4825
  51. package/src/UtilsCommon.ts +14 -14
  52. package/src/UtilsGMCookie.ts +254 -261
  53. package/src/UtilsGMMenu.ts +445 -454
  54. package/src/Vue.ts +233 -229
  55. package/src/WindowApi.ts +59 -59
  56. package/src/ajaxHooker/ajaxHooker.js +1 -0
  57. package/src/indexedDB.ts +497 -502
  58. package/src/types/Event.d.ts +188 -188
  59. package/src/types/Httpx.d.ts +1344 -1343
  60. package/src/types/Log.d.ts +19 -19
  61. package/src/types/Progress.d.ts +20 -20
  62. package/src/types/React.d.ts +119 -119
  63. package/src/types/TryCatch.d.ts +9 -9
  64. package/src/types/UtilsGMCookie.d.ts +93 -93
  65. package/src/types/UtilsGMMenu.d.ts +77 -77
  66. package/src/types/Vue2.d.ts +166 -166
  67. package/src/types/WindowApi.d.ts +14 -14
  68. package/src/types/ajaxHooker.d.ts +151 -151
  69. package/src/types/env.d.ts +7 -2
  70. package/src/types/global.d.ts +31 -31
package/src/Dictionary.ts CHANGED
@@ -1,154 +1,153 @@
1
- export class UtilsDictionary<K extends unknown, V extends any> {
2
- private items: Map<K, V>;
3
- constructor();
4
- constructor(key: K, value: V);
5
- constructor(key?: K, value?: V) {
6
- this.items = new Map();
7
- if (key != null) {
8
- this.set(key, value!);
9
- }
10
- }
11
- /**
12
- * 获取字典的长度,同this.size
13
- */
14
- get length() {
15
- return this.size();
16
- }
17
- /**
18
- * 迭代器
19
- */
20
- get entries() {
21
- let that = this;
22
- return function* (): IterableIterator<[K, V]> {
23
- let itemKeys = Object.keys(that.getItems());
24
- for (const keyName of itemKeys) {
25
- yield [keyName as K, that.get(keyName as K) as V];
26
- }
27
- };
28
- }
29
- /**
30
- * 是否可遍历
31
- */
32
- get [Symbol.iterator]() {
33
- let that = this;
34
- return function () {
35
- return that.entries();
36
- };
37
- }
38
- /**
39
- * 检查是否有某一个键
40
- * @param key 键
41
- */
42
- has(key: K): boolean {
43
- return this.items.has(key);
44
- }
45
- /**
46
- * 获取某个键的值
47
- * https://github.com/microsoft/TypeScript/issues/9619
48
- * 微软到现在都没有实现has和get的联动
49
- * @param key 键
50
- */
51
- get(key: K): V {
52
- return this.items.get(key) as V;
53
- }
54
- /**
55
- * 为字典添加某一个值
56
- * @param key
57
- * @param val 值,默认为""
58
- */
59
- set(key: K, val: V): void {
60
- if (key === void 0) {
61
- throw new Error("Utils.Dictionary().set 参数 key 不能为空");
62
- }
63
- this.items.set(key, val);
64
- }
65
- /**
66
- * 删除某一个键
67
- * @param key 键
68
- * @returns
69
- * + true:键存在且成功删除
70
- * + false:键不存在
71
- */
72
- delete(key: K): boolean {
73
- if (this.has(key)) {
74
- return this.items.delete(key);
75
- }
76
- return false;
77
- }
78
- /**
79
- * 获取字典所有的键
80
- */
81
- keys(): K[] {
82
- return this.items.keys().toArray();
83
- }
84
- /**
85
- * 返回字典中的所有值
86
- */
87
- values(): V[] {
88
- return this.items.values().toArray();
89
- }
90
- /**
91
- * 清空字典
92
- */
93
- clear() {
94
- this.items.clear();
95
- }
96
- /**
97
- * 获取字典的长度
98
- */
99
- size(): number {
100
- return this.items.size;
101
- }
102
- /**
103
- * 返回字典本身
104
- */
105
- getItems() {
106
- return this.items;
107
- }
108
- /**
109
- * 合并另一个字典
110
- * @param data 需要合并的字典
111
- */
112
- concat(data: UtilsDictionary<K, V>) {
113
- data.forEach((value, key) => {
114
- this.items.set(key, value);
115
- });
116
- }
117
- /**
118
- * 迭代字典
119
- * @param callbackfn 回调函数
120
- */
121
- forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
122
- this.items.forEach((value, key, self) => {
123
- callbackfn(value, key, this);
124
- });
125
- }
126
- /**
127
- * 检查已有的键中是否以xx开头
128
- * @param key 需要匹配的键
129
- */
130
- startsWith(key: string): boolean {
131
- const keys = this.keys();
132
- for (const keyName of keys) {
133
- if (String(keyName).startsWith(key)) {
134
- return true;
135
- }
136
- }
137
- return false;
138
- }
139
- /**
140
- * 获取以xx开头的键的值
141
- * @param key 需要匹配的键
142
- */
143
- getStartsWith(key: K): V | undefined {
144
- let result: V | undefined = void 0;
145
- const keys = this.keys();
146
- for (const keyName of keys) {
147
- if (String(keyName).startsWith(String(key))) {
148
- result = this.get(keyName as K);
149
- break;
150
- }
151
- }
152
- return result;
153
- }
154
- }
1
+ export class UtilsDictionary<K, V> {
2
+ private items: Map<K, V>;
3
+ constructor();
4
+ constructor(key: K, value: V);
5
+ constructor(key?: K, value?: V) {
6
+ this.items = new Map();
7
+ if (key != null) {
8
+ this.set(key, value!);
9
+ }
10
+ }
11
+ /**
12
+ * 获取字典的长度,同this.size
13
+ */
14
+ get length() {
15
+ return this.size();
16
+ }
17
+ /**
18
+ * 迭代器
19
+ */
20
+ get entries() {
21
+ const that = this;
22
+ return function* (): IterableIterator<[K, V]> {
23
+ const itemKeys = Object.keys(that.getItems());
24
+ for (const keyName of itemKeys) {
25
+ yield [keyName as K, that.get(keyName as K) as V];
26
+ }
27
+ };
28
+ }
29
+ /**
30
+ * 是否可遍历
31
+ */
32
+ get [Symbol.iterator]() {
33
+ return () => {
34
+ return this.entries();
35
+ };
36
+ }
37
+ /**
38
+ * 检查是否有某一个键
39
+ * @param key 键
40
+ */
41
+ has(key: K): boolean {
42
+ return this.items.has(key);
43
+ }
44
+ /**
45
+ * 获取某个键的值
46
+ * https://github.com/microsoft/TypeScript/issues/9619
47
+ * 微软到现在都没有实现has和get的联动
48
+ * @param key 键
49
+ */
50
+ get(key: K): V {
51
+ return this.items.get(key) as V;
52
+ }
53
+ /**
54
+ * 为字典添加某一个值
55
+ * @param key 键
56
+ * @param val 值,默认为""
57
+ */
58
+ set(key: K, val: V): void {
59
+ if (key === void 0) {
60
+ throw new Error("Utils.Dictionary().set 参数 key 不能为空");
61
+ }
62
+ this.items.set(key, val);
63
+ }
64
+ /**
65
+ * 删除某一个键
66
+ * @param key 键
67
+ * @returns
68
+ * + true:键存在且成功删除
69
+ * + false:键不存在
70
+ */
71
+ delete(key: K): boolean {
72
+ if (this.has(key)) {
73
+ return this.items.delete(key);
74
+ }
75
+ return false;
76
+ }
77
+ /**
78
+ * 获取字典所有的键
79
+ */
80
+ keys(): K[] {
81
+ return Array.from(this.items.keys());
82
+ }
83
+ /**
84
+ * 返回字典中的所有值
85
+ */
86
+ values(): V[] {
87
+ return Array.from(this.items.values());
88
+ }
89
+ /**
90
+ * 清空字典
91
+ */
92
+ clear() {
93
+ this.items.clear();
94
+ }
95
+ /**
96
+ * 获取字典的长度
97
+ */
98
+ size(): number {
99
+ return this.items.size;
100
+ }
101
+ /**
102
+ * 返回字典本身
103
+ */
104
+ getItems() {
105
+ return this.items;
106
+ }
107
+ /**
108
+ * 合并另一个字典
109
+ * @param data 需要合并的字典
110
+ */
111
+ concat(data: UtilsDictionary<K, V>) {
112
+ data.forEach((value, key) => {
113
+ this.items.set(key, value);
114
+ });
115
+ }
116
+ /**
117
+ * 迭代字典
118
+ * @param callbackfn 回调函数
119
+ */
120
+ forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
121
+ this.items.forEach((value, key) => {
122
+ callbackfn(value, key, this);
123
+ });
124
+ }
125
+ /**
126
+ * 检查已有的键中是否以xx开头
127
+ * @param key 需要匹配的键
128
+ */
129
+ startsWith(key: string): boolean {
130
+ const keys = this.keys();
131
+ for (const keyName of keys) {
132
+ if (String(keyName).startsWith(key)) {
133
+ return true;
134
+ }
135
+ }
136
+ return false;
137
+ }
138
+ /**
139
+ * 获取以xx开头的键的值
140
+ * @param key 需要匹配的键
141
+ */
142
+ getStartsWith(key: K): V | undefined {
143
+ let result: V | undefined = void 0;
144
+ const keys = this.keys();
145
+ for (const keyName of keys) {
146
+ if (String(keyName).startsWith(String(key))) {
147
+ result = this.get(keyName as K);
148
+ break;
149
+ }
150
+ }
151
+ return result;
152
+ }
153
+ }