@whitesev/utils 2.7.1 → 2.7.2

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 (45) hide show
  1. package/dist/index.amd.js +168 -212
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +168 -212
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +168 -212
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +168 -212
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +168 -212
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +168 -212
  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/UtilsGMMenu.d.ts +1 -2
  22. package/dist/types/src/WindowApi.d.ts +1 -2
  23. package/dist/types/src/indexedDB.d.ts +1 -2
  24. package/dist/types/src/types/Httpx.d.ts +73 -67
  25. package/dist/types/src/types/env.d.ts +2 -0
  26. package/dist/types/src/types/global.d.ts +3 -0
  27. package/package.json +1 -1
  28. package/src/ColorConversion.ts +14 -25
  29. package/src/DOMUtils.ts +14 -16
  30. package/src/Dictionary.ts +39 -35
  31. package/src/GBKEncoder.ts +8 -12
  32. package/src/Hooks.ts +1 -3
  33. package/src/Httpx.ts +194 -174
  34. package/src/LockFunction.ts +3 -3
  35. package/src/Log.ts +1 -3
  36. package/src/Progress.ts +1 -3
  37. package/src/TryCatch.ts +4 -4
  38. package/src/Utils.ts +27 -43
  39. package/src/UtilsGMMenu.ts +19 -22
  40. package/src/Vue.ts +4 -7
  41. package/src/WindowApi.ts +2 -5
  42. package/src/indexedDB.ts +8 -8
  43. package/src/types/Httpx.d.ts +73 -67
  44. package/src/types/env.d.ts +2 -0
  45. package/src/types/global.d.ts +3 -0
@@ -1039,24 +1039,23 @@ export declare interface HttpxAllowInterceptConfig {
1039
1039
  */
1040
1040
  export declare interface HttpxRequestOption {
1041
1041
  /**
1042
- * 网址
1042
+ * 请求的url
1043
1043
  */
1044
- url?: string;
1044
+ url: string;
1045
1045
  /**
1046
1046
  * 请求方法
1047
1047
  * @default "GET"
1048
1048
  */
1049
1049
  method?: HttpxMethod;
1050
1050
  /**
1051
- * 超时时间,默认5000,可为空
1051
+ * 请求的超时时间
1052
1052
  *
1053
- * fetchtrue时,该值不生效
1053
+ * 当`fetch`为`true`时,该值不生效,也就是请求不会超时
1054
1054
  * @default 5000
1055
1055
  */
1056
1056
  timeout?: number;
1057
1057
  /**
1058
1058
  * 响应类型,默认document,可为空
1059
- *
1060
1059
  * @default "document"
1061
1060
  */
1062
1061
  responseType?: keyof HttpxResponseTypeMap;
@@ -1070,39 +1069,39 @@ export declare interface HttpxRequestOption {
1070
1069
  data?: string | FormData | object;
1071
1070
  /**
1072
1071
  * 是否自动对data进行处理
1073
- * @default true
1074
- * 处理以下请求类型
1075
- * + GET 自动进行URLSearchParams转换
1076
- * + HEAD 自动进行URLSearchParams转换
1077
- * + POST 处理Content-Type不为空的情况
1078
1072
  *
1079
- * application/json
1073
+ * ## 处理以下请求类型
1074
+ * + `GET` 自动进行`URLSearchParams`转换
1075
+ * + `HEAD` 自动进行`URLSearchParams`转换
1076
+ * + `POST` 处理`Content-Type`不为空的情况
1077
+ *
1078
+ * ### `application/json`
1080
1079
  *
1081
- * + string: 不做处理
1082
- * + FormData: 转为JSON并进行JSON.stringify处理
1083
- * + object: 进行JSON.stringify处理
1080
+ * + `string`: 不做处理
1081
+ * + `FormData`: 转为`JSON`并进行`JSON.stringify`处理
1082
+ * + `object`: 进行`JSON.stringify`处理
1084
1083
  *
1085
- * application/x-www-form-urlencoded
1084
+ * ### `application/x-www-form-urlencoded`
1086
1085
  *
1087
- * + string: 不做处理
1088
- * + FormData: 转为URLSearchParams,再转为string
1089
- * + object: 转为URLSearchParams,再转为string
1086
+ * + `string`: 不做处理
1087
+ * + `FormData`: 转为`URLSearchParams`,再转为`string`
1088
+ * + `object`: 转为`URLSearchParams`,再转为`string`
1090
1089
  *
1091
- * multipart/form-data
1092
- * (上传文件专用)
1093
- * + string: 不做处理
1094
- * + FormData: 移除Content-Type
1095
- * + object: 不做处理
1090
+ * ### `multipart/form-data`(上传文件专用)
1091
+ *
1092
+ * + `string`: 不做处理
1093
+ * + `FormData`: 移除`Content-Type`
1094
+ * + `object`: 不做处理
1095
+ * @default true
1096
1096
  */
1097
1097
  processData?: boolean;
1098
1098
  /**
1099
- * 当触发重定向的使用规则,默认follow,可为空
1100
- *
1099
+ * 当触发重定向的使用规则
1101
1100
  * @default "follow"
1102
1101
  */
1103
1102
  redirect?: HttpxRedirect;
1104
1103
  /**
1105
- * 自定义Cookie,可为空
1104
+ * 自定义的Cookie
1106
1105
  */
1107
1106
  cookie?: string;
1108
1107
  /**
@@ -1126,52 +1125,53 @@ export declare interface HttpxRequestOption {
1126
1125
  topLevelSite?: string;
1127
1126
  };
1128
1127
  /**
1129
- * 以二进制模式发送数据字符串,可为空
1128
+ * 以二进制模式发送数据字符串
1130
1129
  */
1131
1130
  binary?: HttpxBinary;
1132
1131
  /**
1133
- * 是否缓存资源,默认true,可为空
1132
+ * 是否缓存资源
1133
+ * @default true
1134
1134
  */
1135
1135
  nocache?: boolean;
1136
1136
  /**
1137
- * 是否重新验证可能缓存的内容,默认true,可为空
1137
+ * 是否重新验证可能缓存的内容
1138
+ * @default true
1138
1139
  */
1139
1140
  revalidate?: boolean;
1140
1141
  /**
1141
- * 将该对象添加到响应的属性中,可为空
1142
+ * 自定义对象(自动存在响应里)
1142
1143
  */
1143
1144
  context?: any;
1144
1145
  /**
1145
- * 重写mimeType,可为空
1146
+ * 重写mimeType,默认不重写
1146
1147
  */
1147
1148
  overrideMimeType?: string;
1148
1149
  /**
1149
- * 是否匿名不发送Cookie,默认为false,可为空
1150
- *
1150
+ * 是否匿名不发送Cookie
1151
1151
  * @default false
1152
1152
  */
1153
1153
  anonymous?: boolean;
1154
1154
  /**
1155
- * 是否使用fetch来发送请求,默认为false,可为空
1156
- *
1155
+ * 是否使用fetch来发送请求
1157
1156
  * @default false
1158
1157
  */
1159
1158
  fetch?: boolean;
1160
1159
  /**
1161
- * 使用fetch请求的配置
1160
+ * 当`fetch`为`true`时的配置项,默认使用自定义的配置
1162
1161
  */
1163
1162
  fetchInit?: HttpxRequestInit;
1164
1163
  /**
1165
1164
  * 拒绝拦截配置
1165
+ *
1166
1166
  * 如果设置了相关配置,那么intercept将不会生效
1167
1167
  */
1168
1168
  allowInterceptConfig?: Partial<HttpxAllowInterceptConfig> | boolean;
1169
1169
  /**
1170
- * 身份验证的用户名
1170
+ * (可选)身份验证的用户名
1171
1171
  */
1172
1172
  user?: string;
1173
1173
  /**
1174
- * 身份验证的密码
1174
+ * (可选)身份验证的密码
1175
1175
  */
1176
1176
  password?: string;
1177
1177
  /**
@@ -1197,13 +1197,13 @@ export declare interface HttpxRequestOption {
1197
1197
  /**
1198
1198
  * (可选)当请求状态改变,触发该回调
1199
1199
  *
1200
- * fetchtrue时该回调不触发
1200
+ * `fetch`为`true`时该回调不会触发
1201
1201
  */
1202
1202
  onreadystatechange?: (...args: any[]) => void;
1203
1203
  /**
1204
1204
  * (可选)当请求上传文件进度改变,触发该回调
1205
1205
  *
1206
- * fetchtrue时该回调不触发
1206
+ * `fetch`为`true`时该回调不会触发
1207
1207
  */
1208
1208
  onprogress?: (...args: any[]) => void;
1209
1209
  }
@@ -1216,12 +1216,12 @@ export declare interface HttpxRequestOptionConfig extends HttpxInitOption {}
1216
1216
  */
1217
1217
  export declare interface HttpxResponseData<T extends HttpxRequestOption> {
1218
1218
  /**
1219
- * 如果fetchtrue,且返回的headers中的Content-Type存在text/event-stream或者是主动设置的responseTypestream
1220
- * 则存在该属性为true
1219
+ * 当请求中配置`fetch`为`true`时,且返回的`headers`中的`Content-Type`存在`text/event-stream`或者是主动设置的`responseType`为`stream`
1220
+ * 则存在该属性为`true`
1221
1221
  */
1222
1222
  isStream?: boolean;
1223
1223
  /**
1224
- * 如果fetchtrue,则存在该属性为true
1224
+ * 当请求中配置`fetch`为`true`时,则存在该属性为`true`
1225
1225
  */
1226
1226
  isFetch?: boolean;
1227
1227
  /**
@@ -1230,31 +1230,31 @@ export declare interface HttpxResponseData<T extends HttpxRequestOption> {
1230
1230
  finalUrl: string;
1231
1231
  /**
1232
1232
  * 数据准备状态
1233
- * + 0 未初始化
1234
- * + 1 载入
1235
- * + 2 载入完成
1236
- * + 3 交互
1237
- * + 4 完成
1233
+ * + `0`:未初始化
1234
+ * + `1`:载入
1235
+ * + `2`:载入完成
1236
+ * + `3`:交互
1237
+ * + `4`:完成
1238
1238
  *
1239
- * 当请求头fetchtrue时,该值固定为4
1239
+ * 当请求中配置`fetch`为`true`时,该值固定为`4`
1240
1240
  */
1241
1241
  readyState: 0 | 1 | 2 | 3 | 4;
1242
1242
  /**
1243
- * 状态码,2xx为成功
1243
+ * 响应的状态码,2xx为成功
1244
1244
  */
1245
1245
  status: HttpxStatus | number;
1246
1246
  /**
1247
- * 关于status的解释
1247
+ * 对`status`的解释
1248
1248
  */
1249
1249
  statusText: "OK" | "" | string;
1250
1250
  /**
1251
- * 响应内容,根据responseType,如果是html,那就是Document类型,如果是json,那么类型是Object类型
1251
+ * 响应内容,根据`responseType`,如果是`html`,那就是`Document`类型,如果是`json`,那么类型是`Object`类型
1252
1252
  */
1253
1253
  response: T["responseType"] extends keyof HttpxResponseTypeMap
1254
1254
  ? HttpxResponseTypeMap[T["responseType"]]
1255
1255
  : HttpxResponseTypeMap["html"];
1256
1256
  /**
1257
- * 当请求头fetchtrue时,该属性存在
1257
+ * 当请求中配置`fetch`为`true`时,该属性存在
1258
1258
  */
1259
1259
  responseFetchHeaders?: Headers;
1260
1260
  /**
@@ -1266,7 +1266,7 @@ export declare interface HttpxResponseData<T extends HttpxRequestOption> {
1266
1266
  */
1267
1267
  responseText: string;
1268
1268
  /**
1269
- * 是请求中设置的responseType,没有设置的话默认为undefined
1269
+ * 请求中配置的`responseType`,没有的话默认为`undefined`
1270
1270
  */
1271
1271
  responseType?: T["responseType"];
1272
1272
  /**
@@ -1281,14 +1281,14 @@ export declare interface HttpxResponse<T extends HttpxRequestOption> {
1281
1281
  /**
1282
1282
  * 是否请求成功
1283
1283
  *
1284
- * 状态码在200-300之间为true,否则为false
1284
+ * 状态码在`200-300`之间为`true`,否则为`false`
1285
1285
  */
1286
1286
  status: boolean;
1287
1287
  /**
1288
1288
  * 响应状态码
1289
1289
  *
1290
- * + -1 onabort触发
1291
- * + 0 ontimeout触发
1290
+ * + `-1` 触发来源:`onabort`
1291
+ * + `0` 触发来源:`ontimeout`
1292
1292
  */
1293
1293
  statusCode: HttpxStatus | number;
1294
1294
  /**
@@ -1313,13 +1313,21 @@ export declare interface HttpxResponse<T extends HttpxRequestOption> {
1313
1313
  * httpx的hook错误的回调数据
1314
1314
  */
1315
1315
  export declare interface HttpxHookErrorData {
1316
- /** 触发的函数名 */
1316
+ /**
1317
+ * 触发的函数名
1318
+ */
1317
1319
  type: "onerror" | "ontimeout" | "onabort";
1318
- /** 触发的错误 */
1320
+ /**
1321
+ * 触发的错误
1322
+ */
1319
1323
  error: Error;
1320
- /** 触发的响应 */
1324
+ /**
1325
+ * 触发的响应
1326
+ */
1321
1327
  response: any;
1322
- /** 请求的配置 */
1328
+ /**
1329
+ * 请求的配置
1330
+ */
1323
1331
  details: HttpxRequestOption;
1324
1332
  }
1325
1333
 
@@ -1335,20 +1343,18 @@ export declare interface HttpxPromise<T> extends Promise<T> {
1335
1343
  */
1336
1344
  export declare interface HttpxInitOption extends HttpxRequestOption {
1337
1345
  /**
1338
- * 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
1346
+ * 实例化,可传入`GM_xmlhttpRequest`,未传入则使用`window.fetch`
1339
1347
  */
1340
1348
  xmlHttpRequest?: Function;
1341
1349
  /**
1342
1350
  * `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL。
1343
1351
  */
1344
1352
  baseURL?: string | undefined;
1345
- /**
1346
- * 重试次数
1347
- * @default 0
1348
- */
1349
- retry?: number;
1350
1353
  /**
1351
1354
  * (可选)是否输出请求配置
1352
1355
  */
1353
1356
  logDetails?: boolean;
1354
1357
  }
1358
+
1359
+ export declare interface HttpxRequestOptionWithDoubleParams
1360
+ extends Omit<HttpxRequestOption, "url"> {}
@@ -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];