@whitesev/utils 2.6.4 → 2.6.6

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.
@@ -1,4 +1,4 @@
1
- import type { HttpxHookErrorData, HttpxRequestOption, HttpxRequestOptionConfig, HttpxResponse, HttpxResponseData, HttpxPromise } from "./types/Httpx";
1
+ import type { HttpxHookErrorData, HttpxRequestOption, HttpxResponse, HttpxResponseData, HttpxPromise, HttpxInitOption } from "./types/Httpx";
2
2
  declare class Httpx {
3
3
  #private;
4
4
  private GM_Api;
@@ -8,15 +8,15 @@ declare class Httpx {
8
8
  private HttpxCallBack;
9
9
  private HttpxRequest;
10
10
  /**
11
- * 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
12
- * @param xmlHttpRequest
11
+ * 实例化
12
+ * @param option 初始化配置
13
13
  */
14
- constructor(xmlHttpRequest?: Function);
14
+ constructor(option?: Partial<HttpxInitOption>);
15
15
  /**
16
- * 覆盖全局配置
17
- * @param details 配置
16
+ * 覆盖当前配置
17
+ * @param option
18
18
  */
19
- config(details?: Partial<HttpxRequestOptionConfig>): void;
19
+ config(option?: Partial<HttpxInitOption>): void;
20
20
  /**
21
21
  * 拦截器
22
22
  */
@@ -166,5 +166,11 @@ declare class Httpx {
166
166
  * @param details 配置
167
167
  */
168
168
  put<T extends HttpxRequestOption>(url: string, details: T): HttpxPromise<HttpxResponse<T>>;
169
+ /**
170
+ * 发送请求
171
+ * @param details 配置
172
+ * @param beforeRequestOption 处理请求前的配置
173
+ */
174
+ request<T extends HttpxRequestOption>(details: T, beforeRequestOption?: (option: Required<T>) => void): HttpxPromise<HttpxResponse<T>>;
169
175
  }
170
176
  export { Httpx };
@@ -1799,6 +1799,12 @@ declare class Utils {
1799
1799
  * Utils.toUrl("/s?word=666");
1800
1800
  */
1801
1801
  toUrl(text: string): URL;
1802
+ /**
1803
+ * 覆盖对象中的函数this指向
1804
+ * @param target 需要覆盖的对象
1805
+ * @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
1806
+ */
1807
+ coverObjectFunctionThis(target: any, objectThis?: any): void;
1802
1808
  /**
1803
1809
  * 生成uuid
1804
1810
  * @example
@@ -62,6 +62,19 @@ export type HttpxStatus =
62
62
  | 510
63
63
  | 511;
64
64
 
65
+ /**
66
+ * HTTP WebDav的请求方法
67
+ * + https://blog.csdn.net/weixin_48421613/article/details/128611546
68
+ */
69
+ export type HttpxWebDavMethod =
70
+ | "PROPFIND"
71
+ | "PROPPATCH"
72
+ | "MKCOL"
73
+ | "MOVE"
74
+ | "COPY"
75
+ | "LOCK"
76
+ | "UNLOCK";
77
+
65
78
  /**
66
79
  * HTTP 请求方法
67
80
  * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods
@@ -75,7 +88,8 @@ export type HttpxMethod =
75
88
  | "CONNECT"
76
89
  | "OPTIONS"
77
90
  | "TRACE"
78
- | "PATCH";
91
+ | "PATCH"
92
+ | HttpxWebDavMethod;
79
93
 
80
94
  /**
81
95
  * 重定向参数
@@ -1196,12 +1210,7 @@ export declare interface HttpxRequestOption {
1196
1210
  /**
1197
1211
  * 自定义的配置请求
1198
1212
  */
1199
- export declare interface HttpxRequestOptionConfig extends HttpxRequestOption {
1200
- /**
1201
- * (可选)是否输出请求配置
1202
- */
1203
- logDetails?: boolean;
1204
- }
1213
+ export declare interface HttpxRequestOptionConfig extends HttpxInitOption {}
1205
1214
  /**
1206
1215
  * 响应的数据的data
1207
1216
  */
@@ -1320,3 +1329,26 @@ export declare interface HttpxHookErrorData {
1320
1329
  export declare interface HttpxPromise<T> extends Promise<T> {
1321
1330
  abort: () => void;
1322
1331
  }
1332
+
1333
+ /**
1334
+ * httpx的初始化配置
1335
+ */
1336
+ export declare interface HttpxInitOption extends HttpxRequestOption {
1337
+ /**
1338
+ * 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
1339
+ */
1340
+ xmlHttpRequest?: Function;
1341
+ /**
1342
+ * `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL。
1343
+ */
1344
+ baseURL?: string | undefined;
1345
+ /**
1346
+ * 重试次数
1347
+ * @default 0
1348
+ */
1349
+ retry?: number;
1350
+ /**
1351
+ * (可选)是否输出请求配置
1352
+ */
1353
+ logDetails?: boolean;
1354
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.6.4",
3
+ "version": "2.6.6",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",