@whitesev/utils 2.8.1 → 2.9.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 (74) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +271 -777
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +2 -0
  5. package/dist/index.amd.min.js.map +1 -0
  6. package/dist/index.cjs.js +271 -777
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +2 -0
  9. package/dist/index.cjs.min.js.map +1 -0
  10. package/dist/index.esm.js +271 -777
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +2 -0
  13. package/dist/index.esm.min.js.map +1 -0
  14. package/dist/index.iife.js +271 -777
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +2 -0
  17. package/dist/index.iife.min.js.map +1 -0
  18. package/dist/index.system.js +271 -777
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +2 -0
  21. package/dist/index.system.min.js.map +1 -0
  22. package/dist/index.umd.js +271 -777
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +2 -0
  25. package/dist/index.umd.min.js.map +1 -0
  26. package/dist/types/src/Utils.d.ts +103 -450
  27. package/dist/types/src/UtilsGMCookie.d.ts +4 -0
  28. package/dist/types/src/UtilsGMMenu.d.ts +3 -6
  29. package/dist/types/src/types/Httpx.d.ts +1344 -1344
  30. package/dist/types/src/types/Log.d.ts +19 -19
  31. package/dist/types/src/types/Progress.d.ts +20 -20
  32. package/dist/types/src/types/React.d.ts +119 -119
  33. package/dist/types/src/types/TryCatch.d.ts +9 -9
  34. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  35. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  36. package/dist/types/src/types/Vue2.d.ts +166 -166
  37. package/dist/types/src/types/WindowApi.d.ts +14 -14
  38. package/dist/types/src/types/ajaxHooker.d.ts +151 -151
  39. package/dist/types/src/types/env.d.ts +7 -7
  40. package/dist/types/src/types/global.d.ts +31 -31
  41. package/index.ts +3 -0
  42. package/package.json +16 -10
  43. package/src/ColorConversion.ts +105 -105
  44. package/src/CommonUtil.ts +280 -280
  45. package/src/DOMUtils.ts +251 -251
  46. package/src/Dictionary.ts +153 -153
  47. package/src/GBKEncoder.ts +108 -108
  48. package/src/Hooks.ts +73 -73
  49. package/src/Httpx.ts +1457 -1457
  50. package/src/LockFunction.ts +62 -62
  51. package/src/Log.ts +258 -258
  52. package/src/Progress.ts +108 -108
  53. package/src/TryCatch.ts +86 -86
  54. package/src/Utils.ts +3778 -4772
  55. package/src/UtilsCommon.ts +14 -14
  56. package/src/UtilsGMCookie.ts +272 -254
  57. package/src/UtilsGMMenu.ts +441 -445
  58. package/src/Vue.ts +233 -233
  59. package/src/WindowApi.ts +59 -59
  60. package/src/indexedDB.ts +497 -497
  61. package/src/types/Httpx.d.ts +1344 -1344
  62. package/src/types/Log.d.ts +19 -19
  63. package/src/types/Progress.d.ts +20 -20
  64. package/src/types/React.d.ts +119 -119
  65. package/src/types/TryCatch.d.ts +9 -9
  66. package/src/types/UtilsGMCookie.d.ts +93 -93
  67. package/src/types/UtilsGMMenu.d.ts +77 -77
  68. package/src/types/Vue2.d.ts +166 -166
  69. package/src/types/WindowApi.d.ts +14 -14
  70. package/src/types/ajaxHooker.d.ts +151 -151
  71. package/src/types/env.d.ts +7 -7
  72. package/src/types/global.d.ts +31 -31
  73. package/dist/types/src/types/Event.d.ts +0 -188
  74. package/src/types/Event.d.ts +0 -188
package/src/Dictionary.ts CHANGED
@@ -1,153 +1,153 @@
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
- }
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
+ }