@whitesev/utils 2.3.2 → 2.3.4

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.
@@ -949,6 +949,26 @@ export declare interface HttpxDetails {
949
949
  * 自定义Cookie,可为空
950
950
  */
951
951
  cookie?: string;
952
+ /**
953
+ * TamperMonkey5.2+
954
+ *
955
+ * @link https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/cookies#storage_partitioning
956
+ */
957
+ cookiePartition?: {
958
+ /**
959
+ * 设置顶级站点
960
+ *
961
+ * @example
962
+ * http://*.example.com/
963
+ *
964
+ * @example
965
+ * http://www.example.com/
966
+ *
967
+ * @example
968
+ * *://*.example.com/
969
+ */
970
+ topLevelSite?: string;
971
+ };
952
972
  /**
953
973
  * 以二进制模式发送数据字符串,可为空
954
974
  */
@@ -1206,68 +1226,98 @@ declare class Httpx {
1206
1226
  /**
1207
1227
  * GET 请求
1208
1228
  * @param url 网址
1229
+ */
1230
+ get(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1231
+ /**
1232
+ * GET 请求
1209
1233
  * @param details 配置
1210
1234
  */
1211
- get<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1235
+ get(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1212
1236
  /**
1213
1237
  * GET 请求
1238
+ * @param url 网址
1214
1239
  * @param details 配置
1215
1240
  */
1216
- get<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1241
+ get(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1217
1242
  /**
1218
1243
  * POST 请求
1219
1244
  * @param details 配置
1220
1245
  */
1221
- post<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1246
+ post(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1247
+ /**
1248
+ * POST 请求
1249
+ * @param url 网址
1250
+ */
1251
+ post(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1222
1252
  /**
1223
1253
  * POST 请求
1224
1254
  * @param url 网址
1225
1255
  * @param details 配置
1226
1256
  */
1227
- post<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1257
+ post(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1228
1258
  /**
1229
1259
  * HEAD 请求
1230
1260
  * @param details 配置
1231
1261
  */
1232
- head<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1262
+ head(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1263
+ /**
1264
+ * HEAD 请求
1265
+ * @param url 网址
1266
+ */
1267
+ head(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1233
1268
  /**
1234
1269
  * HEAD 请求
1235
1270
  * @param url 网址
1236
1271
  * @param details 配置
1237
1272
  */
1238
- head<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1273
+ head(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1239
1274
  /**
1240
1275
  * OPTIONS 请求
1241
1276
  * @param details 配置
1242
1277
  */
1243
- options<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1278
+ options(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1279
+ /**
1280
+ * OPTIONS 请求
1281
+ * @param url 网址
1282
+ */
1283
+ options(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1244
1284
  /**
1245
1285
  * OPTIONS 请求
1246
1286
  * @param url 网址
1247
1287
  * @param details 配置
1248
1288
  */
1249
- options<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1289
+ options(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1250
1290
  /**
1251
1291
  * DELETE 请求
1252
1292
  * @param details 配置
1253
1293
  */
1254
- delete<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1294
+ delete(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1295
+ /**
1296
+ * DELETE 请求
1297
+ * @param url 网址
1298
+ */
1299
+ delete(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1255
1300
  /**
1256
1301
  * DELETE 请求
1257
1302
  * @param url 网址
1258
1303
  * @param details 配置
1259
1304
  */
1260
- delete<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1305
+ delete(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1261
1306
  /**
1262
1307
  * PUT 请求
1263
1308
  * @param details 配置
1264
1309
  */
1265
- put<T extends HttpxDetails>(details: T): HttpxPromise<HttpxAsyncResult<T>>;
1310
+ put(details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1311
+ /**
1312
+ * PUT 请求
1313
+ * @param url 网址
1314
+ */
1315
+ put(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1266
1316
  /**
1267
1317
  * PUT 请求
1268
1318
  * @param url 网址
1269
1319
  * @param details 配置
1270
1320
  */
1271
- put<T extends HttpxDetails>(url: string, details?: T): HttpxPromise<HttpxAsyncResult<T>>;
1321
+ put(url: string, details: HttpxDetails): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1272
1322
  }
1273
1323
  export { Httpx };
@@ -1,20 +1,20 @@
1
1
  /** Utils.Log的初始化配置 */
2
2
  declare interface UtilsLogOptions {
3
- /** 是否输出Tag,false的话其它的颜色也不输出,默认为true */
3
+ /** 是否输出Tag,false的话其它的颜色也不输出 @default true */
4
4
  tag: boolean;
5
- /** log.success的颜色,默认#0000FF */
5
+ /** log.success的颜色 @default "#0000FF" */
6
6
  successColor: string;
7
- /** log.warn的颜色,默认0 */
7
+ /** log.warn的颜色 @default "0" */
8
8
  warnColor: string;
9
- /** log.error的颜色,默认#FF0000 */
9
+ /** log.error的颜色 @default "#FF0000" */
10
10
  errorColor: string;
11
- /** log.info的颜色,默认0 */
11
+ /** log.info的颜色 @default "0" */
12
12
  infoColor: string;
13
- /** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置,默认false */
13
+ /** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置 @default false */
14
14
  debug: boolean;
15
- /** 当console输出超过logMaxCount数量自动清理控制台,默认false */
15
+ /** 当console输出超过logMaxCount数量自动清理控制台 @default false */
16
16
  autoClearConsole: boolean;
17
- /** console输出的最高数量,autoClearConsole开启则生效,默认999 */
17
+ /** console输出的最高数量,autoClearConsole开启则生效 @default 999 */
18
18
  logMaxCount: number;
19
19
  }
20
20
  declare class Log {
@@ -22,10 +22,10 @@ declare class Log {
22
22
  /** 前面的TAG标志 */
23
23
  tag: string;
24
24
  /**
25
- * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
25
+ * @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
26
26
  * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
27
27
  */
28
- constructor(_GM_info_?: {
28
+ constructor(__GM_info?: {
29
29
  script: {
30
30
  name: string;
31
31
  };
@@ -48,41 +48,39 @@ declare class Log {
48
48
  private printContent;
49
49
  /**
50
50
  * 控制台-普通输出
51
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
52
- * @param color 输出的颜色
53
- * @param otherStyle 其它CSS
51
+ * @param args 需要输出的内容
52
+ * @example
53
+ * log.info("输出信息","输出信息2","输出信息3","输出")
54
54
  */
55
- info(msg: any, color?: string, otherStyle?: string): void;
55
+ info(...args: any[]): void;
56
56
  /**
57
57
  * 控制台-警告输出
58
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
59
- * @param color 输出的颜色
60
- * @param otherStyle 其它CSS
58
+ * @param args 需要输出的内容
59
+ * @example
60
+ * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
61
61
  */
62
- warn(msg: any, color?: string, otherStyle?: string): void;
62
+ warn(...args: any[]): void;
63
63
  /**
64
64
  * 控制台-错误输出
65
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
66
- * @param color 输出的颜色
67
- * @param otherStyle 其它CSS
65
+ * @param args 需要输出的内容
66
+ * @example
67
+ * log.error("输出错误","输出错误2","输出错误3","输出错误4")
68
68
  */
69
- error(msg: any, color?: string, otherStyle?: string): void;
69
+ error(...args: any[]): void;
70
70
  /**
71
71
  * 控制台-成功输出
72
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
73
- * @param color 输出的颜色
74
- * @param otherStyle 其它CSS
72
+ * @param args 需要输出的内容
73
+ * @example
74
+ * log.success("输出成功")
75
75
  */
76
- success(msg: any, color?: string, otherStyle?: string): void;
76
+ success(...args: any[]): void;
77
77
  /**
78
78
  * 控制台-输出表格
79
- * @param msg
80
- * @param color 输出的颜色
81
- * @param otherStyle 其它CSS
79
+ * @param msg 需要输出的内容
82
80
  * @example
83
81
  * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
84
82
  */
85
- table(msg: any[], color?: string, otherStyle?: string): void;
83
+ table(msg: any[]): void;
86
84
  /**
87
85
  * 配置Log对象的颜色
88
86
  * @param paramDetails 配置信息
@@ -23,7 +23,7 @@ export declare interface Vue2Object {
23
23
  $data: any;
24
24
  $isServer: boolean;
25
25
  $props: any;
26
- $route: any & {
26
+ $route: {
27
27
  fullPath: string;
28
28
  hash: string;
29
29
  matched: any[];
@@ -33,13 +33,13 @@ export declare interface Vue2Object {
33
33
  path: string;
34
34
  query: any;
35
35
  };
36
- $router: any & {
36
+ $router: {
37
37
  afterHooks: Function[];
38
38
  app: Vue2Object;
39
39
  apps: Vue2Object[];
40
40
  beforeHooks: Function[];
41
41
  fallback: boolean;
42
- history: any & {
42
+ history: {
43
43
  base: string;
44
44
  current: any;
45
45
  listeners: any[];
@@ -66,7 +66,7 @@ export declare interface Vue2Object {
66
66
  */
67
67
  replace: (to: string, data?: any) => void;
68
68
  };
69
- matcher: any & {
69
+ matcher: {
70
70
  addRoute: (...args: any[]) => any;
71
71
  addRoutes: (...args: any[]) => any;
72
72
  getRoutes: () => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Httpx.ts CHANGED
@@ -1047,6 +1047,26 @@ export declare interface HttpxDetails {
1047
1047
  * 自定义Cookie,可为空
1048
1048
  */
1049
1049
  cookie?: string;
1050
+ /**
1051
+ * TamperMonkey5.2+
1052
+ *
1053
+ * @link https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/cookies#storage_partitioning
1054
+ */
1055
+ cookiePartition?: {
1056
+ /**
1057
+ * 设置顶级站点
1058
+ *
1059
+ * @example
1060
+ * http://*.example.com/
1061
+ *
1062
+ * @example
1063
+ * http://www.example.com/
1064
+ *
1065
+ * @example
1066
+ * *://*.example.com/
1067
+ */
1068
+ topLevelSite?: string;
1069
+ };
1050
1070
  /**
1051
1071
  * 以二进制模式发送数据字符串,可为空
1052
1072
  */
@@ -1509,6 +1529,9 @@ class Httpx {
1509
1529
  data: details.data || this.context.#defaultDetails.data,
1510
1530
  redirect: details.redirect || this.context.#defaultDetails.redirect,
1511
1531
  cookie: details.cookie || this.context.#defaultDetails.cookie,
1532
+ cookiePartition:
1533
+ details.cookiePartition ||
1534
+ this.context.#defaultDetails.cookiePartition,
1512
1535
  binary: details.binary || this.context.#defaultDetails.binary,
1513
1536
  nocache: details.nocache || this.context.#defaultDetails.nocache,
1514
1537
  revalidate:
@@ -1661,6 +1684,20 @@ class Httpx {
1661
1684
  } else {
1662
1685
  (result as any).fetchInit = details.fetchInit;
1663
1686
  }
1687
+
1688
+ // 处理新的cookiePartition
1689
+ if (
1690
+ typeof result.cookiePartition === "object" &&
1691
+ result.cookiePartition != null
1692
+ ) {
1693
+ if (
1694
+ Reflect.has(result.cookiePartition, "topLevelSite") &&
1695
+ typeof result.cookiePartition.topLevelSite !== "string"
1696
+ ) {
1697
+ // topLevelSite必须是字符串
1698
+ Reflect.deleteProperty(result.cookiePartition, "topLevelSite");
1699
+ }
1700
+ }
1664
1701
  return result;
1665
1702
  },
1666
1703
  /**
@@ -2220,6 +2257,7 @@ class Httpx {
2220
2257
  data: void 0,
2221
2258
  redirect: void 0,
2222
2259
  cookie: void 0,
2260
+ cookiePartition: void 0,
2223
2261
  binary: void 0,
2224
2262
  nocache: void 0,
2225
2263
  revalidate: void 0,
@@ -2362,26 +2400,33 @@ class Httpx {
2362
2400
  /**
2363
2401
  * GET 请求
2364
2402
  * @param url 网址
2403
+ */
2404
+ async get(
2405
+ url: string // @ts-ignore
2406
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2407
+ /**
2408
+ * GET 请求
2365
2409
  * @param details 配置
2366
2410
  */
2367
- async get<T extends HttpxDetails>(
2368
- url: string,
2369
- details?: T // @ts-ignore
2370
- ): HttpxPromise<HttpxAsyncResult<T>>;
2411
+ async get(
2412
+ details: HttpxDetails // @ts-ignore
2413
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2371
2414
  /**
2372
2415
  * GET 请求
2416
+ * @param url 网址
2373
2417
  * @param details 配置
2374
2418
  */
2375
- async get<T extends HttpxDetails>(
2376
- details: T // @ts-ignore
2377
- ): HttpxPromise<HttpxAsyncResult<T>>;
2419
+ async get(
2420
+ url: string,
2421
+ details: HttpxDetails // @ts-ignore
2422
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2378
2423
  /**
2379
2424
  * GET 请求
2380
2425
  * @param url 网址
2381
2426
  * @param details 配置
2382
2427
  */
2383
2428
  async get(
2384
- ...args: (HttpxDetails | string)[] // @ts-ignore
2429
+ ...args: (string | HttpxDetails)[] // @ts-ignore
2385
2430
  ): HttpxPromise<HttpxAsyncResult<HttpxDetails>> {
2386
2431
  let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
2387
2432
  let abortFn: Function | null = null;
@@ -2420,18 +2465,24 @@ class Httpx {
2420
2465
  * POST 请求
2421
2466
  * @param details 配置
2422
2467
  */
2423
- async post<T extends HttpxDetails>(
2424
- details: T // @ts-ignore
2425
- ): HttpxPromise<HttpxAsyncResult<T>>;
2468
+ async post(
2469
+ details: HttpxDetails // @ts-ignore
2470
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2471
+ /**
2472
+ * POST 请求
2473
+ * @param url 网址
2474
+ */
2475
+ // @ts-ignore
2476
+ async post(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2426
2477
  /**
2427
2478
  * POST 请求
2428
2479
  * @param url 网址
2429
2480
  * @param details 配置
2430
2481
  */
2431
- async post<T extends HttpxDetails>(
2482
+ async post(
2432
2483
  url: string,
2433
- details?: T // @ts-ignore
2434
- ): HttpxPromise<HttpxAsyncResult<T>>;
2484
+ details: HttpxDetails // @ts-ignore
2485
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2435
2486
  /**
2436
2487
  * POST 请求
2437
2488
  */
@@ -2474,18 +2525,25 @@ class Httpx {
2474
2525
  * HEAD 请求
2475
2526
  * @param details 配置
2476
2527
  */
2477
- async head<T extends HttpxDetails>(
2478
- details: T // @ts-ignore
2479
- ): HttpxPromise<HttpxAsyncResult<T>>;
2528
+ async head(
2529
+ details: HttpxDetails // @ts-ignore
2530
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2531
+ /**
2532
+ * HEAD 请求
2533
+ * @param url 网址
2534
+ */
2535
+ async head(
2536
+ url: string // @ts-ignore
2537
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2480
2538
  /**
2481
2539
  * HEAD 请求
2482
2540
  * @param url 网址
2483
2541
  * @param details 配置
2484
2542
  */
2485
- async head<T extends HttpxDetails>(
2543
+ async head(
2486
2544
  url: string,
2487
- details?: T // @ts-ignore
2488
- ): HttpxPromise<HttpxAsyncResult<T>>;
2545
+ details: HttpxDetails // @ts-ignore
2546
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2489
2547
  /**
2490
2548
  * HEAD 请求
2491
2549
  */
@@ -2533,18 +2591,25 @@ class Httpx {
2533
2591
  * OPTIONS 请求
2534
2592
  * @param details 配置
2535
2593
  */
2536
- options<T extends HttpxDetails>(
2537
- details: T // @ts-ignore
2538
- ): HttpxPromise<HttpxAsyncResult<T>>;
2594
+ options(
2595
+ details: HttpxDetails // @ts-ignore
2596
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2597
+ /**
2598
+ * OPTIONS 请求
2599
+ * @param url 网址
2600
+ */
2601
+ options(
2602
+ url: string // @ts-ignore
2603
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2539
2604
  /**
2540
2605
  * OPTIONS 请求
2541
2606
  * @param url 网址
2542
2607
  * @param details 配置
2543
2608
  */
2544
- options<T extends HttpxDetails>(
2609
+ options(
2545
2610
  url: string,
2546
- details?: T // @ts-ignore
2547
- ): HttpxPromise<HttpxAsyncResult<T>>;
2611
+ details: HttpxDetails // @ts-ignore
2612
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2548
2613
  /**
2549
2614
  * OPTIONS 请求
2550
2615
  */
@@ -2589,18 +2654,25 @@ class Httpx {
2589
2654
  * DELETE 请求
2590
2655
  * @param details 配置
2591
2656
  */
2592
- async delete<T extends HttpxDetails>(
2593
- details: T // @ts-ignore
2594
- ): HttpxPromise<HttpxAsyncResult<T>>;
2657
+ async delete(
2658
+ details: HttpxDetails // @ts-ignore
2659
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2660
+ /**
2661
+ * DELETE 请求
2662
+ * @param url 网址
2663
+ */
2664
+ async delete(
2665
+ url: string // @ts-ignore
2666
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2595
2667
  /**
2596
2668
  * DELETE 请求
2597
2669
  * @param url 网址
2598
2670
  * @param details 配置
2599
2671
  */
2600
- async delete<T extends HttpxDetails>(
2672
+ async delete(
2601
2673
  url: string,
2602
- details?: T // @ts-ignore
2603
- ): HttpxPromise<HttpxAsyncResult<T>>;
2674
+ details: HttpxDetails // @ts-ignore
2675
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2604
2676
  /**
2605
2677
  * DELETE 请求
2606
2678
  */
@@ -2646,18 +2718,25 @@ class Httpx {
2646
2718
  * PUT 请求
2647
2719
  * @param details 配置
2648
2720
  */
2649
- async put<T extends HttpxDetails>(
2650
- details: T // @ts-ignore
2651
- ): HttpxPromise<HttpxAsyncResult<T>>;
2721
+ async put(
2722
+ details: HttpxDetails // @ts-ignore
2723
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2724
+ /**
2725
+ * PUT 请求
2726
+ * @param url 网址
2727
+ */
2728
+ async put(
2729
+ url: string // @ts-ignore
2730
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2652
2731
  /**
2653
2732
  * PUT 请求
2654
2733
  * @param url 网址
2655
2734
  * @param details 配置
2656
2735
  */
2657
- async put<T extends HttpxDetails>(
2736
+ async put(
2658
2737
  url: string,
2659
- details?: T // @ts-ignore
2660
- ): HttpxPromise<HttpxAsyncResult<T>>;
2738
+ details: HttpxDetails // @ts-ignore
2739
+ ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
2661
2740
  /**
2662
2741
  * PUT 请求
2663
2742
  */