@whitesev/utils 2.11.12 → 2.11.14
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 +16 -4
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +16 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +16 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +16 -4
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +16 -4
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +16 -4
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Dictionary.d.ts +13 -2
- package/dist/types/src/types/ajaxHooker.d.ts +98 -7
- package/package.json +1 -1
- package/src/Dictionary.ts +24 -3
- package/src/types/ajaxHooker.d.ts +98 -7
|
@@ -83,9 +83,20 @@ export declare class UtilsDictionary<K, V> {
|
|
|
83
83
|
concat(data: UtilsDictionary<K, V>): void;
|
|
84
84
|
/**
|
|
85
85
|
* 迭代字典
|
|
86
|
-
* @param
|
|
86
|
+
* @param cb 回调函数
|
|
87
87
|
*/
|
|
88
|
-
forEach(
|
|
88
|
+
forEach(cb: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void): void;
|
|
89
|
+
/**
|
|
90
|
+
* 找到字典中对应的键和值
|
|
91
|
+
* @param cb 回调函数
|
|
92
|
+
*/
|
|
93
|
+
find(cb: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => {
|
|
94
|
+
key: K;
|
|
95
|
+
value: V;
|
|
96
|
+
} | void): {
|
|
97
|
+
key: K;
|
|
98
|
+
value: V;
|
|
99
|
+
} | undefined;
|
|
89
100
|
/**
|
|
90
101
|
* 检查已有的键中是否以xx开头
|
|
91
102
|
* @param key 需要匹配的键
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { HttpxHeaders, HttpxMethod, HttpxStatus } from "./Httpx";
|
|
2
2
|
|
|
3
|
+
export declare type UtilsAjaxHookType = "xhr" | "fetch";
|
|
4
|
+
|
|
3
5
|
/** 请求的response配置 */
|
|
4
6
|
export declare interface UtilsAjaxHookResponseOptions {
|
|
5
7
|
/**
|
|
@@ -24,12 +26,92 @@ export declare interface UtilsAjaxHookResponseOptions {
|
|
|
24
26
|
responseText?: string;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* 额外属性
|
|
31
|
+
*
|
|
32
|
+
* 你可以在request对象上添加新属性,只要该属性被对应的type所支持,修改就能直接生效。
|
|
33
|
+
*
|
|
34
|
+
* 这些属性未作为request对象的标准属性,是因为xhr和fetch的接口设计有较大差异,库不主动读取这些属性的值,仅保留修改能力。
|
|
35
|
+
*/
|
|
36
|
+
export declare type UtilsAjaxHookRequestExtraOptions_xhr = {
|
|
37
|
+
/**
|
|
38
|
+
* The XMLHttpRequest property **`responseType`** is an enumerated string value specifying the type of data contained in the response.
|
|
39
|
+
*
|
|
40
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/responseType)
|
|
41
|
+
*/
|
|
42
|
+
responseType: XMLHttpRequest["responseType"];
|
|
43
|
+
/**
|
|
44
|
+
* The **`XMLHttpRequest.timeout`** property is an unsigned long representing the number of milliseconds a request can take before automatically being terminated. The default value is 0, which means there is no timeout. Timeout shouldn't be used for synchronous XMLHttpRequests requests used in a document environment or it will throw an InvalidAccessError exception. When a timeout happens, a timeout event is fired.
|
|
45
|
+
*
|
|
46
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/timeout)
|
|
47
|
+
*/
|
|
48
|
+
timeout: XMLHttpRequest["timeout"];
|
|
49
|
+
/**
|
|
50
|
+
* The **`XMLHttpRequest.withCredentials`** property is a boolean value that indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authentication headers or TLS client certificates. Setting withCredentials has no effect on same-origin requests.
|
|
51
|
+
*
|
|
52
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/withCredentials)
|
|
53
|
+
*/
|
|
54
|
+
withCredentials: XMLHttpRequest["withCredentials"];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 额外属性
|
|
59
|
+
*
|
|
60
|
+
* 你可以在request对象上添加新属性,只要该属性被对应的type所支持,修改就能直接生效。
|
|
61
|
+
*
|
|
62
|
+
* 这些属性未作为request对象的标准属性,是因为xhr和fetch的接口设计有较大差异,库不主动读取这些属性的值,仅保留修改能力。
|
|
63
|
+
*/
|
|
64
|
+
export declare type UtilsAjaxHookRequestExtraOptions_fetch = {
|
|
65
|
+
/**
|
|
66
|
+
* 一个字符串,指示请求如何与浏览器的缓存交互以设置请求的缓存。
|
|
67
|
+
*/
|
|
68
|
+
cache: RequestInit["cache"];
|
|
69
|
+
/**
|
|
70
|
+
* 一个字符串,指示凭据是始终、从不还是仅在发送到同源 URL 时随请求一起发送。设置请求的凭据。
|
|
71
|
+
*/
|
|
72
|
+
credentials: RequestInit["credentials"];
|
|
73
|
+
/**
|
|
74
|
+
* 要按请求获取的资源的加密哈希值。设置请求的完整性。
|
|
75
|
+
*/
|
|
76
|
+
integrity: RequestInit["integrity"];
|
|
77
|
+
/**
|
|
78
|
+
* 用于设置请求保持活动的布尔值。
|
|
79
|
+
*/
|
|
80
|
+
keepalive: RequestInit["keepalive"];
|
|
81
|
+
/**
|
|
82
|
+
* 一个字符串来指示请求是使用CORS,还是仅限于相同的Origin URL。设置请求模式。
|
|
83
|
+
*/
|
|
84
|
+
mode: RequestInit["mode"];
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
*/
|
|
88
|
+
priority: RequestInit["priority"];
|
|
89
|
+
/**
|
|
90
|
+
* 指示请求是否遵循重定向、在遇到重定向时导致错误或返回重定向(以不透明方式)的字符串。设置请求的重定向。
|
|
91
|
+
*/
|
|
92
|
+
redirect: RequestInit["redirect"];
|
|
93
|
+
/**
|
|
94
|
+
* 一个字符串,其值为同源 URL、“about:client”或空字符串,用于设置请求的引荐来源网址。
|
|
95
|
+
*/
|
|
96
|
+
referrer: RequestInit["referrer"];
|
|
97
|
+
/**
|
|
98
|
+
* 用于设置请求的referrerPolicy 的引用策略。
|
|
99
|
+
*/
|
|
100
|
+
referrerPolicy: RequestInit["referrerPolicy"];
|
|
101
|
+
/**
|
|
102
|
+
* 用于设置请求信号的 AbortSignal。
|
|
103
|
+
*/
|
|
104
|
+
signal: RequestInit["signal"];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* hook到的请求的配置
|
|
109
|
+
*/
|
|
110
|
+
export declare type UtilsAjaxHookRequestOption<T extends UtilsAjaxHookType = UtilsAjaxHookType> = {
|
|
29
111
|
/**
|
|
30
112
|
* 只读属性。一个字符串,表明请求类型是xhr还是fetch
|
|
31
113
|
*/
|
|
32
|
-
type:
|
|
114
|
+
readonly type: T;
|
|
33
115
|
/**
|
|
34
116
|
* 请求的Url
|
|
35
117
|
*/
|
|
@@ -63,8 +145,17 @@ export declare interface UtilsAjaxHookRequestOptions {
|
|
|
63
145
|
/**
|
|
64
146
|
* 只读属性。异步请求为true,同步请求为false,异步特性无法作用于同步请求
|
|
65
147
|
*/
|
|
66
|
-
async: boolean;
|
|
67
|
-
}
|
|
148
|
+
readonly async: boolean;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* hook请求的配置
|
|
153
|
+
*/
|
|
154
|
+
export declare type UtilsAjaxHookRequestOptions<T extends UtilsAjaxHookType = UtilsAjaxHookType> = T extends "xhr"
|
|
155
|
+
? UtilsAjaxHookRequestExtraOptions_xhr & UtilsAjaxHookRequestOption<T>
|
|
156
|
+
: T extends "fetch"
|
|
157
|
+
? UtilsAjaxHookRequestExtraOptions_fetch & UtilsAjaxHookRequestOption<T>
|
|
158
|
+
: UtilsAjaxHookRequestOption<T>;
|
|
68
159
|
|
|
69
160
|
/** 过滤规则配置 */
|
|
70
161
|
export declare interface UtilsAjaxHookFilterOptions {
|
|
@@ -136,7 +227,7 @@ export declare interface UtilsAjaxHookResult {
|
|
|
136
227
|
) => void | undefined | null | Promise<void | undefined | null>
|
|
137
228
|
): {
|
|
138
229
|
/**
|
|
139
|
-
*
|
|
230
|
+
* 移除添加的hook(该函数是额外添加的,原版仅返回空值)
|
|
140
231
|
*/
|
|
141
232
|
remove: () => boolean;
|
|
142
233
|
};
|
|
@@ -154,7 +245,7 @@ export declare interface UtilsAjaxHookResult {
|
|
|
154
245
|
*/
|
|
155
246
|
filter(filterOptions: UtilsAjaxHookFilterOptions[]): {
|
|
156
247
|
/**
|
|
157
|
-
*
|
|
248
|
+
* 移除添加的filter(该函数是额外添加的,原版仅返回空值)
|
|
158
249
|
*/
|
|
159
250
|
remove: () => void;
|
|
160
251
|
};
|
package/package.json
CHANGED
package/src/Dictionary.ts
CHANGED
|
@@ -167,13 +167,34 @@ export class UtilsDictionary<K, V> {
|
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
169
|
* 迭代字典
|
|
170
|
-
* @param
|
|
170
|
+
* @param cb 回调函数
|
|
171
171
|
*/
|
|
172
|
-
forEach(
|
|
172
|
+
forEach(cb: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
|
|
173
173
|
this.items.forEach((value, key) => {
|
|
174
|
-
|
|
174
|
+
cb(value, key, this);
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* 找到字典中对应的键和值
|
|
179
|
+
* @param cb 回调函数
|
|
180
|
+
*/
|
|
181
|
+
find(
|
|
182
|
+
cb: (
|
|
183
|
+
value: V,
|
|
184
|
+
key: K,
|
|
185
|
+
dictionary: UtilsDictionary<K, V>
|
|
186
|
+
) => {
|
|
187
|
+
key: K;
|
|
188
|
+
value: V;
|
|
189
|
+
} | void
|
|
190
|
+
) {
|
|
191
|
+
for (const [key, value] of this.items.entries()) {
|
|
192
|
+
const result = cb(value, key, this);
|
|
193
|
+
if (result) {
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
177
198
|
/**
|
|
178
199
|
* 检查已有的键中是否以xx开头
|
|
179
200
|
* @param key 需要匹配的键
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { HttpxHeaders, HttpxMethod, HttpxStatus } from "./Httpx";
|
|
2
2
|
|
|
3
|
+
export declare type UtilsAjaxHookType = "xhr" | "fetch";
|
|
4
|
+
|
|
3
5
|
/** 请求的response配置 */
|
|
4
6
|
export declare interface UtilsAjaxHookResponseOptions {
|
|
5
7
|
/**
|
|
@@ -24,12 +26,92 @@ export declare interface UtilsAjaxHookResponseOptions {
|
|
|
24
26
|
responseText?: string;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* 额外属性
|
|
31
|
+
*
|
|
32
|
+
* 你可以在request对象上添加新属性,只要该属性被对应的type所支持,修改就能直接生效。
|
|
33
|
+
*
|
|
34
|
+
* 这些属性未作为request对象的标准属性,是因为xhr和fetch的接口设计有较大差异,库不主动读取这些属性的值,仅保留修改能力。
|
|
35
|
+
*/
|
|
36
|
+
export declare type UtilsAjaxHookRequestExtraOptions_xhr = {
|
|
37
|
+
/**
|
|
38
|
+
* The XMLHttpRequest property **`responseType`** is an enumerated string value specifying the type of data contained in the response.
|
|
39
|
+
*
|
|
40
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/responseType)
|
|
41
|
+
*/
|
|
42
|
+
responseType: XMLHttpRequest["responseType"];
|
|
43
|
+
/**
|
|
44
|
+
* The **`XMLHttpRequest.timeout`** property is an unsigned long representing the number of milliseconds a request can take before automatically being terminated. The default value is 0, which means there is no timeout. Timeout shouldn't be used for synchronous XMLHttpRequests requests used in a document environment or it will throw an InvalidAccessError exception. When a timeout happens, a timeout event is fired.
|
|
45
|
+
*
|
|
46
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/timeout)
|
|
47
|
+
*/
|
|
48
|
+
timeout: XMLHttpRequest["timeout"];
|
|
49
|
+
/**
|
|
50
|
+
* The **`XMLHttpRequest.withCredentials`** property is a boolean value that indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authentication headers or TLS client certificates. Setting withCredentials has no effect on same-origin requests.
|
|
51
|
+
*
|
|
52
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/withCredentials)
|
|
53
|
+
*/
|
|
54
|
+
withCredentials: XMLHttpRequest["withCredentials"];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 额外属性
|
|
59
|
+
*
|
|
60
|
+
* 你可以在request对象上添加新属性,只要该属性被对应的type所支持,修改就能直接生效。
|
|
61
|
+
*
|
|
62
|
+
* 这些属性未作为request对象的标准属性,是因为xhr和fetch的接口设计有较大差异,库不主动读取这些属性的值,仅保留修改能力。
|
|
63
|
+
*/
|
|
64
|
+
export declare type UtilsAjaxHookRequestExtraOptions_fetch = {
|
|
65
|
+
/**
|
|
66
|
+
* 一个字符串,指示请求如何与浏览器的缓存交互以设置请求的缓存。
|
|
67
|
+
*/
|
|
68
|
+
cache: RequestInit["cache"];
|
|
69
|
+
/**
|
|
70
|
+
* 一个字符串,指示凭据是始终、从不还是仅在发送到同源 URL 时随请求一起发送。设置请求的凭据。
|
|
71
|
+
*/
|
|
72
|
+
credentials: RequestInit["credentials"];
|
|
73
|
+
/**
|
|
74
|
+
* 要按请求获取的资源的加密哈希值。设置请求的完整性。
|
|
75
|
+
*/
|
|
76
|
+
integrity: RequestInit["integrity"];
|
|
77
|
+
/**
|
|
78
|
+
* 用于设置请求保持活动的布尔值。
|
|
79
|
+
*/
|
|
80
|
+
keepalive: RequestInit["keepalive"];
|
|
81
|
+
/**
|
|
82
|
+
* 一个字符串来指示请求是使用CORS,还是仅限于相同的Origin URL。设置请求模式。
|
|
83
|
+
*/
|
|
84
|
+
mode: RequestInit["mode"];
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
*/
|
|
88
|
+
priority: RequestInit["priority"];
|
|
89
|
+
/**
|
|
90
|
+
* 指示请求是否遵循重定向、在遇到重定向时导致错误或返回重定向(以不透明方式)的字符串。设置请求的重定向。
|
|
91
|
+
*/
|
|
92
|
+
redirect: RequestInit["redirect"];
|
|
93
|
+
/**
|
|
94
|
+
* 一个字符串,其值为同源 URL、“about:client”或空字符串,用于设置请求的引荐来源网址。
|
|
95
|
+
*/
|
|
96
|
+
referrer: RequestInit["referrer"];
|
|
97
|
+
/**
|
|
98
|
+
* 用于设置请求的referrerPolicy 的引用策略。
|
|
99
|
+
*/
|
|
100
|
+
referrerPolicy: RequestInit["referrerPolicy"];
|
|
101
|
+
/**
|
|
102
|
+
* 用于设置请求信号的 AbortSignal。
|
|
103
|
+
*/
|
|
104
|
+
signal: RequestInit["signal"];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* hook到的请求的配置
|
|
109
|
+
*/
|
|
110
|
+
export declare type UtilsAjaxHookRequestOption<T extends UtilsAjaxHookType = UtilsAjaxHookType> = {
|
|
29
111
|
/**
|
|
30
112
|
* 只读属性。一个字符串,表明请求类型是xhr还是fetch
|
|
31
113
|
*/
|
|
32
|
-
type:
|
|
114
|
+
readonly type: T;
|
|
33
115
|
/**
|
|
34
116
|
* 请求的Url
|
|
35
117
|
*/
|
|
@@ -63,8 +145,17 @@ export declare interface UtilsAjaxHookRequestOptions {
|
|
|
63
145
|
/**
|
|
64
146
|
* 只读属性。异步请求为true,同步请求为false,异步特性无法作用于同步请求
|
|
65
147
|
*/
|
|
66
|
-
async: boolean;
|
|
67
|
-
}
|
|
148
|
+
readonly async: boolean;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* hook请求的配置
|
|
153
|
+
*/
|
|
154
|
+
export declare type UtilsAjaxHookRequestOptions<T extends UtilsAjaxHookType = UtilsAjaxHookType> = T extends "xhr"
|
|
155
|
+
? UtilsAjaxHookRequestExtraOptions_xhr & UtilsAjaxHookRequestOption<T>
|
|
156
|
+
: T extends "fetch"
|
|
157
|
+
? UtilsAjaxHookRequestExtraOptions_fetch & UtilsAjaxHookRequestOption<T>
|
|
158
|
+
: UtilsAjaxHookRequestOption<T>;
|
|
68
159
|
|
|
69
160
|
/** 过滤规则配置 */
|
|
70
161
|
export declare interface UtilsAjaxHookFilterOptions {
|
|
@@ -136,7 +227,7 @@ export declare interface UtilsAjaxHookResult {
|
|
|
136
227
|
) => void | undefined | null | Promise<void | undefined | null>
|
|
137
228
|
): {
|
|
138
229
|
/**
|
|
139
|
-
*
|
|
230
|
+
* 移除添加的hook(该函数是额外添加的,原版仅返回空值)
|
|
140
231
|
*/
|
|
141
232
|
remove: () => boolean;
|
|
142
233
|
};
|
|
@@ -154,7 +245,7 @@ export declare interface UtilsAjaxHookResult {
|
|
|
154
245
|
*/
|
|
155
246
|
filter(filterOptions: UtilsAjaxHookFilterOptions[]): {
|
|
156
247
|
/**
|
|
157
|
-
*
|
|
248
|
+
* 移除添加的filter(该函数是额外添加的,原版仅返回空值)
|
|
158
249
|
*/
|
|
159
250
|
remove: () => void;
|
|
160
251
|
};
|