@whitesev/utils 2.5.5 → 2.5.7

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.
@@ -1422,6 +1422,53 @@ declare class Utils {
1422
1422
  * await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
1423
1423
  **/
1424
1424
  waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: Function): Promise<void[]>;
1425
+ /**
1426
+ * 等待任意事件成立
1427
+ *
1428
+ * 运行方式为根据页面元素的改变而触发回调
1429
+ * @param checkFn 检测的函数
1430
+ * @param timeout 超时时间,默认0
1431
+ * @param parent (可选)父元素,默认document
1432
+ * @example
1433
+ * Utils.wait(()=> {
1434
+ * let $test = document.querySelector("#test");
1435
+ * return {
1436
+ * success: $test !== null,
1437
+ * data: $test
1438
+ * }
1439
+ * })
1440
+ */
1441
+ wait<T extends any>(checkFn: (...args: any[]) => {
1442
+ /**
1443
+ * 是否检测成功
1444
+ */
1445
+ success: boolean;
1446
+ /**
1447
+ * 返回的值
1448
+ */
1449
+ data: T;
1450
+ }, timeout?: null | undefined, parent?: Node | Element | Document | HTMLElement): Promise<T>;
1451
+ wait<T extends any>(checkFn: (...args: any[]) => {
1452
+ /**
1453
+ * 是否检测成功
1454
+ */
1455
+ success: boolean;
1456
+ /**
1457
+ * 返回的值
1458
+ */
1459
+ data: T;
1460
+ }, timeout?: number, parent?: Node | Element | Document | HTMLElement): Promise<T | null>;
1461
+ /**
1462
+ * 等待元素出现
1463
+ * @param selectorFn 获取元素的函数
1464
+ * @param timeout 超时时间,默认0
1465
+ * @example
1466
+ * Utils.waitNode(()=>document.querySelector("div"), 1000).then( $div =>{
1467
+ * console.log($div); // $div => HTMLDivELement | null
1468
+ * })
1469
+ */
1470
+ waitNode<K extends any>(selectorFn: () => K | null | undefined): Promise<K>;
1471
+ waitNode<K extends any>(selectorFn: () => K | null | undefined, timeout: number): Promise<K | null | undefined>;
1425
1472
  /**
1426
1473
  * 等待元素出现
1427
1474
  * @param selector CSS选择器
@@ -1430,7 +1477,7 @@ declare class Utils {
1430
1477
  * Utils.waitNode("div").then( $div =>{
1431
1478
  * console.log($div); // div => HTMLDivELement
1432
1479
  * })
1433
- * Utils.waitNode("div",document).then( $div =>{
1480
+ * Utils.waitNode("div", document).then( $div =>{
1434
1481
  * console.log($div); // div => HTMLDivELement
1435
1482
  * })
1436
1483
  */
@@ -1444,7 +1491,7 @@ declare class Utils {
1444
1491
  * Utils.waitNode(["div"]).then( ([$div]) =>{
1445
1492
  * console.log($div); // div => HTMLDivELement[]
1446
1493
  * })
1447
- * Utils.waitNode(["div"],document).then( ([$div]) =>{
1494
+ * Utils.waitNode(["div"], document).then( ([$div]) =>{
1448
1495
  * console.log($div); // div => HTMLDivELement[]
1449
1496
  * })
1450
1497
  */
@@ -1456,7 +1503,7 @@ declare class Utils {
1456
1503
  * @param parent 父元素,默认document
1457
1504
  * @param timeout 超时时间,默认0
1458
1505
  * @example
1459
- * Utils.waitNode("div",document,1000).then( $div =>{
1506
+ * Utils.waitNode("div", document, 1000).then( $div =>{
1460
1507
  * console.log($div); // $div => HTMLDivELement | null
1461
1508
  * })
1462
1509
  */
@@ -1468,7 +1515,7 @@ declare class Utils {
1468
1515
  * @param parent 父元素,默认document
1469
1516
  * @param timeout 超时时间,默认0
1470
1517
  * @example
1471
- * Utils.waitNode(["div"],document,1000).then( ([$div]) =>{
1518
+ * Utils.waitNode(["div"], document, 1000).then( ([$div]) =>{
1472
1519
  * console.log($div); // $div => HTMLDivELement[] | null
1473
1520
  * })
1474
1521
  */
@@ -1479,7 +1526,7 @@ declare class Utils {
1479
1526
  * @param selector CSS选择器
1480
1527
  * @param timeout 超时时间,默认0
1481
1528
  * @example
1482
- * Utils.waitNode("div",1000).then( $div =>{
1529
+ * Utils.waitNode("div", 1000).then( $div =>{
1483
1530
  * console.log($div); // $div => HTMLDivELement | null
1484
1531
  * })
1485
1532
  */
@@ -1490,7 +1537,7 @@ declare class Utils {
1490
1537
  * @param selectorList CSS选择器数组
1491
1538
  * @param timeout 超时时间,默认0
1492
1539
  * @example
1493
- * Utils.waitNode(["div"],1000).then( [$div] =>{
1540
+ * Utils.waitNode(["div"], 1000).then( [$div] =>{
1494
1541
  * console.log($div); // $div => HTMLDivELement[] | null
1495
1542
  * })
1496
1543
  */
@@ -1504,7 +1551,7 @@ declare class Utils {
1504
1551
  * Utils.waitAnyNode(["div","div"]).then( $div =>{
1505
1552
  * console.log($div); // $div => HTMLDivELement 这里是第一个
1506
1553
  * })
1507
- * Utils.waitAnyNode(["a","div"],document).then( $a =>{
1554
+ * Utils.waitAnyNode(["a","div"], document).then( $a =>{
1508
1555
  * console.log($a); // $a => HTMLAnchorElement 这里是第一个
1509
1556
  * })
1510
1557
  */
@@ -1516,7 +1563,7 @@ declare class Utils {
1516
1563
  * @param parent 父元素,默认document
1517
1564
  * @param timeout 超时时间,默认0
1518
1565
  * @example
1519
- * Utils.waitAnyNode(["div","div"],document,10000).then( $div =>{
1566
+ * Utils.waitAnyNode(["div","div"], document, 10000).then( $div =>{
1520
1567
  * console.log($div); // $div => HTMLDivELement | null
1521
1568
  * })
1522
1569
  */
@@ -1527,7 +1574,7 @@ declare class Utils {
1527
1574
  * @param selectorList CSS选择器数组
1528
1575
  * @param timeout 超时时间,默认0
1529
1576
  * @example
1530
- * Utils.waitAnyNode(["div","div"],10000).then( $div =>{
1577
+ * Utils.waitAnyNode(["div","div"], 10000).then( $div =>{
1531
1578
  * console.log($div); // $div => HTMLDivELement | null
1532
1579
  * })
1533
1580
  */
@@ -1541,7 +1588,7 @@ declare class Utils {
1541
1588
  * Utils.waitNodeList("div").then( $result =>{
1542
1589
  * console.log($result); // $result => NodeListOf<HTMLDivElement>
1543
1590
  * })
1544
- * Utils.waitNodeList("div",document).then( $result =>{
1591
+ * Utils.waitNodeList("div", document).then( $result =>{
1545
1592
  * console.log($result); // $result => NodeListOf<HTMLDivElement>
1546
1593
  * })
1547
1594
  */
@@ -1555,7 +1602,7 @@ declare class Utils {
1555
1602
  * Utils.waitNodeList(["div"]).then( $result =>{
1556
1603
  * console.log($result); // $result => NodeListOf<HTMLDivElement>[]
1557
1604
  * })
1558
- * Utils.waitNodeList(["div"],document).then( $result =>{
1605
+ * Utils.waitNodeList(["div"], document).then( $result =>{
1559
1606
  * console.log($result); // $result => NodeListOf<HTMLDivElement>[]
1560
1607
  * })
1561
1608
  */
@@ -1567,7 +1614,7 @@ declare class Utils {
1567
1614
  * @param parent 监听的父元素
1568
1615
  * @param timeout 超时时间,默认0
1569
1616
  * @example
1570
- * Utils.waitNodeList("div",document,10000).then( $result =>{
1617
+ * Utils.waitNodeList("div", document, 10000).then( $result =>{
1571
1618
  * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1572
1619
  * })
1573
1620
  */
@@ -1579,7 +1626,7 @@ declare class Utils {
1579
1626
  * @param parent 监听的父元素
1580
1627
  * @param timeout 超时时间,默认0
1581
1628
  * @example
1582
- * Utils.waitNodeList(["div"],document,10000).then( $result =>{
1629
+ * Utils.waitNodeList(["div"], document, 10000).then( $result =>{
1583
1630
  * console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
1584
1631
  * })
1585
1632
  */
@@ -1590,7 +1637,7 @@ declare class Utils {
1590
1637
  * @param selector CSS选择器数组
1591
1638
  * @param timeout 超时时间,默认0
1592
1639
  * @example
1593
- * Utils.waitNodeList("div",10000).then( $result =>{
1640
+ * Utils.waitNodeList("div", 10000).then( $result =>{
1594
1641
  * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1595
1642
  * })
1596
1643
  */
@@ -1601,7 +1648,7 @@ declare class Utils {
1601
1648
  * @param selectorList CSS选择器数组
1602
1649
  * @param timeout 超时时间,默认0
1603
1650
  * @example
1604
- * Utils.waitNodeList(["div"],10000).then( $result =>{
1651
+ * Utils.waitNodeList(["div"], 10000).then( $result =>{
1605
1652
  * console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
1606
1653
  * })
1607
1654
  */
@@ -1615,7 +1662,7 @@ declare class Utils {
1615
1662
  * Utils.waitAnyNodeList(["div","a"]).then( $result =>{
1616
1663
  * console.log($result); // $result => NodeListOf<HTMLDivElement>
1617
1664
  * })
1618
- * Utils.waitAnyNodeList(["div","a"],document).then( $result =>{
1665
+ * Utils.waitAnyNodeList(["div","a"], document).then( $result =>{
1619
1666
  * console.log($result); // $result => NodeListOf<HTMLDivElement>
1620
1667
  * })
1621
1668
  */
@@ -1627,7 +1674,7 @@ declare class Utils {
1627
1674
  * @param parent 父元素,默认document
1628
1675
  * @param timeout 超时时间,默认0
1629
1676
  * @example
1630
- * Utils.waitAnyNodeList(["div","a"],document,10000).then( $result =>{
1677
+ * Utils.waitAnyNodeList(["div","a"], document, 10000).then( $result =>{
1631
1678
  * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1632
1679
  * })
1633
1680
  */
@@ -1638,7 +1685,7 @@ declare class Utils {
1638
1685
  * @param selectorList CSS选择器数组
1639
1686
  * @param timeout 超时时间,默认0
1640
1687
  * @example
1641
- * Utils.waitAnyNodeList(["div","div"],10000).then( $result =>{
1688
+ * Utils.waitAnyNodeList(["div","div"], 10000).then( $result =>{
1642
1689
  * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1643
1690
  * })
1644
1691
  */
@@ -32,5 +32,14 @@ declare class UtilsGMCookie {
32
32
  * @param callback 删除操作后的回调(成功/失败)
33
33
  */
34
34
  delete(option: UtilsGMCookieDeleteOptions, callback?: (error?: Error) => void): void;
35
+ /**
36
+ * 解析cookie字符串
37
+ * 例如:document.cookie
38
+ * @param cookieStr
39
+ */
40
+ parseCookie(cookieStr: string): {
41
+ key: string;
42
+ value: string;
43
+ }[];
35
44
  }
36
45
  export { UtilsGMCookie };
@@ -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.5",
3
+ "version": "2.5.7",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",