utils-lib-js 2.0.19 → 2.0.20
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 +27 -0
- package/README.md +21 -0
- package/package.json +51 -51
- package/dist/bundle/animate.d.ts +0 -25
- package/dist/bundle/array.d.ts +0 -10
- package/dist/bundle/base.d.ts +0 -17
- package/dist/bundle/element.d.ts +0 -6
- package/dist/bundle/event.d.ts +0 -14
- package/dist/bundle/function.d.ts +0 -13
- package/dist/bundle/index.d.ts +0 -76
- package/dist/bundle/index.js +0 -49
- package/dist/bundle/log.d.ts +0 -8
- package/dist/bundle/object.d.ts +0 -36
- package/dist/bundle/static.d.ts +0 -16
- package/dist/bundle/storage.d.ts +0 -9
- package/dist/bundle/types.d.ts +0 -69
- package/dist/cjs/animate.d.ts +0 -25
- package/dist/cjs/array.d.ts +0 -10
- package/dist/cjs/base.d.ts +0 -17
- package/dist/cjs/element.d.ts +0 -6
- package/dist/cjs/event.d.ts +0 -14
- package/dist/cjs/function.d.ts +0 -13
- package/dist/cjs/index.d.ts +0 -76
- package/dist/cjs/index.js +0 -49
- package/dist/cjs/log.d.ts +0 -8
- package/dist/cjs/object.d.ts +0 -36
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/static.d.ts +0 -16
- package/dist/cjs/storage.d.ts +0 -9
- package/dist/cjs/types.d.ts +0 -69
- package/dist/esm/animate.d.ts +0 -25
- package/dist/esm/array.d.ts +0 -10
- package/dist/esm/base.d.ts +0 -17
- package/dist/esm/element.d.ts +0 -6
- package/dist/esm/event.d.ts +0 -14
- package/dist/esm/function.d.ts +0 -13
- package/dist/esm/index.d.ts +0 -76
- package/dist/esm/index.js +0 -49
- package/dist/esm/log.d.ts +0 -8
- package/dist/esm/object.d.ts +0 -36
- package/dist/esm/static.d.ts +0 -16
- package/dist/esm/storage.d.ts +0 -9
- package/dist/esm/types.d.ts +0 -69
- package/dist/umd/animate.d.ts +0 -25
- package/dist/umd/array.d.ts +0 -10
- package/dist/umd/base.d.ts +0 -17
- package/dist/umd/element.d.ts +0 -6
- package/dist/umd/event.d.ts +0 -14
- package/dist/umd/function.d.ts +0 -13
- package/dist/umd/index.d.ts +0 -76
- package/dist/umd/index.js +0 -49
- package/dist/umd/log.d.ts +0 -8
- package/dist/umd/object.d.ts +0 -36
- package/dist/umd/static.d.ts +0 -16
- package/dist/umd/storage.d.ts +0 -9
- package/dist/umd/types.d.ts +0 -69
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`
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "utils-lib-js",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "JavaScript工具函数,封装的一些常用的js函数",
|
|
5
|
-
"main": "./dist/cjs/index.js",
|
|
6
|
-
"types": "./dist/cjs/index.d.ts",
|
|
7
|
-
"module": "./dist/esm/index.js",
|
|
8
|
-
"type": "module",
|
|
9
|
-
"exports": {
|
|
10
|
-
"import": "./dist/esm/index.js",
|
|
11
|
-
"require": "./dist/cjs/index.js"
|
|
12
|
-
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "utils-lib-js",
|
|
3
|
+
"version": "2.0.20",
|
|
4
|
+
"description": "JavaScript工具函数,封装的一些常用的js函数",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"types": "./dist/cjs/index.d.ts",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"debug": "start cmd /k pnpm run build:hot & pnpm run node:hot",
|
|
15
|
+
"node:hot": "nodemon example.js --watch example.js",
|
|
16
|
+
"build:hot": "pnpm rollup -c --watch",
|
|
17
|
+
"build": "pnpm run rollup:build && pnpm run commonjs",
|
|
18
|
+
"rollup:build": "rm -fr dist && pnpm rollup -c",
|
|
19
|
+
"build:publish": "pnpm run build && pnpm publish",
|
|
20
|
+
"commonjs": "cp ./commonjs.json dist/cjs/package.json"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://gitee.com/DieHunter/utils-lib-js.git"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"utils",
|
|
28
|
+
"tools",
|
|
29
|
+
"lib"
|
|
30
|
+
],
|
|
31
|
+
"author": "",
|
|
32
|
+
"license": "ISC",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@rollup/plugin-alias": "^4.0.3",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
36
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
37
|
+
"@types/node": "^18.7.15",
|
|
38
|
+
"rollup": "^3.20.2",
|
|
39
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
40
|
+
"tslib": "^2.5.0",
|
|
41
|
+
"typescript": "^4.9.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"event-message-center": "^1.4.0",
|
|
45
|
+
"js-log-lib": "^1.1.2",
|
|
46
|
+
"js-request-lib": "^1.0.7",
|
|
47
|
+
"task-queue-lib": "^1.4.2",
|
|
48
|
+
"timer-manager-lib": "^1.0.0"
|
|
49
|
+
},
|
|
50
|
+
"umdModuleName": "UtilsLib"
|
|
51
|
+
}
|
package/dist/bundle/animate.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { IAnimateFrame } from "./types";
|
|
2
|
-
export declare class AnimateFrame implements IAnimateFrame {
|
|
3
|
-
fn: any;
|
|
4
|
-
id: any;
|
|
5
|
-
duration: number;
|
|
6
|
-
isActive: boolean;
|
|
7
|
-
constructor(fn: any);
|
|
8
|
-
start(duration: any): any;
|
|
9
|
-
stop(id?: any): void;
|
|
10
|
-
animate(timer?: number): any;
|
|
11
|
-
}
|
|
12
|
-
export declare function quadraticBezier(_x: number, _y: number, t: number): number[];
|
|
13
|
-
export declare function cubicBezier(_x1: number, _y1: number, _x2: number, _y2: number, t: number): number[];
|
|
14
|
-
export declare function factorial(n: number): any;
|
|
15
|
-
export declare function combination(n: number, k: number): number;
|
|
16
|
-
export declare function NBezier(points: number[][], t: number): number[];
|
|
17
|
-
declare const _default: {
|
|
18
|
-
AnimateFrame: typeof AnimateFrame;
|
|
19
|
-
quadraticBezier: typeof quadraticBezier;
|
|
20
|
-
cubicBezier: typeof cubicBezier;
|
|
21
|
-
factorial: typeof factorial;
|
|
22
|
-
combination: typeof combination;
|
|
23
|
-
NBezier: typeof NBezier;
|
|
24
|
-
};
|
|
25
|
-
export default _default;
|
package/dist/bundle/array.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./types";
|
|
2
|
-
export declare const arrayRandom: IArrayRandom<any[]>;
|
|
3
|
-
export declare const arrayUniq: IArrayUniq<any[]>;
|
|
4
|
-
export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
|
|
5
|
-
declare const _default: {
|
|
6
|
-
arrayRandom: IArrayRandom<any[]>;
|
|
7
|
-
arrayUniq: IArrayUniq<any[]>;
|
|
8
|
-
arrayDemote: IArrayDemote<IDemoteArray<any>>;
|
|
9
|
-
};
|
|
10
|
-
export default _default;
|
package/dist/bundle/base.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IRandomNum, IUrlSplit, IUrlJoin, IGetType, IGetTypeByList } from "./types";
|
|
2
|
-
import { types } from "./static";
|
|
3
|
-
export declare const randomNum: IRandomNum;
|
|
4
|
-
export declare const urlSplit: IUrlSplit;
|
|
5
|
-
export declare const urlJoin: IUrlJoin;
|
|
6
|
-
export declare const getType: IGetType<types>;
|
|
7
|
-
export declare const getTypeByList: IGetTypeByList;
|
|
8
|
-
export declare const toKebabCase: (camelCase: string, separator?: string) => string;
|
|
9
|
-
declare const _default: {
|
|
10
|
-
randomNum: IRandomNum;
|
|
11
|
-
urlSplit: IUrlSplit;
|
|
12
|
-
urlJoin: IUrlJoin;
|
|
13
|
-
getType: IGetType<types>;
|
|
14
|
-
getTypeByList: IGetTypeByList;
|
|
15
|
-
toKebabCase: (camelCase: string, separator?: string) => string;
|
|
16
|
-
};
|
|
17
|
-
export default _default;
|
package/dist/bundle/element.d.ts
DELETED
package/dist/bundle/event.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./types";
|
|
2
|
-
export declare const addHandler: IAddHandler;
|
|
3
|
-
export declare const stopBubble: IStopBubble;
|
|
4
|
-
export declare const stopDefault: IStopDefault;
|
|
5
|
-
export declare const removeHandler: IRemoveHandler;
|
|
6
|
-
export declare const dispatchEvent: IDispatchEvent;
|
|
7
|
-
declare const _default: {
|
|
8
|
-
addHandler: IAddHandler;
|
|
9
|
-
stopBubble: IStopBubble;
|
|
10
|
-
stopDefault: IStopDefault;
|
|
11
|
-
removeHandler: IRemoveHandler;
|
|
12
|
-
dispatchEvent: IDispatchEvent;
|
|
13
|
-
};
|
|
14
|
-
export default _default;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ICatchAwait, IThrottle, IDebounce, IDefer, IRequestFrame } from "./types";
|
|
2
|
-
export declare const throttle: IThrottle;
|
|
3
|
-
export declare const debounce: IDebounce;
|
|
4
|
-
export declare const defer: IDefer;
|
|
5
|
-
export declare const catchAwait: ICatchAwait<Promise<any>>;
|
|
6
|
-
export declare const requestFrame: IRequestFrame;
|
|
7
|
-
declare const _default: {
|
|
8
|
-
throttle: IThrottle;
|
|
9
|
-
debounce: IDebounce;
|
|
10
|
-
defer: IDefer;
|
|
11
|
-
catchAwait: ICatchAwait<Promise<any>>;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
package/dist/bundle/index.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
export * from "./object";
|
|
2
|
-
export * from "./base";
|
|
3
|
-
export * from "./array";
|
|
4
|
-
export * from "./function";
|
|
5
|
-
export * from "./element";
|
|
6
|
-
export * from "./static";
|
|
7
|
-
export * from "./types";
|
|
8
|
-
export * from "./event";
|
|
9
|
-
export * from "./storage";
|
|
10
|
-
export * from "./log";
|
|
11
|
-
export * from "./animate";
|
|
12
|
-
export * from "event-message-center";
|
|
13
|
-
export * from "task-queue-lib";
|
|
14
|
-
export * from "js-request-lib";
|
|
15
|
-
export * from "timer-manager-lib";
|
|
16
|
-
export * from "js-log-lib";
|
|
17
|
-
import eventMessageCenter from "event-message-center";
|
|
18
|
-
import taskQueueLib from "task-queue-lib";
|
|
19
|
-
import JSRequest from "js-request-lib";
|
|
20
|
-
import TimerManager from "timer-manager-lib";
|
|
21
|
-
import JSLogLib from "js-log-lib";
|
|
22
|
-
declare const _default: {
|
|
23
|
-
eventMessageCenter: typeof eventMessageCenter;
|
|
24
|
-
taskQueueLib: typeof taskQueueLib;
|
|
25
|
-
JSRequest: typeof JSRequest;
|
|
26
|
-
TimerManager: typeof TimerManager;
|
|
27
|
-
JSLogLib: typeof JSLogLib;
|
|
28
|
-
AnimateFrame: typeof import("./animate").AnimateFrame;
|
|
29
|
-
quadraticBezier: typeof import("./animate").quadraticBezier;
|
|
30
|
-
cubicBezier: typeof import("./animate").cubicBezier;
|
|
31
|
-
factorial: typeof import("./animate").factorial;
|
|
32
|
-
combination: typeof import("./animate").combination;
|
|
33
|
-
NBezier: typeof import("./animate").NBezier;
|
|
34
|
-
logOneLine: import("./types").ILogOneLine;
|
|
35
|
-
logLoop: import("./types").ILogLoop;
|
|
36
|
-
setStorage: (key: string, val: any) => void;
|
|
37
|
-
getStorage: (key: string) => any;
|
|
38
|
-
clearStorage: (key: string) => void;
|
|
39
|
-
addHandler: import("./types").IAddHandler;
|
|
40
|
-
stopBubble: import("./types").IStopBubble;
|
|
41
|
-
stopDefault: import("./types").IStopDefault;
|
|
42
|
-
removeHandler: import("./types").IRemoveHandler;
|
|
43
|
-
dispatchEvent: import("./types").IDispatchEvent;
|
|
44
|
-
types: typeof import("./static").types;
|
|
45
|
-
createElement: import("./types").ICreateElement<HTMLElement>;
|
|
46
|
-
throttle: import("./types").IThrottle;
|
|
47
|
-
debounce: import("./types").IDebounce;
|
|
48
|
-
defer: import("./types").IDefer;
|
|
49
|
-
catchAwait: import("./types").ICatchAwait<Promise<any>>;
|
|
50
|
-
arrayRandom: import("./types").IArrayRandom<any[]>;
|
|
51
|
-
arrayUniq: import("./types").IArrayUniq<any[]>;
|
|
52
|
-
arrayDemote: import("./types").IArrayDemote<import("./types").IDemoteArray<any>>;
|
|
53
|
-
randomNum: import("./types").IRandomNum;
|
|
54
|
-
urlSplit: import("./types").IUrlSplit;
|
|
55
|
-
urlJoin: import("./types").IUrlJoin;
|
|
56
|
-
getType: import("./types").IGetType<import("./static").types>;
|
|
57
|
-
getTypeByList: import("./types").IGetTypeByList;
|
|
58
|
-
toKebabCase: (camelCase: string, separator?: string) => string;
|
|
59
|
-
getValue: import("./types").IGetValue;
|
|
60
|
-
setValue: import("./types").ISetValue;
|
|
61
|
-
mixIn: import("./types").IMixIn;
|
|
62
|
-
enumInversion: import("./types").IEnumInversion;
|
|
63
|
-
isNotObject: (source: any, type: any) => boolean;
|
|
64
|
-
cloneDeep: import("./types").ICloneDeep;
|
|
65
|
-
createObjectVariable: import("./types").ICreateObjectVariable;
|
|
66
|
-
createObject: import("./types").ICreateObject;
|
|
67
|
-
inherit: import("./types").IInherit;
|
|
68
|
-
getInstance: import("./types").IGetInstance;
|
|
69
|
-
classDecorator: import("./types").IClassDecorator;
|
|
70
|
-
stringToJson: import("./types").IStringToJson;
|
|
71
|
-
jsonToString: import("./types").IJsonToString;
|
|
72
|
-
isWindow: (win: any) => boolean;
|
|
73
|
-
emptyObject: (init?: import("./types").IObject<unknown>) => any;
|
|
74
|
-
isEmptyObject: (object?: import("./types").IObject<unknown>) => boolean;
|
|
75
|
-
};
|
|
76
|
-
export default _default;
|