@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];