@whitesev/utils 2.7.1 → 2.7.3

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 (53) hide show
  1. package/dist/index.amd.js +260 -409
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +260 -409
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +260 -409
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +260 -409
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +260 -409
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +260 -409
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/ColorConversion.d.ts +3 -8
  14. package/dist/types/src/Dictionary.d.ts +21 -14
  15. package/dist/types/src/GBKEncoder.d.ts +1 -2
  16. package/dist/types/src/Hooks.d.ts +1 -2
  17. package/dist/types/src/Httpx.d.ts +45 -46
  18. package/dist/types/src/LockFunction.d.ts +1 -2
  19. package/dist/types/src/Log.d.ts +1 -2
  20. package/dist/types/src/Progress.d.ts +1 -2
  21. package/dist/types/src/Utils.d.ts +30 -2
  22. package/dist/types/src/UtilsGMMenu.d.ts +1 -2
  23. package/dist/types/src/WindowApi.d.ts +1 -2
  24. package/dist/types/src/indexedDB.d.ts +1 -2
  25. package/dist/types/src/types/Event.d.ts +1 -2
  26. package/dist/types/src/types/Httpx.d.ts +75 -86
  27. package/dist/types/src/types/ajaxHooker.d.ts +1 -5
  28. package/dist/types/src/types/env.d.ts +2 -0
  29. package/dist/types/src/types/global.d.ts +3 -0
  30. package/package.json +1 -1
  31. package/src/ColorConversion.ts +13 -37
  32. package/src/CommonUtil.ts +8 -31
  33. package/src/DOMUtils.ts +9 -24
  34. package/src/Dictionary.ts +37 -38
  35. package/src/GBKEncoder.ts +9 -18
  36. package/src/Hooks.ts +2 -7
  37. package/src/Httpx.ts +257 -412
  38. package/src/LockFunction.ts +1 -3
  39. package/src/Log.ts +8 -26
  40. package/src/Progress.ts +3 -13
  41. package/src/TryCatch.ts +4 -12
  42. package/src/Utils.ts +233 -595
  43. package/src/UtilsCommon.ts +5 -9
  44. package/src/UtilsGMCookie.ts +1 -4
  45. package/src/UtilsGMMenu.ts +29 -51
  46. package/src/Vue.ts +6 -18
  47. package/src/WindowApi.ts +2 -5
  48. package/src/indexedDB.ts +11 -20
  49. package/src/types/Event.d.ts +1 -2
  50. package/src/types/Httpx.d.ts +75 -86
  51. package/src/types/ajaxHooker.d.ts +1 -5
  52. package/src/types/env.d.ts +2 -0
  53. package/src/types/global.d.ts +3 -0
@@ -66,14 +66,7 @@ export type HttpxStatus =
66
66
  * HTTP WebDav的请求方法
67
67
  * + https://blog.csdn.net/weixin_48421613/article/details/128611546
68
68
  */
69
- export type HttpxWebDavMethod =
70
- | "PROPFIND"
71
- | "PROPPATCH"
72
- | "MKCOL"
73
- | "MOVE"
74
- | "COPY"
75
- | "LOCK"
76
- | "UNLOCK";
69
+ export type HttpxWebDavMethod = "PROPFIND" | "PROPPATCH" | "MKCOL" | "MOVE" | "COPY" | "LOCK" | "UNLOCK";
77
70
 
78
71
  /**
79
72
  * HTTP 请求方法
@@ -99,21 +92,12 @@ export type HttpxRedirect = "follow" | "error" | "manual";
99
92
  /**
100
93
  * 二进制数据
101
94
  */
102
- export type HttpxBinary =
103
- | Uint8ArrayConstructor
104
- | ArrayBufferConstructor
105
- | DataViewConstructor
106
- | Blob
107
- | File;
95
+ export type HttpxBinary = Uint8ArrayConstructor | ArrayBufferConstructor | DataViewConstructor | Blob | File;
108
96
 
109
97
  /**
110
98
  * 触发的响应函数名
111
99
  */
112
- export type HttpxResponseCallBackType =
113
- | "onload"
114
- | "onerror"
115
- | "ontimeout"
116
- | "onabort";
100
+ export type HttpxResponseCallBackType = "onload" | "onerror" | "ontimeout" | "onabort";
117
101
 
118
102
  /**
119
103
  * 响应类型映射字典
@@ -1039,24 +1023,23 @@ export declare interface HttpxAllowInterceptConfig {
1039
1023
  */
1040
1024
  export declare interface HttpxRequestOption {
1041
1025
  /**
1042
- * 网址
1026
+ * 请求的url
1043
1027
  */
1044
- url?: string;
1028
+ url: string;
1045
1029
  /**
1046
1030
  * 请求方法
1047
1031
  * @default "GET"
1048
1032
  */
1049
1033
  method?: HttpxMethod;
1050
1034
  /**
1051
- * 超时时间,默认5000,可为空
1035
+ * 请求的超时时间
1052
1036
  *
1053
- * fetchtrue时,该值不生效
1037
+ * 当`fetch`为`true`时,该值不生效,也就是请求不会超时
1054
1038
  * @default 5000
1055
1039
  */
1056
1040
  timeout?: number;
1057
1041
  /**
1058
1042
  * 响应类型,默认document,可为空
1059
- *
1060
1043
  * @default "document"
1061
1044
  */
1062
1045
  responseType?: keyof HttpxResponseTypeMap;
@@ -1070,39 +1053,39 @@ export declare interface HttpxRequestOption {
1070
1053
  data?: string | FormData | object;
1071
1054
  /**
1072
1055
  * 是否自动对data进行处理
1073
- * @default true
1074
- * 处理以下请求类型
1075
- * + GET 自动进行URLSearchParams转换
1076
- * + HEAD 自动进行URLSearchParams转换
1077
- * + POST 处理Content-Type不为空的情况
1078
1056
  *
1079
- * application/json
1057
+ * ## 处理以下请求类型
1058
+ * + `GET` 自动进行`URLSearchParams`转换
1059
+ * + `HEAD` 自动进行`URLSearchParams`转换
1060
+ * + `POST` 处理`Content-Type`不为空的情况
1061
+ *
1062
+ * ### `application/json`
1080
1063
  *
1081
- * + string: 不做处理
1082
- * + FormData: 转为JSON并进行JSON.stringify处理
1083
- * + object: 进行JSON.stringify处理
1064
+ * + `string`: 不做处理
1065
+ * + `FormData`: 转为`JSON`并进行`JSON.stringify`处理
1066
+ * + `object`: 进行`JSON.stringify`处理
1084
1067
  *
1085
- * application/x-www-form-urlencoded
1068
+ * ### `application/x-www-form-urlencoded`
1086
1069
  *
1087
- * + string: 不做处理
1088
- * + FormData: 转为URLSearchParams,再转为string
1089
- * + object: 转为URLSearchParams,再转为string
1070
+ * + `string`: 不做处理
1071
+ * + `FormData`: 转为`URLSearchParams`,再转为`string`
1072
+ * + `object`: 转为`URLSearchParams`,再转为`string`
1090
1073
  *
1091
- * multipart/form-data
1092
- * (上传文件专用)
1093
- * + string: 不做处理
1094
- * + FormData: 移除Content-Type
1095
- * + object: 不做处理
1074
+ * ### `multipart/form-data`(上传文件专用)
1075
+ *
1076
+ * + `string`: 不做处理
1077
+ * + `FormData`: 移除`Content-Type`
1078
+ * + `object`: 不做处理
1079
+ * @default true
1096
1080
  */
1097
1081
  processData?: boolean;
1098
1082
  /**
1099
- * 当触发重定向的使用规则,默认follow,可为空
1100
- *
1083
+ * 当触发重定向的使用规则
1101
1084
  * @default "follow"
1102
1085
  */
1103
1086
  redirect?: HttpxRedirect;
1104
1087
  /**
1105
- * 自定义Cookie,可为空
1088
+ * 自定义的Cookie
1106
1089
  */
1107
1090
  cookie?: string;
1108
1091
  /**
@@ -1126,52 +1109,53 @@ export declare interface HttpxRequestOption {
1126
1109
  topLevelSite?: string;
1127
1110
  };
1128
1111
  /**
1129
- * 以二进制模式发送数据字符串,可为空
1112
+ * 以二进制模式发送数据字符串
1130
1113
  */
1131
1114
  binary?: HttpxBinary;
1132
1115
  /**
1133
- * 是否缓存资源,默认true,可为空
1116
+ * 是否缓存资源
1117
+ * @default true
1134
1118
  */
1135
1119
  nocache?: boolean;
1136
1120
  /**
1137
- * 是否重新验证可能缓存的内容,默认true,可为空
1121
+ * 是否重新验证可能缓存的内容
1122
+ * @default true
1138
1123
  */
1139
1124
  revalidate?: boolean;
1140
1125
  /**
1141
- * 将该对象添加到响应的属性中,可为空
1126
+ * 自定义对象(自动存在响应里)
1142
1127
  */
1143
1128
  context?: any;
1144
1129
  /**
1145
- * 重写mimeType,可为空
1130
+ * 重写mimeType,默认不重写
1146
1131
  */
1147
1132
  overrideMimeType?: string;
1148
1133
  /**
1149
- * 是否匿名不发送Cookie,默认为false,可为空
1150
- *
1134
+ * 是否匿名不发送Cookie
1151
1135
  * @default false
1152
1136
  */
1153
1137
  anonymous?: boolean;
1154
1138
  /**
1155
- * 是否使用fetch来发送请求,默认为false,可为空
1156
- *
1139
+ * 是否使用fetch来发送请求
1157
1140
  * @default false
1158
1141
  */
1159
1142
  fetch?: boolean;
1160
1143
  /**
1161
- * 使用fetch请求的配置
1144
+ * 当`fetch`为`true`时的配置项,默认使用自定义的配置
1162
1145
  */
1163
1146
  fetchInit?: HttpxRequestInit;
1164
1147
  /**
1165
1148
  * 拒绝拦截配置
1149
+ *
1166
1150
  * 如果设置了相关配置,那么intercept将不会生效
1167
1151
  */
1168
1152
  allowInterceptConfig?: Partial<HttpxAllowInterceptConfig> | boolean;
1169
1153
  /**
1170
- * 身份验证的用户名
1154
+ * (可选)身份验证的用户名
1171
1155
  */
1172
1156
  user?: string;
1173
1157
  /**
1174
- * 身份验证的密码
1158
+ * (可选)身份验证的密码
1175
1159
  */
1176
1160
  password?: string;
1177
1161
  /**
@@ -1197,13 +1181,13 @@ export declare interface HttpxRequestOption {
1197
1181
  /**
1198
1182
  * (可选)当请求状态改变,触发该回调
1199
1183
  *
1200
- * fetchtrue时该回调不触发
1184
+ * `fetch`为`true`时该回调不会触发
1201
1185
  */
1202
1186
  onreadystatechange?: (...args: any[]) => void;
1203
1187
  /**
1204
1188
  * (可选)当请求上传文件进度改变,触发该回调
1205
1189
  *
1206
- * fetchtrue时该回调不触发
1190
+ * `fetch`为`true`时该回调不会触发
1207
1191
  */
1208
1192
  onprogress?: (...args: any[]) => void;
1209
1193
  }
@@ -1216,12 +1200,12 @@ export declare interface HttpxRequestOptionConfig extends HttpxInitOption {}
1216
1200
  */
1217
1201
  export declare interface HttpxResponseData<T extends HttpxRequestOption> {
1218
1202
  /**
1219
- * 如果fetchtrue,且返回的headers中的Content-Type存在text/event-stream或者是主动设置的responseTypestream
1220
- * 则存在该属性为true
1203
+ * 当请求中配置`fetch`为`true`时,且返回的`headers`中的`Content-Type`存在`text/event-stream`或者是主动设置的`responseType`为`stream`
1204
+ * 则存在该属性为`true`
1221
1205
  */
1222
1206
  isStream?: boolean;
1223
1207
  /**
1224
- * 如果fetchtrue,则存在该属性为true
1208
+ * 当请求中配置`fetch`为`true`时,则存在该属性为`true`
1225
1209
  */
1226
1210
  isFetch?: boolean;
1227
1211
  /**
@@ -1230,31 +1214,31 @@ export declare interface HttpxResponseData<T extends HttpxRequestOption> {
1230
1214
  finalUrl: string;
1231
1215
  /**
1232
1216
  * 数据准备状态
1233
- * + 0 未初始化
1234
- * + 1 载入
1235
- * + 2 载入完成
1236
- * + 3 交互
1237
- * + 4 完成
1217
+ * + `0`:未初始化
1218
+ * + `1`:载入
1219
+ * + `2`:载入完成
1220
+ * + `3`:交互
1221
+ * + `4`:完成
1238
1222
  *
1239
- * 当请求头fetchtrue时,该值固定为4
1223
+ * 当请求中配置`fetch`为`true`时,该值固定为`4`
1240
1224
  */
1241
1225
  readyState: 0 | 1 | 2 | 3 | 4;
1242
1226
  /**
1243
- * 状态码,2xx为成功
1227
+ * 响应的状态码,2xx为成功
1244
1228
  */
1245
1229
  status: HttpxStatus | number;
1246
1230
  /**
1247
- * 关于status的解释
1231
+ * 对`status`的解释
1248
1232
  */
1249
1233
  statusText: "OK" | "" | string;
1250
1234
  /**
1251
- * 响应内容,根据responseType,如果是html,那就是Document类型,如果是json,那么类型是Object类型
1235
+ * 响应内容,根据`responseType`,如果是`html`,那就是`Document`类型,如果是`json`,那么类型是`Object`类型
1252
1236
  */
1253
1237
  response: T["responseType"] extends keyof HttpxResponseTypeMap
1254
1238
  ? HttpxResponseTypeMap[T["responseType"]]
1255
1239
  : HttpxResponseTypeMap["html"];
1256
1240
  /**
1257
- * 当请求头fetchtrue时,该属性存在
1241
+ * 当请求中配置`fetch`为`true`时,该属性存在
1258
1242
  */
1259
1243
  responseFetchHeaders?: Headers;
1260
1244
  /**
@@ -1266,7 +1250,7 @@ export declare interface HttpxResponseData<T extends HttpxRequestOption> {
1266
1250
  */
1267
1251
  responseText: string;
1268
1252
  /**
1269
- * 是请求中设置的responseType,没有设置的话默认为undefined
1253
+ * 请求中配置的`responseType`,没有的话默认为`undefined`
1270
1254
  */
1271
1255
  responseType?: T["responseType"];
1272
1256
  /**
@@ -1281,14 +1265,14 @@ export declare interface HttpxResponse<T extends HttpxRequestOption> {
1281
1265
  /**
1282
1266
  * 是否请求成功
1283
1267
  *
1284
- * 状态码在200-300之间为true,否则为false
1268
+ * 状态码在`200-300`之间为`true`,否则为`false`
1285
1269
  */
1286
1270
  status: boolean;
1287
1271
  /**
1288
1272
  * 响应状态码
1289
1273
  *
1290
- * + -1 onabort触发
1291
- * + 0 ontimeout触发
1274
+ * + `-1` 触发来源:`onabort`
1275
+ * + `0` 触发来源:`ontimeout`
1292
1276
  */
1293
1277
  statusCode: HttpxStatus | number;
1294
1278
  /**
@@ -1313,13 +1297,21 @@ export declare interface HttpxResponse<T extends HttpxRequestOption> {
1313
1297
  * httpx的hook错误的回调数据
1314
1298
  */
1315
1299
  export declare interface HttpxHookErrorData {
1316
- /** 触发的函数名 */
1300
+ /**
1301
+ * 触发的函数名
1302
+ */
1317
1303
  type: "onerror" | "ontimeout" | "onabort";
1318
- /** 触发的错误 */
1304
+ /**
1305
+ * 触发的错误
1306
+ */
1319
1307
  error: Error;
1320
- /** 触发的响应 */
1308
+ /**
1309
+ * 触发的响应
1310
+ */
1321
1311
  response: any;
1322
- /** 请求的配置 */
1312
+ /**
1313
+ * 请求的配置
1314
+ */
1323
1315
  details: HttpxRequestOption;
1324
1316
  }
1325
1317
 
@@ -1335,20 +1327,17 @@ export declare interface HttpxPromise<T> extends Promise<T> {
1335
1327
  */
1336
1328
  export declare interface HttpxInitOption extends HttpxRequestOption {
1337
1329
  /**
1338
- * 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
1330
+ * 实例化,可传入`GM_xmlhttpRequest`,未传入则使用`window.fetch`
1339
1331
  */
1340
1332
  xmlHttpRequest?: Function;
1341
1333
  /**
1342
1334
  * `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL。
1343
1335
  */
1344
1336
  baseURL?: string | undefined;
1345
- /**
1346
- * 重试次数
1347
- * @default 0
1348
- */
1349
- retry?: number;
1350
1337
  /**
1351
1338
  * (可选)是否输出请求配置
1352
1339
  */
1353
1340
  logDetails?: boolean;
1354
1341
  }
1342
+
1343
+ export declare interface HttpxRequestOptionWithDoubleParams extends Omit<HttpxRequestOption, "url"> {}
@@ -122,11 +122,7 @@ export declare interface UtilsAjaxHookResult {
122
122
  };
123
123
  });
124
124
  */
125
- hook(
126
- callback: (
127
- request: UtilsAjaxHookRequestOptions
128
- ) => void | Promise<undefined>
129
- ): void;
125
+ hook(callback: (request: UtilsAjaxHookRequestOptions) => void | Promise<undefined>): void;
130
126
  /**
131
127
  * 过滤
132
128
  * @example
@@ -0,0 +1,2 @@
1
+ declare var jQuery: any;
2
+ declare var unsafeWindow: Window;
@@ -18,11 +18,14 @@ export type ArgsType<T extends JSTypeNames[]> = {
18
18
  export declare interface UtilsOwnObject<V extends any> {
19
19
  [key: string]: V | UtilsOwnObject<V>;
20
20
  }
21
+
21
22
  export declare interface AnyObject {
22
23
  [key: string]: any | AnyObject;
23
24
  toString(): string;
24
25
  }
26
+
25
27
  export type PartialKeys<T, K extends keyof T> = {
26
28
  [P in K]?: T[P];
27
29
  };
30
+
28
31
  export type Values<T> = T[keyof T];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@whitesev/utils",
4
- "version": "2.7.1",
4
+ "version": "2.7.3",
5
5
  "type": "module",
6
6
  "description": "一个常用的工具库",
7
7
  "main": "dist/index.cjs.js",
@@ -1,4 +1,4 @@
1
- class ColorConversion {
1
+ export class ColorConversion {
2
2
  /**
3
3
  * 判断是否是16进制颜色
4
4
  * @param str
@@ -15,14 +15,13 @@ class ColorConversion {
15
15
  /**
16
16
  * 16进制颜色转rgba
17
17
  *
18
- * #ff0000 rgba(123,123,123, 0.4)
18
+ * 例如:`#ff0000` 转为 `rgba(123,123,123, 0.4)`
19
19
  * @param hex
20
20
  * @param opacity
21
21
  */
22
22
  hexToRgba(hex: string, opacity: number): string {
23
23
  if (!this.isHex(hex)) {
24
- // @ts-ignore
25
- throw new TypeError("输入错误的hex", hex);
24
+ throw new TypeError("输入错误的hex:" + hex);
26
25
  }
27
26
  return hex && hex.replace(/\s+/g, "").length === 7
28
27
  ? "rgba(" +
@@ -39,20 +38,17 @@ class ColorConversion {
39
38
  /**
40
39
  * hex转rgb
41
40
  * @param str
42
- * @returns
43
41
  */
44
42
  hexToRgb(str: string) {
45
43
  if (!this.isHex(str)) {
46
- // @ts-ignore
47
- throw new TypeError("输入错误的hex", str);
44
+ throw new TypeError("输入错误的hex:" + str);
48
45
  }
49
46
  /* replace替换查找的到的字符串 */
50
47
  str = str.replace("#", "");
51
48
  /* match得到查询数组 */
52
- let hxs = str.match(/../g);
49
+ let hxs = str.match(/../g)!;
53
50
  for (let index = 0; index < 3; index++) {
54
- // @ts-ignore
55
- hxs[index] = parseInt(hxs[index], 16);
51
+ (hxs as any)[index as any] = parseInt(hxs[index], 16);
56
52
  }
57
53
 
58
54
  return hxs;
@@ -62,13 +58,8 @@ class ColorConversion {
62
58
  * @param redValue
63
59
  * @param greenValue
64
60
  * @param blueValue
65
- * @returns
66
61
  */
67
- rgbToHex(
68
- redValue: string | number,
69
- greenValue: string | number,
70
- blueValue: string | number
71
- ): string {
62
+ rgbToHex(redValue: string | number, greenValue: string | number, blueValue: string | number): string {
72
63
  /* 验证输入的rgb值是否合法 */
73
64
  let validPattern = /^\d{1,3}$/;
74
65
  if (
@@ -77,54 +68,39 @@ class ColorConversion {
77
68
  !validPattern.test(blueValue.toString())
78
69
  )
79
70
  throw new TypeError("输入错误的rgb颜色值");
80
- let hexs = [
81
- redValue.toString(16),
82
- greenValue.toString(16),
83
- blueValue.toString(16),
84
- ];
85
- for (let index = 0; index < 3; index++)
86
- if (hexs[index].length == 1) hexs[index] = "0" + hexs[index];
71
+ let hexs = [redValue.toString(16), greenValue.toString(16), blueValue.toString(16)];
72
+ for (let index = 0; index < 3; index++) if (hexs[index].length == 1) hexs[index] = "0" + hexs[index];
87
73
  return "#" + hexs.join("");
88
74
  }
89
75
  /**
90
76
  * 获取颜色变暗或亮
91
77
  * @param color 颜色
92
78
  * @param level 0~1.0
93
- * @returns
94
79
  */
95
80
  getDarkColor(color: string, level: string): string {
96
81
  if (!this.isHex(color)) {
97
- // @ts-ignore
98
- throw new TypeError("输入错误的hex", color);
82
+ throw new TypeError("输入错误的hex:" + color);
99
83
  }
100
84
  let rgbc = this.hexToRgb(color);
101
85
  for (let index = 0; index < 3; index++) {
102
- // @ts-ignore
103
- rgbc[index] = Math.floor(rgbc[index] * (1 - level));
86
+ (rgbc as any)[index] = Math.floor((rgbc as any)[index] * (1 - (level as any)));
104
87
  }
105
88
 
106
- // @ts-ignore
107
89
  return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
108
90
  }
109
91
  /**
110
92
  * 获取颜色变亮
111
93
  * @param color 颜色
112
94
  * @param level 0~1.0
113
- * @returns
114
95
  */
115
96
  getLightColor(color: string, level: number): string {
116
97
  if (!this.isHex(color)) {
117
- // @ts-ignore
118
- throw new TypeError("输入错误的hex", color);
98
+ throw new TypeError("输入错误的hex:" + color);
119
99
  }
120
100
  let rgbc = this.hexToRgb(color);
121
101
  for (let index = 0; index < 3; index++) {
122
- // @ts-ignore
123
- rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
102
+ (rgbc as any)[index] = Math.floor((255 - (rgbc as any)[index]) * (level as any) + (rgbc as any)[index]);
124
103
  }
125
- // @ts-ignore
126
104
  return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
127
105
  }
128
106
  }
129
-
130
- export { ColorConversion };
package/src/CommonUtil.ts CHANGED
@@ -49,11 +49,7 @@ class CommonUtil {
49
49
  !UtilsContext.isDOM(sourceValue)
50
50
  ) {
51
51
  /* 源端的值是object类型,且不是元素节点 */
52
- (target as any)[sourceKeyName] = UtilsContext.assign(
53
- targetValue,
54
- sourceValue,
55
- isAdd
56
- );
52
+ (target as any)[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
57
53
  continue;
58
54
  }
59
55
  (target as any)[sourceKeyName] = sourceValue;
@@ -70,11 +66,7 @@ class CommonUtil {
70
66
  Object.keys(sourceValue).length
71
67
  ) {
72
68
  /* 源端的值是object类型,且不是元素节点 */
73
- (target as any)[targetKeyName] = UtilsContext.assign(
74
- targetValue,
75
- sourceValue,
76
- isAdd
77
- );
69
+ (target as any)[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
78
70
  continue;
79
71
  }
80
72
  /* 直接赋值 */
@@ -153,10 +145,7 @@ class CommonUtil {
153
145
  itemResult = objItem === 0;
154
146
  break;
155
147
  case "string":
156
- itemResult =
157
- objItem.trim() === "" ||
158
- objItem === "null" ||
159
- objItem === "undefined";
148
+ itemResult = objItem.trim() === "" || objItem === "null" || objItem === "undefined";
160
149
  break;
161
150
  case "boolean":
162
151
  itemResult = !objItem;
@@ -164,9 +153,7 @@ class CommonUtil {
164
153
  case "function":
165
154
  let funcStr = objItem.toString().replace(/\s/g, "");
166
155
  /* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
167
- itemResult = Boolean(
168
- funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/)
169
- );
156
+ itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
170
157
  break;
171
158
  }
172
159
  }
@@ -214,8 +201,7 @@ class CommonUtil {
214
201
  if (obj === null) return null;
215
202
  let clone = obj instanceof Array ? [] : {};
216
203
  for (const [key, value] of Object.entries(obj)) {
217
- (clone as any)[key] =
218
- typeof value === "object" ? UtilsContext.deepClone(value) : value;
204
+ (clone as any)[key] = typeof value === "object" ? UtilsContext.deepClone(value) : value;
219
205
  }
220
206
  return clone;
221
207
  }
@@ -243,14 +229,8 @@ class CommonUtil {
243
229
  * Utils.toJSON("{123:123}")
244
230
  * > {123:123}
245
231
  */
246
- toJSON<T = any>(
247
- data: string | null,
248
- errorCallBack?: (error: Error) => void
249
- ): T;
250
- toJSON<T = any>(
251
- data: string | null,
252
- errorCallBack?: (error: Error) => void
253
- ): T {
232
+ toJSON<T = any>(data: string | null, errorCallBack?: (error: Error) => void): T;
233
+ toJSON<T = any>(data: string | null, errorCallBack?: (error: Error) => void): T {
254
234
  let result: any = {};
255
235
  if (typeof data === "object") {
256
236
  return data as any;
@@ -274,10 +254,7 @@ class CommonUtil {
274
254
  /^[\],:{}\s]*$/.test(
275
255
  data
276
256
  .replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
277
- .replace(
278
- /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
279
- "]"
280
- )
257
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
281
258
  .replace(/(?:^|:|,)(?:\s*\[)+/g, "")
282
259
  )
283
260
  ) {
package/src/DOMUtils.ts CHANGED
@@ -88,8 +88,7 @@ class DOMUtils {
88
88
  let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
89
89
  let text = textMatch![2];
90
90
  selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
91
- return Array.from(parent.querySelectorAll<E>(selector)).filter(($ele) => {
92
- // @ts-ignore
91
+ return Array.from(parent.querySelectorAll<HTMLElement>(selector)).filter(($ele) => {
93
92
  return ($ele?.textContent || $ele?.innerText)?.includes(text);
94
93
  });
95
94
  } else if (
@@ -107,8 +106,7 @@ class DOMUtils {
107
106
  }
108
107
  let regexp = new RegExp(pattern, flags);
109
108
  selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
110
- return Array.from(parent.querySelectorAll<E>(selector)).filter(($ele) => {
111
- // @ts-ignore
109
+ return Array.from(parent.querySelectorAll<HTMLElement>(selector)).filter(($ele) => {
112
110
  return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
113
111
  });
114
112
  } else {
@@ -137,10 +135,7 @@ class DOMUtils {
137
135
  * DOMUtils.matches("div:regexp(/^xxx/ig)")
138
136
  * > false
139
137
  */
140
- matches(
141
- $el: HTMLElement | Element | null | undefined,
142
- selector: string
143
- ): boolean {
138
+ matches($el: HTMLElement | Element | null | undefined, selector: string): boolean {
144
139
  selector = selector.trim();
145
140
  if ($el == null) {
146
141
  return false;
@@ -158,8 +153,7 @@ class DOMUtils {
158
153
  let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
159
154
  let text = textMatch![2];
160
155
  selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
161
- // @ts-ignore
162
- let content = $el?.textContent || $el?.innerText;
156
+ let content = $el?.textContent || (<HTMLElement>$el)?.innerText;
163
157
  if (typeof content !== "string") {
164
158
  content = "";
165
159
  }
@@ -179,8 +173,7 @@ class DOMUtils {
179
173
  }
180
174
  let regexp = new RegExp(pattern, flags);
181
175
  selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
182
- // @ts-ignore
183
- let content = $el?.textContent || $el?.innerText;
176
+ let content = $el?.textContent || (<HTMLElement>$el)?.innerText;
184
177
  if (typeof content !== "string") {
185
178
  content = "";
186
179
  }
@@ -215,14 +208,8 @@ class DOMUtils {
215
208
  $el: HTMLElement | Element,
216
209
  selector: string
217
210
  ): HTMLElementTagNameMap[K] | null;
218
- closest<E extends Element = Element>(
219
- $el: HTMLElement | Element,
220
- selector: string
221
- ): E | null;
222
- closest<E extends Element = Element>(
223
- $el: HTMLElement | Element,
224
- selector: string
225
- ): E | null {
211
+ closest<E extends Element = Element>($el: HTMLElement | Element, selector: string): E | null;
212
+ closest<E extends Element = Element>($el: HTMLElement | Element, selector: string): E | null {
226
213
  selector = selector.trim();
227
214
 
228
215
  if (selector.match(/[^\s]{1}:empty$/gi)) {
@@ -243,8 +230,7 @@ class DOMUtils {
243
230
  selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
244
231
  let $closest = $el?.closest<E>(selector);
245
232
  if ($closest) {
246
- // @ts-ignore
247
- let content = $el?.textContent || $el?.innerText;
233
+ let content = $el?.textContent || (<HTMLElement>$el)?.innerText;
248
234
  if (typeof content === "string" && content.includes(text)) {
249
235
  return $closest;
250
236
  }
@@ -267,8 +253,7 @@ class DOMUtils {
267
253
  selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
268
254
  let $closest = $el?.closest<E>(selector);
269
255
  if ($closest) {
270
- // @ts-ignore
271
- let content = $el?.textContent || $el?.innerText;
256
+ let content = $el?.textContent || (<HTMLElement>$el)?.innerText;
272
257
  if (typeof content === "string" && content.match(regexp)) {
273
258
  return $closest;
274
259
  }