@whitesev/utils 2.5.6 → 2.5.8

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.
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Main moduleRaid class
3
+ * @link https://scriptcat.org/zh-CN/script-show-page/2628
4
+ */
5
+ export class ModuleRaid {
6
+ /**
7
+ * moduleRaid constructor
8
+ *
9
+ * @example
10
+ * Constructing an instance without any arguments:
11
+ * ```ts
12
+ * const mR = new ModuleRaid()
13
+ * ```
14
+ *
15
+ * Constructing an instance with the optional `opts` object:
16
+ * ```ts
17
+ * const mR = new ModuleRaid({ entrypoint: 'webpackChunk_custom_name' })
18
+ * ```
19
+ *
20
+ * @param opts a object containing options to initialize moduleRaid with
21
+ * - **opts:**
22
+ * - _target_: the window object being searched for
23
+ * - _entrypoint_: the Webpack entrypoint present on the global window object
24
+ * - _debug_: whether debug mode is enabled or not
25
+ * - _strict_: whether strict mode is enabled or not
26
+ */
27
+ constructor(opts: any);
28
+ /**
29
+ * A random generated module ID we use for injecting into Webpack
30
+ */
31
+ moduleID: string;
32
+ /**
33
+ * An array containing different argument injection methods for
34
+ * Webpack (before version 4), and subsequently pulling out methods and modules
35
+ * @internal
36
+ */
37
+ functionArguments: ((number[] | ((_e: any, _t: any, i: any) => void)[])[] | (number[] | string[][] | {
38
+ [x: string]: (_e: any, _t: any, i: any) => void;
39
+ })[])[];
40
+ modules: {};
41
+ constructors: any[];
42
+ get: any;
43
+ /**
44
+ * An array containing different argument injection methods for
45
+ * Webpack (after version 4), and subsequently pulling out methods and modules
46
+ * @internal
47
+ */
48
+ arrayArguments: ((number[] | ((_e: any, _t: any, i: any) => void)[])[] | {}[] | (number[] | string[][] | {
49
+ [x: string]: (_e: any, _t: any, i: any) => void;
50
+ })[])[];
51
+ target: Window & typeof globalThis;
52
+ entrypoint: string;
53
+ debug: boolean;
54
+ strict: boolean;
55
+ /**
56
+ * Debug logging method, outputs to the console when {@link ModuleRaid.debug} is true
57
+ *
58
+ * @param {*} message The message to be logged
59
+ * @internal
60
+ */
61
+ log(message: any): void;
62
+ /**
63
+ * Method to set an alternative getter if we weren't able to extract __webpack_require__
64
+ * from Webpack
65
+ * @internal
66
+ */
67
+ replaceGet(): void;
68
+ /**
69
+ * Method that will try to inject a module into Webpack or get modules
70
+ * depending on it's success it might be more or less brute about it
71
+ * @internal
72
+ */
73
+ fillModules(): void;
74
+ /**
75
+ * Method to hook into `window[this.entrypoint].push` adding a listener for new
76
+ * chunks being pushed into Webpack
77
+ *
78
+ * @example
79
+ * You can listen for newly pushed packages using the `moduleraid:webpack-push` event
80
+ * on `document`
81
+ *
82
+ * ```ts
83
+ * document.addEventListener('moduleraid:webpack-push', (e) => {
84
+ * // e.detail contains the arguments push() was called with
85
+ * console.log(e.detail)
86
+ * })
87
+ * ```
88
+ * @internal
89
+ */
90
+ setupPushEvent(): void;
91
+ /**
92
+ * Method to try autodetecting a Webpack JSONP entrypoint based on common naming
93
+ *
94
+ * If the default entrypoint, or the entrypoint that's passed to the moduleRaid constructor
95
+ * already matches, the method exits early
96
+ *
97
+ * If `options.strict` has been set in the constructor and the initial entrypoint cannot
98
+ * be found, this method will error, demanding a strictly set entrypoint
99
+ * @internal
100
+ */
101
+ detectEntrypoint(): void;
102
+ /**
103
+ * Recursive object-search function for modules
104
+ *
105
+ * @param object the object to search through
106
+ * @param query the query the object keys/values are searched for
107
+ * @returns boolean state of `object` containing `query` somewhere in it
108
+ * @internal
109
+ */
110
+ searchObject(object: any, query: any): boolean;
111
+ /**
112
+ * Method to search through the module object, searching for the fitting content
113
+ * if a string is supplied
114
+ *
115
+ * If query is supplied as a function, everything that returns true when passed
116
+ * to the query function will be returned
117
+ *
118
+ * @example
119
+ * With a string as query argument:
120
+ * ```ts
121
+ * const results = mR.findModule('feature')
122
+ * // => Array of module results
123
+ * ```
124
+ *
125
+ * With a function as query argument:
126
+ * ```ts
127
+ * const results = mR.findModule((module) => { typeof module === 'function' })
128
+ * // => Array of module results
129
+ * ```
130
+ *
131
+ * @param query query to search the module list for
132
+ * @return a list of modules fitting the query
133
+ */
134
+ findModule(query: any): any[];
135
+ /**
136
+ * Method to search through the constructor array, searching for the fitting content
137
+ * if a string is supplied
138
+ *
139
+ * If query is supplied as a function, everything that returns true when passed
140
+ * to the query function will be returned
141
+ *
142
+ * @example
143
+ * With a string as query argument:
144
+ * ```ts
145
+ * const results = mR.findConstructor('feature')
146
+ * // => Array of constructor/module tuples
147
+ * ```
148
+ *
149
+ * With a function as query argument:
150
+ * ```ts
151
+ * const results = mR.findConstructor((constructor) => { constructor.prototype.value !== undefined })
152
+ * // => Array of constructor/module tuples
153
+ * ```
154
+ *
155
+ * Accessing the resulting data:
156
+ * ```ts
157
+ * // With array destructuring (ES6)
158
+ * const [constructor, module] = results[0]
159
+ *
160
+ * // ...or...
161
+ *
162
+ * // regular access
163
+ * const constructor = results[0][0]
164
+ * const module = results[0][1]
165
+ * ```
166
+ *
167
+ * @param query query to search the constructor list for
168
+ * @returns a list of constructor/module tuples fitting the query
169
+ */
170
+ findConstructor(query: any): any[];
171
+ }
@@ -5,12 +5,12 @@ export declare const TryCatch: (...args: any) => {
5
5
  * @param paramDetails 配置
6
6
  * @returns
7
7
  */
8
- config(paramDetails: UtilsTryCatchConfig): any;
8
+ config(paramDetails: UtilsTryCatchConfig): /*elided*/ any;
9
9
  /**
10
10
  * 处理错误
11
11
  * @param handler
12
12
  */
13
- error(handler: ((...args: any[]) => any) | string | Function): any;
13
+ error(handler: ((...args: any[]) => any) | string | Function): /*elided*/ any;
14
14
  /**
15
15
  * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
16
16
  * @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
@@ -14,6 +14,7 @@ import type { UtilsAjaxHookResult } from "./types/ajaxHooker";
14
14
  import { Vue } from "./Vue";
15
15
  import { type ArgsType, type JSTypeNames, type UtilsOwnObject } from "./types/global";
16
16
  import type { WindowApiOption } from "./types/WindowApi";
17
+ import { ModuleRaid } from "./ModuleRaid";
17
18
  declare class Utils {
18
19
  private windowApi;
19
20
  constructor(option?: WindowApiOption);
@@ -1382,8 +1383,8 @@ declare class Utils {
1382
1383
  * > ()=>{throw new Error('测试错误')}出现错误
1383
1384
  */
1384
1385
  tryCatch: (...args: any) => {
1385
- config(paramDetails: import("./types/TryCatch").UtilsTryCatchConfig): any;
1386
- error(handler: ((...args: any[]) => any) | string | Function): any;
1386
+ config(paramDetails: import("./types/TryCatch").UtilsTryCatchConfig): /*elided*/ any;
1387
+ error(handler: ((...args: any[]) => any) | string | Function): /*elided*/ any;
1387
1388
  run<A extends any[], R>(callback: ((...args: A) => R) | string | Function, __context__?: any): import("./types/TryCatch").UtilsTryCatchType;
1388
1389
  };
1389
1390
  /**
@@ -1422,6 +1423,53 @@ declare class Utils {
1422
1423
  * await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
1423
1424
  **/
1424
1425
  waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: Function): Promise<void[]>;
1426
+ /**
1427
+ * 等待任意事件成立
1428
+ *
1429
+ * 运行方式为根据页面元素的改变而触发回调
1430
+ * @param checkFn 检测的函数
1431
+ * @param timeout 超时时间,默认0
1432
+ * @param parent (可选)父元素,默认document
1433
+ * @example
1434
+ * Utils.wait(()=> {
1435
+ * let $test = document.querySelector("#test");
1436
+ * return {
1437
+ * success: $test !== null,
1438
+ * data: $test
1439
+ * }
1440
+ * })
1441
+ */
1442
+ wait<T extends any>(checkFn: (...args: any[]) => {
1443
+ /**
1444
+ * 是否检测成功
1445
+ */
1446
+ success: boolean;
1447
+ /**
1448
+ * 返回的值
1449
+ */
1450
+ data: T;
1451
+ }, timeout?: null | undefined, parent?: Node | Element | Document | HTMLElement): Promise<T>;
1452
+ wait<T extends any>(checkFn: (...args: any[]) => {
1453
+ /**
1454
+ * 是否检测成功
1455
+ */
1456
+ success: boolean;
1457
+ /**
1458
+ * 返回的值
1459
+ */
1460
+ data: T;
1461
+ }, timeout?: number, parent?: Node | Element | Document | HTMLElement): Promise<T | null>;
1462
+ /**
1463
+ * 等待元素出现
1464
+ * @param selectorFn 获取元素的函数
1465
+ * @param timeout 超时时间,默认0
1466
+ * @example
1467
+ * Utils.waitNode(()=>document.querySelector("div"), 1000).then( $div =>{
1468
+ * console.log($div); // $div => HTMLDivELement | null
1469
+ * })
1470
+ */
1471
+ waitNode<K extends any>(selectorFn: () => K | null | undefined): Promise<K>;
1472
+ waitNode<K extends any>(selectorFn: () => K | null | undefined, timeout: number): Promise<K | null | undefined>;
1425
1473
  /**
1426
1474
  * 等待元素出现
1427
1475
  * @param selector CSS选择器
@@ -1430,7 +1478,7 @@ declare class Utils {
1430
1478
  * Utils.waitNode("div").then( $div =>{
1431
1479
  * console.log($div); // div => HTMLDivELement
1432
1480
  * })
1433
- * Utils.waitNode("div",document).then( $div =>{
1481
+ * Utils.waitNode("div", document).then( $div =>{
1434
1482
  * console.log($div); // div => HTMLDivELement
1435
1483
  * })
1436
1484
  */
@@ -1444,7 +1492,7 @@ declare class Utils {
1444
1492
  * Utils.waitNode(["div"]).then( ([$div]) =>{
1445
1493
  * console.log($div); // div => HTMLDivELement[]
1446
1494
  * })
1447
- * Utils.waitNode(["div"],document).then( ([$div]) =>{
1495
+ * Utils.waitNode(["div"], document).then( ([$div]) =>{
1448
1496
  * console.log($div); // div => HTMLDivELement[]
1449
1497
  * })
1450
1498
  */
@@ -1456,7 +1504,7 @@ declare class Utils {
1456
1504
  * @param parent 父元素,默认document
1457
1505
  * @param timeout 超时时间,默认0
1458
1506
  * @example
1459
- * Utils.waitNode("div",document,1000).then( $div =>{
1507
+ * Utils.waitNode("div", document, 1000).then( $div =>{
1460
1508
  * console.log($div); // $div => HTMLDivELement | null
1461
1509
  * })
1462
1510
  */
@@ -1468,7 +1516,7 @@ declare class Utils {
1468
1516
  * @param parent 父元素,默认document
1469
1517
  * @param timeout 超时时间,默认0
1470
1518
  * @example
1471
- * Utils.waitNode(["div"],document,1000).then( ([$div]) =>{
1519
+ * Utils.waitNode(["div"], document, 1000).then( ([$div]) =>{
1472
1520
  * console.log($div); // $div => HTMLDivELement[] | null
1473
1521
  * })
1474
1522
  */
@@ -1479,7 +1527,7 @@ declare class Utils {
1479
1527
  * @param selector CSS选择器
1480
1528
  * @param timeout 超时时间,默认0
1481
1529
  * @example
1482
- * Utils.waitNode("div",1000).then( $div =>{
1530
+ * Utils.waitNode("div", 1000).then( $div =>{
1483
1531
  * console.log($div); // $div => HTMLDivELement | null
1484
1532
  * })
1485
1533
  */
@@ -1490,7 +1538,7 @@ declare class Utils {
1490
1538
  * @param selectorList CSS选择器数组
1491
1539
  * @param timeout 超时时间,默认0
1492
1540
  * @example
1493
- * Utils.waitNode(["div"],1000).then( [$div] =>{
1541
+ * Utils.waitNode(["div"], 1000).then( [$div] =>{
1494
1542
  * console.log($div); // $div => HTMLDivELement[] | null
1495
1543
  * })
1496
1544
  */
@@ -1504,7 +1552,7 @@ declare class Utils {
1504
1552
  * Utils.waitAnyNode(["div","div"]).then( $div =>{
1505
1553
  * console.log($div); // $div => HTMLDivELement 这里是第一个
1506
1554
  * })
1507
- * Utils.waitAnyNode(["a","div"],document).then( $a =>{
1555
+ * Utils.waitAnyNode(["a","div"], document).then( $a =>{
1508
1556
  * console.log($a); // $a => HTMLAnchorElement 这里是第一个
1509
1557
  * })
1510
1558
  */
@@ -1516,7 +1564,7 @@ declare class Utils {
1516
1564
  * @param parent 父元素,默认document
1517
1565
  * @param timeout 超时时间,默认0
1518
1566
  * @example
1519
- * Utils.waitAnyNode(["div","div"],document,10000).then( $div =>{
1567
+ * Utils.waitAnyNode(["div","div"], document, 10000).then( $div =>{
1520
1568
  * console.log($div); // $div => HTMLDivELement | null
1521
1569
  * })
1522
1570
  */
@@ -1527,7 +1575,7 @@ declare class Utils {
1527
1575
  * @param selectorList CSS选择器数组
1528
1576
  * @param timeout 超时时间,默认0
1529
1577
  * @example
1530
- * Utils.waitAnyNode(["div","div"],10000).then( $div =>{
1578
+ * Utils.waitAnyNode(["div","div"], 10000).then( $div =>{
1531
1579
  * console.log($div); // $div => HTMLDivELement | null
1532
1580
  * })
1533
1581
  */
@@ -1541,7 +1589,7 @@ declare class Utils {
1541
1589
  * Utils.waitNodeList("div").then( $result =>{
1542
1590
  * console.log($result); // $result => NodeListOf<HTMLDivElement>
1543
1591
  * })
1544
- * Utils.waitNodeList("div",document).then( $result =>{
1592
+ * Utils.waitNodeList("div", document).then( $result =>{
1545
1593
  * console.log($result); // $result => NodeListOf<HTMLDivElement>
1546
1594
  * })
1547
1595
  */
@@ -1555,7 +1603,7 @@ declare class Utils {
1555
1603
  * Utils.waitNodeList(["div"]).then( $result =>{
1556
1604
  * console.log($result); // $result => NodeListOf<HTMLDivElement>[]
1557
1605
  * })
1558
- * Utils.waitNodeList(["div"],document).then( $result =>{
1606
+ * Utils.waitNodeList(["div"], document).then( $result =>{
1559
1607
  * console.log($result); // $result => NodeListOf<HTMLDivElement>[]
1560
1608
  * })
1561
1609
  */
@@ -1567,7 +1615,7 @@ declare class Utils {
1567
1615
  * @param parent 监听的父元素
1568
1616
  * @param timeout 超时时间,默认0
1569
1617
  * @example
1570
- * Utils.waitNodeList("div",document,10000).then( $result =>{
1618
+ * Utils.waitNodeList("div", document, 10000).then( $result =>{
1571
1619
  * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1572
1620
  * })
1573
1621
  */
@@ -1579,7 +1627,7 @@ declare class Utils {
1579
1627
  * @param parent 监听的父元素
1580
1628
  * @param timeout 超时时间,默认0
1581
1629
  * @example
1582
- * Utils.waitNodeList(["div"],document,10000).then( $result =>{
1630
+ * Utils.waitNodeList(["div"], document, 10000).then( $result =>{
1583
1631
  * console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
1584
1632
  * })
1585
1633
  */
@@ -1590,7 +1638,7 @@ declare class Utils {
1590
1638
  * @param selector CSS选择器数组
1591
1639
  * @param timeout 超时时间,默认0
1592
1640
  * @example
1593
- * Utils.waitNodeList("div",10000).then( $result =>{
1641
+ * Utils.waitNodeList("div", 10000).then( $result =>{
1594
1642
  * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1595
1643
  * })
1596
1644
  */
@@ -1601,7 +1649,7 @@ declare class Utils {
1601
1649
  * @param selectorList CSS选择器数组
1602
1650
  * @param timeout 超时时间,默认0
1603
1651
  * @example
1604
- * Utils.waitNodeList(["div"],10000).then( $result =>{
1652
+ * Utils.waitNodeList(["div"], 10000).then( $result =>{
1605
1653
  * console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
1606
1654
  * })
1607
1655
  */
@@ -1615,7 +1663,7 @@ declare class Utils {
1615
1663
  * Utils.waitAnyNodeList(["div","a"]).then( $result =>{
1616
1664
  * console.log($result); // $result => NodeListOf<HTMLDivElement>
1617
1665
  * })
1618
- * Utils.waitAnyNodeList(["div","a"],document).then( $result =>{
1666
+ * Utils.waitAnyNodeList(["div","a"], document).then( $result =>{
1619
1667
  * console.log($result); // $result => NodeListOf<HTMLDivElement>
1620
1668
  * })
1621
1669
  */
@@ -1627,7 +1675,7 @@ declare class Utils {
1627
1675
  * @param parent 父元素,默认document
1628
1676
  * @param timeout 超时时间,默认0
1629
1677
  * @example
1630
- * Utils.waitAnyNodeList(["div","a"],document,10000).then( $result =>{
1678
+ * Utils.waitAnyNodeList(["div","a"], document, 10000).then( $result =>{
1631
1679
  * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1632
1680
  * })
1633
1681
  */
@@ -1638,7 +1686,7 @@ declare class Utils {
1638
1686
  * @param selectorList CSS选择器数组
1639
1687
  * @param timeout 超时时间,默认0
1640
1688
  * @example
1641
- * Utils.waitAnyNodeList(["div","div"],10000).then( $result =>{
1689
+ * Utils.waitAnyNodeList(["div","div"], 10000).then( $result =>{
1642
1690
  * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1643
1691
  * })
1644
1692
  */
@@ -1768,6 +1816,7 @@ declare class Utils {
1768
1816
  * > "测试"
1769
1817
  */
1770
1818
  Vue: typeof Vue;
1819
+ ModuleRaid: typeof ModuleRaid;
1771
1820
  }
1772
1821
  declare let utils: Utils;
1773
1822
  export { utils as Utils };
@@ -25,3 +25,4 @@ export declare interface AnyObject {
25
25
  export type PartialKeys<T, K extends keyof T> = {
26
26
  [P in K]?: T[P];
27
27
  };
28
+ export type Values<T> = T[keyof T];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.5.6",
3
+ "version": "2.5.8",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",