@whitesev/utils 2.4.3 → 2.4.5

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.
@@ -1698,6 +1698,23 @@ declare class Utils {
1698
1698
  * > 111;
1699
1699
  */
1700
1700
  watchObject(target: any, propertyName: string, getCallBack: (value: any) => void, setCallBack: (value: any) => void): void;
1701
+ /**
1702
+ * 深度获取对象属性
1703
+ * @param target 待获取的对象
1704
+ * @param handler 获取属性的回调
1705
+ */
1706
+ queryProperty(target: any, handler: (target: any) => {
1707
+ /**
1708
+ * 是否是需要的属性
1709
+ * + true 将目标值赋值给data
1710
+ * + false 不是需要的,data为下一个处理的对象
1711
+ */
1712
+ isFind: boolean;
1713
+ /**
1714
+ * 对象/目标值
1715
+ */
1716
+ data: any;
1717
+ }): any;
1701
1718
  /**
1702
1719
  * 创建一个新的Utils实例
1703
1720
  * @param option
@@ -1241,10 +1241,9 @@ export declare interface HttpxResponseData<T extends HttpxRequestOption> {
1241
1241
  /**
1242
1242
  * 响应内容,根据responseType,如果是html,那就是Document类型,如果是json,那么类型是Object类型
1243
1243
  */
1244
- // @ts-ignore
1245
- response: HttpxResponseTypeMap[T["responseType"]] extends unknown
1246
- ? HttpxResponseTypeMap["html"]
1247
- : T["responseType"];
1244
+ response: T["responseType"] extends keyof HttpxResponseTypeMap
1245
+ ? HttpxResponseTypeMap[T["responseType"]]
1246
+ : HttpxResponseTypeMap["html"];
1248
1247
  /**
1249
1248
  * 当请求头fetch为true时,该属性存在
1250
1249
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.4.3",
3
+ "version": "2.4.5",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Httpx.ts CHANGED
@@ -1392,7 +1392,7 @@ class Httpx {
1392
1392
  * @param url 网址
1393
1393
  * @param details 配置
1394
1394
  */
1395
- post<T extends HttpxRequestOption>(
1395
+ post<T = HttpxRequestOption>(
1396
1396
  url: string,
1397
1397
  details: T // @ts-ignore
1398
1398
  ): HttpxPromise<HttpxResponse<T>>;
package/src/Utils.ts CHANGED
@@ -29,7 +29,7 @@ class Utils {
29
29
  this.windowApi = new WindowApi(option);
30
30
  }
31
31
  /** 版本号 */
32
- version = "2024.10.31";
32
+ version = "2024.11.1";
33
33
 
34
34
  /**
35
35
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -4939,6 +4939,40 @@ class Utils {
4939
4939
  }
4940
4940
  }
4941
4941
 
4942
+ /**
4943
+ * 深度获取对象属性
4944
+ * @param target 待获取的对象
4945
+ * @param handler 获取属性的回调
4946
+ */
4947
+ queryProperty(
4948
+ target: any,
4949
+ handler: (target: any) => {
4950
+ /**
4951
+ * 是否是需要的属性
4952
+ * + true 将目标值赋值给data
4953
+ * + false 不是需要的,data为下一个处理的对象
4954
+ */
4955
+ isFind: boolean;
4956
+ /**
4957
+ * 对象/目标值
4958
+ */
4959
+ data: any;
4960
+ }
4961
+ ): any {
4962
+ if (target == null) {
4963
+ return;
4964
+ }
4965
+ let handleResult = handler(target);
4966
+ if (
4967
+ handleResult &&
4968
+ typeof handleResult.isFind === "boolean" &&
4969
+ handleResult.isFind
4970
+ ) {
4971
+ return handleResult.data;
4972
+ }
4973
+ return this.queryProperty(handleResult.data, handler);
4974
+ }
4975
+
4942
4976
  /**
4943
4977
  * 创建一个新的Utils实例
4944
4978
  * @param option
@@ -1241,10 +1241,9 @@ export declare interface HttpxResponseData<T extends HttpxRequestOption> {
1241
1241
  /**
1242
1242
  * 响应内容,根据responseType,如果是html,那就是Document类型,如果是json,那么类型是Object类型
1243
1243
  */
1244
- // @ts-ignore
1245
- response: HttpxResponseTypeMap[T["responseType"]] extends unknown
1246
- ? HttpxResponseTypeMap["html"]
1247
- : T["responseType"];
1244
+ response: T["responseType"] extends keyof HttpxResponseTypeMap
1245
+ ? HttpxResponseTypeMap[T["responseType"]]
1246
+ : HttpxResponseTypeMap["html"];
1248
1247
  /**
1249
1248
  * 当请求头fetch为true时,该属性存在
1250
1249
  */