utils-lib-js 2.0.19 → 2.0.21

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.
package/README.en.md CHANGED
@@ -401,6 +401,33 @@ console.log(demotedArray);
401
401
  // Output: reduced array [1, 2, 3, 4, 5]
402
402
  ```
403
403
 
404
+ ##### 4. arrayLoop(list: any[], current? : number): { item: any; current: number }
405
+
406
+ Walks through the elements in the group and returns the current element and its index.
407
+
408
+ - 'list' : The array to traverse.
409
+ - 'current' : indicates the index of the current element. The default is 0.
410
+
411
+ ```javascript
412
+ // Each time the arrayLoop function is called, current is incremented by 1 and takes the module length to loop to the beginning of the array.
413
+ const list = [
414
+ " Element 1",
415
+ "element 2",
416
+ " element 3",
417
+ "element 4",
418
+ " element 5",
419
+ ];
420
+ // Simulation loop multiple times
421
+ let c = 0;
422
+ Array(10)
423
+ .fill("")
424
+ .forEach(() => {
425
+ const { item, current } = arrayLoop(list, c);
426
+ c = current;
427
+ console.log(item, c); // 1,2,3,4,0,1,2,3,4,0
428
+ });
429
+ ```
430
+
404
431
  #### function module
405
432
 
406
433
  ##### 1. `throttle(fn: Function, time: number): Function`
package/README.md CHANGED
@@ -401,6 +401,27 @@ console.log(demotedArray);
401
401
  // 输出: 降维后的数组 [1, 2, 3, 4, 5]
402
402
  ```
403
403
 
404
+ ##### 4. arrayLoop(list: any[], current?: number): { item: any; current: number }
405
+
406
+ 遍历数组中的元素,并返回当前元素及其索引。
407
+
408
+ - `list`: 要遍历的数组。
409
+ - `current`: 当前元素的索引,默认为 0。
410
+
411
+ ```javascript
412
+ // 每次调用arrayLoop函数时,current将加 1,并取模数组长度,以循环到数组的开始。
413
+ const list = ["元素1", "元素2", "元素3", "元素4", "元素5"];
414
+ // 模拟循环多次
415
+ let c = 0;
416
+ Array(10)
417
+ .fill("")
418
+ .forEach(() => {
419
+ const { item, current } = arrayLoop(list, c);
420
+ c = current;
421
+ console.log(item, c); // 1,2,3,4,0,1,2,3,4,0
422
+ });
423
+ ```
424
+
404
425
  #### function 模块
405
426
 
406
427
  ##### 1. `throttle(fn: Function, time: number): Function`
@@ -1,10 +1,12 @@
1
- import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./types";
1
+ import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray, IArrayLoop } from "./types";
2
2
  export declare const arrayRandom: IArrayRandom<any[]>;
3
3
  export declare const arrayUniq: IArrayUniq<any[]>;
4
4
  export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
5
+ export declare const arrayLoop: IArrayLoop;
5
6
  declare const _default: {
6
7
  arrayRandom: IArrayRandom<any[]>;
7
8
  arrayUniq: IArrayUniq<any[]>;
8
9
  arrayDemote: IArrayDemote<IDemoteArray<any>>;
10
+ arrayLoop: IArrayLoop;
9
11
  };
10
12
  export default _default;
@@ -50,6 +50,7 @@ declare const _default: {
50
50
  arrayRandom: import("./types").IArrayRandom<any[]>;
51
51
  arrayUniq: import("./types").IArrayUniq<any[]>;
52
52
  arrayDemote: import("./types").IArrayDemote<import("./types").IDemoteArray<any>>;
53
+ arrayLoop: import("./types").IArrayLoop;
53
54
  randomNum: import("./types").IRandomNum;
54
55
  urlSplit: import("./types").IUrlSplit;
55
56
  urlJoin: import("./types").IUrlJoin;