@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.
package/src/Utils.ts CHANGED
@@ -31,7 +31,7 @@ class Utils {
31
31
  this.windowApi = new WindowApi(option);
32
32
  }
33
33
  /** 版本号 */
34
- version = "2025.3.25";
34
+ version = "2025.4.11";
35
35
 
36
36
  /**
37
37
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -5197,6 +5197,22 @@ class Utils {
5197
5197
  }
5198
5198
  return new URL(text);
5199
5199
  }
5200
+ /**
5201
+ * 覆盖对象中的函数this指向
5202
+ * @param target 需要覆盖的对象
5203
+ * @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
5204
+ */
5205
+ coverObjectFunctionThis(target: any, objectThis?: any) {
5206
+ if (typeof target !== "object" || target === null) {
5207
+ throw new Error("target must be object");
5208
+ }
5209
+ objectThis = objectThis || target;
5210
+ Object.keys(target).forEach((key) => {
5211
+ if (typeof target[key] === "function") {
5212
+ target[key] = target[key].bind(objectThis);
5213
+ }
5214
+ });
5215
+ }
5200
5216
  /**
5201
5217
  * 生成uuid
5202
5218
  * @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
+ }