utils-lib-js 2.0.6 → 2.0.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.
- package/README.en.md +579 -414
- package/README.md +566 -415
- package/dist/bundle/index.js +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/umd/index.js +2 -2
- package/package.json +49 -49
- package/commonjs.json +0 -3
- package/example.js +0 -11
- package/pnpm-lock.yaml +0 -450
- package/rollup.config.js +0 -46
- package/tsconfig.json +0 -28
package/README.md
CHANGED
|
@@ -1,540 +1,691 @@
|
|
|
1
1
|
# utils-lib-js
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
JavaScript工具函数,封装的一些常用的js函数
|
|
3
|
+
## 介绍
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
软件架构说明
|
|
5
|
+
JavaScript 工具函数,封装的一些常用的 js 函数
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
#### 安装教程
|
|
11
|
-
|
|
12
|
-
1. pnpm i
|
|
13
|
-
2. pnpm build
|
|
14
|
-
|
|
15
|
-
#### 使用说明
|
|
7
|
+
## 调试说明
|
|
16
8
|
|
|
17
9
|
1. pnpm build(构建)
|
|
18
10
|
2. pnpm debug(调试源码)
|
|
11
|
+
3. 在 esm,cjs,window 环境下导入该工具库
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
## 参与贡献
|
|
21
14
|
|
|
22
15
|
1. Fork 本仓库
|
|
23
|
-
2.
|
|
16
|
+
2. Star 仓库
|
|
24
17
|
3. 提交代码
|
|
25
18
|
4. 新建 Pull Request
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
接口:
|
|
20
|
+
## 使用说明
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
### 安装
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
`npm install utils-lib-js`
|
|
25
|
+
或
|
|
26
|
+
`yarn add utils-lib-js`
|
|
27
|
+
或
|
|
28
|
+
`pnpm install utils-lib-js`
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
[key: IKey]: T | IObject<any>
|
|
36
|
-
}
|
|
30
|
+
### 引入
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
#### ESM
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
import { defer, messageCenter, TaskQueue, Request } from "utils-lib-js";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### CJS
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
const { defer, messageCenter, TaskQueue } = require("utils-lib-js");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### 浏览器中
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<script src="./node_modules/utils-lib-js/dist/umd/index.js"></script>
|
|
48
|
+
<script>
|
|
49
|
+
console.log(UtilsLib);
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### TS 接口注释
|
|
54
|
+
|
|
55
|
+
参照 https://gitee.com/DieHunter/utils-lib-js/blob/master/src/types.ts
|
|
56
|
+
|
|
57
|
+
### 代码演示
|
|
58
|
+
|
|
59
|
+
#### base 模块
|
|
43
60
|
|
|
44
|
-
|
|
45
|
-
_instance: Function
|
|
46
|
-
} & T
|
|
61
|
+
##### 1. `randomNum(min: number, max: number, bool?: boolean): number`
|
|
47
62
|
|
|
48
|
-
|
|
63
|
+
生成指定范围内的随机整数。
|
|
49
64
|
|
|
50
|
-
|
|
65
|
+
- `min`: 最小值(包含)。
|
|
66
|
+
- `max`: 最大值(包含)。
|
|
67
|
+
- `bool`: 是否包含最大值,默认为 `false`。
|
|
51
68
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @return {number} 随机数
|
|
57
|
-
**/
|
|
69
|
+
```javascript
|
|
70
|
+
const randomNumber = randomNum(1, 10);
|
|
71
|
+
console.log(randomNumber); // 生成一个介于 1 到 10 之间的随机整数
|
|
72
|
+
```
|
|
58
73
|
|
|
59
|
-
|
|
74
|
+
##### 2. `urlSplit(url: string): object`
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
* @param {string} url 待截取的地址
|
|
63
|
-
* @return {object} 参数对象
|
|
64
|
-
**/
|
|
76
|
+
将 URL 查询参数解析为对象。
|
|
65
77
|
|
|
66
|
-
|
|
78
|
+
- `url`: 包含查询参数的 URL。
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
```javascript
|
|
81
|
+
const url = "https://example.com/path?param1=value1¶m2=value2";
|
|
82
|
+
const params = urlSplit(url);
|
|
83
|
+
console.log(params);
|
|
84
|
+
// 输出: { param1: 'value1', param2: 'value2' }
|
|
85
|
+
```
|
|
73
86
|
|
|
74
|
-
|
|
87
|
+
##### 3. `urlJoin(url: string, query: object): string`
|
|
75
88
|
|
|
76
|
-
|
|
77
|
-
* @param {any} data 待检测数据
|
|
78
|
-
* @return {string} 数据类型
|
|
79
|
-
**/
|
|
89
|
+
将对象转换为 URL 查询参数,并与原始 URL 连接。
|
|
80
90
|
|
|
81
|
-
|
|
91
|
+
- `url`: 原始 URL。
|
|
92
|
+
- `query`: 包含查询参数的对象。
|
|
82
93
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
```javascript
|
|
95
|
+
const url = "https://example.com/path";
|
|
96
|
+
const query = { param1: "value1", param2: "value2" };
|
|
97
|
+
const newUrl = urlJoin(url, query);
|
|
98
|
+
console.log(newUrl);
|
|
99
|
+
// 输出: https://example.com/path?param1=value1¶m2=value2
|
|
100
|
+
```
|
|
88
101
|
|
|
89
|
-
|
|
102
|
+
##### 4. `getType(data: any): string`
|
|
90
103
|
|
|
104
|
+
获取数据的类型。
|
|
91
105
|
|
|
92
|
-
|
|
106
|
+
- `data`: 要检查的数据。
|
|
93
107
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
* @return {IObject[IKey]} 对象某个属性
|
|
99
|
-
**/
|
|
108
|
+
```javascript
|
|
109
|
+
const dataType = getType("Hello, World!");
|
|
110
|
+
console.log(dataType); // 输出: string
|
|
111
|
+
```
|
|
100
112
|
|
|
101
|
-
|
|
113
|
+
##### 5. `getTypeByList(data: any, whiteList: string[]): boolean`
|
|
102
114
|
|
|
103
|
-
|
|
104
|
-
* @param {IObject} object 目标对象
|
|
105
|
-
* @param {string} key 对象层级
|
|
106
|
-
* @param {any} value 需要赋的值
|
|
107
|
-
* @return {IObject} 目标对象
|
|
108
|
-
**/
|
|
115
|
+
检查数据类型是否在白名单内。
|
|
109
116
|
|
|
110
|
-
|
|
117
|
+
- `data`: 要检查的数据。
|
|
118
|
+
- `whiteList`: 允许的数据类型列表。
|
|
111
119
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
```javascript
|
|
121
|
+
const data = 42;
|
|
122
|
+
const allowedTypes = ["number", "string"];
|
|
123
|
+
const isTypeAllowed = getTypeByList(data, allowedTypes);
|
|
124
|
+
console.log(isTypeAllowed); // 输出: true
|
|
125
|
+
```
|
|
118
126
|
|
|
119
|
-
|
|
127
|
+
#### object 模块
|
|
120
128
|
|
|
121
|
-
|
|
122
|
-
* @param {IObject<string>} target 目标对象
|
|
123
|
-
* @return {IObject<string>} 目标对象
|
|
124
|
-
**/
|
|
129
|
+
##### 1. `getValue(object: object, key: string, defaultValue: any = ''): any`
|
|
125
130
|
|
|
126
|
-
|
|
131
|
+
获取对象中指定路径的值。
|
|
127
132
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
**/
|
|
133
|
+
- `object`: 目标对象。
|
|
134
|
+
- `key`: 要获取的值的路径。
|
|
135
|
+
- `defaultValue`: 默认值,当路径不存在时返回。
|
|
132
136
|
|
|
133
|
-
|
|
137
|
+
```javascript
|
|
138
|
+
const obj = { a: { b: { c: 42 } } };
|
|
139
|
+
const value = getValue(obj, "a.b.c", "default");
|
|
140
|
+
console.log(value); // 输出: 42
|
|
141
|
+
```
|
|
134
142
|
|
|
135
|
-
|
|
136
|
-
* @param {string} type 数据类型
|
|
137
|
-
* @param {any} __init 初始值
|
|
138
|
-
* @return {any} 目标对象
|
|
139
|
-
**/
|
|
143
|
+
##### 2. `setValue(object: object, key: string, value: any = {}): object`
|
|
140
144
|
|
|
141
|
-
|
|
145
|
+
设置对象中指定路径的值。
|
|
142
146
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
**/
|
|
147
|
+
- `object`: 目标对象。
|
|
148
|
+
- `key`: 要设置的值的路径。
|
|
149
|
+
- `value`: 要设置的值。
|
|
147
150
|
|
|
148
|
-
|
|
151
|
+
```javascript
|
|
152
|
+
const obj = { a: { b: { c: 42 } } };
|
|
153
|
+
setValue(obj, "a.b.d", "new value");
|
|
154
|
+
console.log(obj); // 输出: { a: { b: { c: 42, d: 'new value' } } }
|
|
155
|
+
```
|
|
149
156
|
|
|
150
|
-
|
|
151
|
-
* @param {Function} source 源对象
|
|
152
|
-
* @return {Function} 继承产物
|
|
153
|
-
**/
|
|
157
|
+
##### 3. `mixIn(target: object, source: object = {}, overwrite: boolean = false): object`
|
|
154
158
|
|
|
155
|
-
|
|
159
|
+
将源对象的属性混入目标对象中。
|
|
156
160
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
* @param {any[]} params 构造函数的参数
|
|
161
|
-
* @return {IObject} 实例化的单例
|
|
162
|
-
**/
|
|
161
|
+
- `target`: 目标对象。
|
|
162
|
+
- `source`: 源对象。
|
|
163
|
+
- `overwrite`: 是否覆盖已存在的属性,默认为 `false`。
|
|
163
164
|
|
|
164
|
-
|
|
165
|
+
```javascript
|
|
166
|
+
const target = { a: 1 };
|
|
167
|
+
const source = { b: 2 };
|
|
168
|
+
const result = mixIn(target, source);
|
|
169
|
+
console.log(result); // 输出: { a: 1, b: 2 }
|
|
170
|
+
```
|
|
165
171
|
|
|
166
|
-
|
|
167
|
-
* @param {IObject<any>} params 混入的属性
|
|
168
|
-
* @return {ClassDecorator} 装饰器钩子函数
|
|
169
|
-
**/
|
|
172
|
+
##### 4. `enumInversion(target: object): object`
|
|
170
173
|
|
|
171
|
-
|
|
174
|
+
反转枚举对象的键值对。
|
|
172
175
|
|
|
173
|
-
|
|
174
|
-
* @param {string} target 字符串
|
|
175
|
-
* @return {IObject<any>} 对象
|
|
176
|
-
**/
|
|
176
|
+
- `target`: 要反转的枚举对象。
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
```javascript
|
|
179
|
+
const enumObj = { key1: "value1", key2: "value2" };
|
|
180
|
+
const invertedEnum = enumInversion(enumObj);
|
|
181
|
+
console.log(invertedEnum); // 输出: { value1: 'key1', value2: 'key2' }
|
|
182
|
+
```
|
|
179
183
|
|
|
180
|
-
|
|
181
|
-
* @param {IObject<any>} target 对象
|
|
182
|
-
* @return {string} 字符串
|
|
183
|
-
**/
|
|
184
|
+
##### 5. `isNotObject(source: any, type: string): boolean`
|
|
184
185
|
|
|
185
|
-
|
|
186
|
+
检查值是否为非对象类型。
|
|
186
187
|
|
|
187
|
-
|
|
188
|
+
- `source`: 要检查的值。
|
|
189
|
+
- `type`: 数据类型。
|
|
188
190
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
**/
|
|
191
|
+
```javascript
|
|
192
|
+
const result = isNotObject(42, "number");
|
|
193
|
+
console.log(result); // 输出: false
|
|
194
|
+
```
|
|
194
195
|
|
|
195
|
-
|
|
196
|
+
##### 6. `cloneDeep(target: any): any`
|
|
196
197
|
|
|
197
|
-
|
|
198
|
-
* @param {Function} fn 防抖处理的函数
|
|
199
|
-
* @param {number} time 允许运行函数间隔/毫秒
|
|
200
|
-
* @return {Function} 处理后的函数
|
|
201
|
-
**/
|
|
198
|
+
深度克隆对象。
|
|
202
199
|
|
|
203
|
-
|
|
200
|
+
- `target`: 要克隆的对象。
|
|
204
201
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
export type IDefer = (timer: number) => IPromise
|
|
202
|
+
```javascript
|
|
203
|
+
const obj = { a: { b: { c: 42 } } };
|
|
204
|
+
const clonedObj = cloneDeep(obj);
|
|
205
|
+
console.log(clonedObj); // 输出: { a: { b: { c: 42 } } }
|
|
206
|
+
```
|
|
211
207
|
|
|
212
|
-
|
|
213
|
-
* @param {Promise<any>} defer 延迟函数
|
|
214
|
-
* @returns {Promise<any>} [error, result]
|
|
215
|
-
*/
|
|
208
|
+
##### 7. `createObjectVariable(type: string, source: object = {}): object`
|
|
216
209
|
|
|
217
|
-
|
|
210
|
+
根据类型创建特定类型的对象。
|
|
218
211
|
|
|
219
|
-
|
|
212
|
+
- `type`: 要创建的对象类型。
|
|
213
|
+
- `source`: 初始化对象的数据。
|
|
220
214
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
export type IArrayRandom<T extends any[]> = (arr: T) => T
|
|
215
|
+
```javascript
|
|
216
|
+
const array = createObjectVariable("array", [1, 2, 3]);
|
|
217
|
+
console.log(array); // 输出: [1, 2, 3]
|
|
218
|
+
```
|
|
227
219
|
|
|
228
|
-
|
|
229
|
-
* @param {Array<any>} arr 目标数组
|
|
230
|
-
* @returns {Array<any>} 去重后的数组
|
|
231
|
-
*/
|
|
220
|
+
##### 8. `createObject(source: object): object`
|
|
232
221
|
|
|
233
|
-
|
|
222
|
+
使用原型链创建对象。
|
|
234
223
|
|
|
235
|
-
|
|
236
|
-
* @param {Array<any>} arr 目标数组
|
|
237
|
-
* @returns {Array<any>} 扁平化的数组
|
|
238
|
-
*/
|
|
224
|
+
- `source`: 原型对象。
|
|
239
225
|
|
|
240
|
-
|
|
226
|
+
```javascript
|
|
227
|
+
const protoObj = { a: 1 };
|
|
228
|
+
const newObj = createObject(protoObj);
|
|
229
|
+
console.log(newObj.a); // 输出: 1
|
|
230
|
+
```
|
|
241
231
|
|
|
242
|
-
#####
|
|
232
|
+
##### 9. `inherit(source: object, target: function): function`
|
|
243
233
|
|
|
244
|
-
|
|
245
|
-
* @param {string} ele 标签类型
|
|
246
|
-
* @param {CSSStyleDeclaration} style 样式
|
|
247
|
-
* @param {Attr} attr 属性
|
|
248
|
-
* @param {object} parent 父元素
|
|
249
|
-
*/
|
|
234
|
+
继承原型链。
|
|
250
235
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
236
|
+
- `source`: 父对象的原型链。
|
|
237
|
+
- `target`: 子对象的构造函数。
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
function Parent() {}
|
|
241
|
+
Parent.prototype.method = function () {
|
|
242
|
+
console.log("Hello from parent");
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
function Child() {}
|
|
246
|
+
inherit(Parent, Child);
|
|
247
|
+
const childInstance = new Child();
|
|
248
|
+
childInstance.method(); // 输出: Hello from parent
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
##### 10. `getInstance(classProto: function, overwrite: boolean = false, ...params: any[]): object`
|
|
252
|
+
|
|
253
|
+
获取类的单例实例。
|
|
254
|
+
|
|
255
|
+
- `classProto`: 类的原型链。
|
|
256
|
+
- `overwrite`: 是否覆盖已存在的实例,默认为 `false`。
|
|
257
|
+
- `params`: 类构造函数的参数。
|
|
258
|
+
|
|
259
|
+
```javascript
|
|
260
|
+
class Singleton {
|
|
261
|
+
constructor(name) {
|
|
262
|
+
this.name = name;
|
|
263
|
+
}
|
|
256
264
|
}
|
|
257
265
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
* @return {ElementObject} 生成的标签
|
|
261
|
-
*/
|
|
266
|
+
const instance1 = getInstance(Singleton, false, "Instance 1");
|
|
267
|
+
const instance2 = getInstance(Singleton, true, "Instance 2");
|
|
262
268
|
|
|
263
|
-
|
|
269
|
+
console.log(instance1 === instance2); // 输出: false
|
|
270
|
+
```
|
|
264
271
|
|
|
265
|
-
#####
|
|
272
|
+
##### 11. `classDecorator(params: object): ClassDecorator`
|
|
266
273
|
|
|
267
|
-
|
|
268
|
-
* @param {Document} ele 标签
|
|
269
|
-
* @param {string} type 事件类型
|
|
270
|
-
* @param {(e: Event) => void} handler 事件回调
|
|
271
|
-
* @return {void}
|
|
272
|
-
*/
|
|
274
|
+
为类添加装饰器。
|
|
273
275
|
|
|
274
|
-
|
|
276
|
+
- `params`: 要添加的属性和方法。
|
|
275
277
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
278
|
+
```javascript
|
|
279
|
+
@classDecorator({
|
|
280
|
+
additionalMethod: function () {
|
|
281
|
+
console.log("Additional method");
|
|
282
|
+
},
|
|
283
|
+
})
|
|
284
|
+
class DecoratedClass {}
|
|
280
285
|
|
|
281
|
-
|
|
286
|
+
const instance = new DecoratedClass();
|
|
287
|
+
instance.additionalMethod(); // 输出: Additional method
|
|
288
|
+
```
|
|
282
289
|
|
|
283
|
-
|
|
284
|
-
* @param {Event} e 浏览器事件对象
|
|
285
|
-
* @return {void}
|
|
286
|
-
*/
|
|
290
|
+
##### 12. `stringToJson(target: string): object | null`
|
|
287
291
|
|
|
288
|
-
|
|
292
|
+
将 JSON 字符串转换为对象。
|
|
289
293
|
|
|
290
|
-
|
|
291
|
-
* @param {Document} ele 标签
|
|
292
|
-
* @param {string} type 事件类型
|
|
293
|
-
* @param {(e: Event) => void} handler 事件回调
|
|
294
|
-
* @return {void}
|
|
295
|
-
*/
|
|
294
|
+
- `target`: 要转换的 JSON 字符串。
|
|
296
295
|
|
|
297
|
-
|
|
296
|
+
```javascript
|
|
297
|
+
const jsonString = '{"key": "value"}';
|
|
298
|
+
const jsonObject = stringToJson(jsonString);
|
|
299
|
+
console.log(jsonObject); // 输出: { key: 'value' }
|
|
300
|
+
```
|
|
298
301
|
|
|
299
|
-
|
|
300
|
-
* @param {Event} e 浏览器事件对象
|
|
301
|
-
* @return {void}
|
|
302
|
-
*/
|
|
302
|
+
##### 13. `jsonToString(target: any): string`
|
|
303
303
|
|
|
304
|
-
|
|
304
|
+
将对象转换为 JSON 字符串。
|
|
305
305
|
|
|
306
|
+
- `target`: 要转换的对象。
|
|
306
307
|
|
|
307
|
-
|
|
308
|
+
```javascript
|
|
309
|
+
const obj = { key: "value" };
|
|
310
|
+
const jsonString = jsonToString(obj);
|
|
311
|
+
console.log(jsonString); // 输出: '{"key":"value"}'
|
|
312
|
+
```
|
|
308
313
|
|
|
309
|
-
|
|
310
|
-
* @param {string} str 输出字符
|
|
311
|
-
* @param {boolean} overwrite 覆盖前面的输出
|
|
312
|
-
* @param {boolean} warp 最后一行换行
|
|
313
|
-
* @return {void}
|
|
314
|
-
*/
|
|
315
|
-
export type ILogOneLine = (str: string, overwrite?: boolean, warp?: boolean) => void
|
|
314
|
+
##### 14. `isWindow(win: any): boolean`
|
|
316
315
|
|
|
317
|
-
|
|
318
|
-
* @param {string[]} loopList 输出的字符队列
|
|
319
|
-
* @param {number} index 第几个字符
|
|
320
|
-
* @param {boolean} isStop 控制暂停循环
|
|
321
|
-
* @param {number} timer 两个相隔时间间隔
|
|
322
|
-
*/
|
|
323
|
-
export type ILogLoopParams = {
|
|
324
|
-
loopList?: string[]
|
|
325
|
-
index?: number
|
|
326
|
-
isStop?: boolean
|
|
327
|
-
timer?: number
|
|
328
|
-
}
|
|
329
|
-
export type ILogLoop = (opts?: ILogLoopParams) => ILogLoopParams | void
|
|
316
|
+
检查是否是浏览器窗口。
|
|
330
317
|
|
|
331
|
-
|
|
332
|
-
###### https://gitee.com/DieHunter/js-request-lib
|
|
333
|
-
export type IRequestParams<T> = T | IObject<any> | null
|
|
318
|
+
- `win`: 要检查的对象。
|
|
334
319
|
|
|
335
|
-
|
|
320
|
+
```javascript
|
|
321
|
+
const isBrowserWindow = isWindow(window);
|
|
322
|
+
console.log(isBrowserWindow); // 输出: true
|
|
323
|
+
```
|
|
336
324
|
|
|
337
|
-
|
|
325
|
+
#### array 模块
|
|
338
326
|
|
|
339
|
-
|
|
327
|
+
##### 1. `arrayRandom(arr: any[]): any[]`
|
|
340
328
|
|
|
341
|
-
|
|
329
|
+
对数组进行随机排序。
|
|
342
330
|
|
|
343
|
-
|
|
331
|
+
- `arr`: 要排序的数组。
|
|
344
332
|
|
|
345
|
-
|
|
333
|
+
```javascript
|
|
334
|
+
const originalArray = [1, 2, 3, 4, 5];
|
|
335
|
+
const randomizedArray = arrayRandom(originalArray);
|
|
336
|
+
console.log(randomizedArray);
|
|
337
|
+
// 输出: 一个随机排序的数组
|
|
338
|
+
```
|
|
346
339
|
|
|
347
|
-
|
|
340
|
+
##### 2. `arrayUniq(arr: any[]): any[]`
|
|
348
341
|
|
|
349
|
-
|
|
342
|
+
从数组中移除重复的元素。
|
|
350
343
|
|
|
351
|
-
|
|
344
|
+
- `arr`: 要处理的数组。
|
|
352
345
|
|
|
353
|
-
|
|
346
|
+
```javascript
|
|
347
|
+
const arrayWithDuplicates = [1, 2, 2, 3, 4, 4, 5];
|
|
348
|
+
const uniqueArray = arrayUniq(arrayWithDuplicates);
|
|
349
|
+
console.log(uniqueArray);
|
|
350
|
+
// 输出: 移除重复元素后的数组
|
|
351
|
+
```
|
|
354
352
|
|
|
355
|
-
|
|
353
|
+
##### 3. `arrayDemote(arr: IDemoteArray<any>, result: any[] = []): any[]`
|
|
356
354
|
|
|
357
|
-
|
|
355
|
+
将多层嵌套的数组降维。
|
|
358
356
|
|
|
359
|
-
|
|
357
|
+
- `arr`: 要降维的数组。
|
|
358
|
+
- `result`: 用于存储结果的数组,默认为空数组。
|
|
360
359
|
|
|
361
|
-
|
|
360
|
+
```javascript
|
|
361
|
+
const nestedArray = [1, [2, [3, [4]], 5]];
|
|
362
|
+
const demotedArray = arrayDemote(nestedArray);
|
|
363
|
+
console.log(demotedArray);
|
|
364
|
+
// 输出: 降维后的数组 [1, 2, 3, 4, 5]
|
|
365
|
+
```
|
|
362
366
|
|
|
363
|
-
|
|
367
|
+
#### function 模块
|
|
364
368
|
|
|
365
|
-
|
|
369
|
+
##### 1. `throttle(fn: Function, time: number): Function`
|
|
366
370
|
|
|
367
|
-
|
|
371
|
+
限制函数在指定时间内的调用频率。
|
|
368
372
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
query?: IRequestParams<IObject<any>>
|
|
372
|
-
body?: IRequestBody
|
|
373
|
-
headers?: IRequestHeaders
|
|
374
|
-
controller?: AbortController
|
|
375
|
-
timeout?: number
|
|
376
|
-
timer?: number | unknown | null
|
|
377
|
-
[key: string]: any
|
|
378
|
-
}
|
|
373
|
+
- `fn`: 要执行的函数。
|
|
374
|
+
- `time`: 时间间隔(毫秒)。
|
|
379
375
|
|
|
380
|
-
|
|
376
|
+
```javascript
|
|
377
|
+
const throttledFunction = throttle(
|
|
378
|
+
() => console.log("Throttled function called!"),
|
|
379
|
+
1000
|
|
380
|
+
);
|
|
381
|
+
throttledFunction(); // 只有在 1 秒后才会执行
|
|
382
|
+
```
|
|
381
383
|
|
|
382
|
-
|
|
383
|
-
use(type: "request" | "response" | "error", fn: Function): void
|
|
384
|
-
get reqFn(): Function
|
|
385
|
-
get resFn(): Function
|
|
386
|
-
get errFn(): Function
|
|
387
|
-
}
|
|
384
|
+
##### 2. `debounce(fn: Function, time: number): Function`
|
|
388
385
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
export type IRequestBase = {
|
|
392
|
-
readonly origin: string
|
|
393
|
-
chackUrl: (url: IUrl) => boolean
|
|
394
|
-
envDesc: () => IEnv
|
|
395
|
-
errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R
|
|
396
|
-
clearTimer: (opts: IRequestOptions) => void
|
|
397
|
-
initAbort: <T = IRequestOptions>(opts: T) => T
|
|
398
|
-
requestType: () => IRequestBaseFn
|
|
399
|
-
fixOrigin: (fixStr: string) => string
|
|
400
|
-
fetch: IRequestBaseFn
|
|
401
|
-
http: IRequestBaseFn
|
|
402
|
-
getDataByType: (type: IDataType, response: Response) => Promise<any>
|
|
403
|
-
}
|
|
386
|
+
限制函数在指定时间内的连续调用。
|
|
404
387
|
|
|
405
|
-
|
|
388
|
+
- `fn`: 要执行的函数。
|
|
389
|
+
- `time`: 时间间隔(毫秒)。
|
|
406
390
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
391
|
+
```javascript
|
|
392
|
+
const debouncedFunction = debounce(
|
|
393
|
+
() => console.log("Debounced function called!"),
|
|
394
|
+
1000
|
|
395
|
+
);
|
|
396
|
+
debouncedFunction(); // 在 1 秒内多次调用,只有最后一次会执行
|
|
397
|
+
```
|
|
412
398
|
|
|
413
|
-
|
|
399
|
+
##### 3. `defer(timer: number = 0): { promise: Promise<void>, resolve: Function, reject: Function }`
|
|
414
400
|
|
|
415
|
-
|
|
416
|
-
GET: IRequestFn
|
|
417
|
-
POST: IRequestFn
|
|
418
|
-
DELETE: IRequestFn
|
|
419
|
-
PUT: IRequestFn
|
|
420
|
-
OPTIONS: IRequestFn
|
|
421
|
-
HEAD: IRequestFn
|
|
422
|
-
PATCH: IRequestFn
|
|
423
|
-
} & IRequestBase
|
|
401
|
+
创建一个扁平化的 Promise 延迟对象,可以设置在一定时间后超时。
|
|
424
402
|
|
|
403
|
+
- `timer`: 超时时间(毫秒),默认为 0。
|
|
425
404
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
clear: () => this
|
|
440
|
-
has: (type: string) => boolean
|
|
441
|
-
handlerLength: (type: string) => number
|
|
442
|
-
watch: (type: string, handler: Function) => this
|
|
443
|
-
invoke: (type: string, data?: any) => Promise<void>
|
|
444
|
-
}
|
|
405
|
+
```javascript
|
|
406
|
+
const deferFn = () => {
|
|
407
|
+
const { resolve, promise } = defer();
|
|
408
|
+
setTimeout(() => resolve("success"), 500);
|
|
409
|
+
return promise;
|
|
410
|
+
};
|
|
411
|
+
const delayFn = () => {
|
|
412
|
+
const { promise } = defer(1000);
|
|
413
|
+
return promise;
|
|
414
|
+
};
|
|
415
|
+
deferFn().then(console.log); // 延迟输出
|
|
416
|
+
delayFn().catch(console.error); // 超时输出
|
|
417
|
+
```
|
|
445
418
|
|
|
419
|
+
##### 4. `catchAwait(defer: Promise<any>): Promise<[Error | null, any]>`
|
|
446
420
|
|
|
421
|
+
捕获异步操作的错误并返回 `[Error, null]` 或 `[null, result]`。
|
|
447
422
|
|
|
448
|
-
|
|
449
|
-
##### 任务队列
|
|
450
|
-
###### https://gitee.com/DieHunter/task-queue
|
|
451
|
-
/**
|
|
452
|
-
* 单条队列
|
|
453
|
-
* defer: 待运行的异步函数
|
|
454
|
-
* params?: defer的参数,也可以用bind直接传递
|
|
455
|
-
*
|
|
456
|
-
*/
|
|
457
|
-
export interface IQueue {
|
|
458
|
-
defer: Function
|
|
459
|
-
name?: string
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* 队列参数
|
|
463
|
-
* children: 队列列表
|
|
464
|
-
* name: 队列唯一标识
|
|
465
|
-
* result: 运行完成后的结果
|
|
466
|
-
*
|
|
467
|
-
*/
|
|
468
|
-
export interface IQueues {
|
|
469
|
-
children: Array<Function>
|
|
470
|
-
name: string
|
|
471
|
-
result?: any[]
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* 队列缓存
|
|
475
|
-
*/
|
|
476
|
-
export type IQueueTemp = {
|
|
477
|
-
[key: string]: IQueues
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* 系统队列
|
|
481
|
-
*/
|
|
482
|
-
export type IQueueList = Array<IQueue>
|
|
483
|
-
/**
|
|
484
|
-
* 队列状态 idle:空闲 pending:等待 fulfilled:完成 rejected:失败
|
|
485
|
-
*/
|
|
486
|
-
export type IState = "idle" | "pending" | "fulfilled" | "rejected"
|
|
487
|
-
/**
|
|
488
|
-
* 任务队列参数
|
|
489
|
-
*/
|
|
490
|
-
export type ITaskQueueProps = {
|
|
491
|
-
maxLen: number
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* 任务队列
|
|
495
|
-
*/
|
|
496
|
-
export type ITaskQueue = {
|
|
497
|
-
readonly fix: string
|
|
498
|
-
props: ITaskQueueProps
|
|
499
|
-
queueTemp: IQueueTemp
|
|
500
|
-
queues: IQueueList
|
|
501
|
-
state: IState
|
|
502
|
-
push: (queue: IQueues) => Promise<void>
|
|
503
|
-
unshift: (length: number) => IQueueList
|
|
504
|
-
run: (reject: any) => unknown
|
|
505
|
-
clear: () => void
|
|
506
|
-
}
|
|
423
|
+
- `defer`: 异步操作的 Promise 对象。
|
|
507
424
|
|
|
425
|
+
```javascript
|
|
426
|
+
const asyncOperation = new Promise((resolve, reject) => {
|
|
427
|
+
// 模拟异步操作
|
|
428
|
+
setTimeout(() => {
|
|
429
|
+
reject(new Error("Something went wrong!"));
|
|
430
|
+
}, 1000);
|
|
431
|
+
});
|
|
508
432
|
|
|
433
|
+
const [error, result] = await catchAwait(asyncOperation);
|
|
434
|
+
console.log(error); // 输出: Error: Something went wrong!
|
|
435
|
+
console.log(result); // 输出: null
|
|
436
|
+
```
|
|
509
437
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
438
|
+
#### element 模块
|
|
439
|
+
|
|
440
|
+
##### 1. `createElement(options: { ele?: string | HTMLElement, style?: object, attr?: object, parent?: HTMLElement }): HTMLElement`
|
|
441
|
+
|
|
442
|
+
创建并返回一个 HTML 元素。
|
|
443
|
+
|
|
444
|
+
- `ele`: 元素类型或已存在的 HTMLElement 对象,可选,默认为 'div'。
|
|
445
|
+
- `style`: 元素的样式对象,可选。
|
|
446
|
+
- `attr`: 元素的属性对象,可选。
|
|
447
|
+
- `parent`: 元素的父级元素,可选。
|
|
448
|
+
|
|
449
|
+
```javascript
|
|
450
|
+
const options = {
|
|
451
|
+
ele: 'div',
|
|
452
|
+
style: { color: 'blue', fontSize: '16px' },
|
|
453
|
+
attr: { id: 'myElement', className: 'custom-class' },
|
|
454
|
+
parent: document.body
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
const createdElement = createElement(options);
|
|
458
|
+
// 在 body 中创建一个带有样式和属性的 div 元素
|
|
459
|
+
```
|
|
460
|
+
#### event 模块
|
|
461
|
+
|
|
462
|
+
##### 1. `addHandler(ele: HTMLElement, type: string, handler: EventListener): void`
|
|
463
|
+
|
|
464
|
+
为元素添加事件监听器。
|
|
465
|
+
|
|
466
|
+
- `ele`: 目标元素。
|
|
467
|
+
- `type`: 事件类型。
|
|
468
|
+
- `handler`: 事件处理函数。
|
|
469
|
+
|
|
470
|
+
```javascript
|
|
471
|
+
const button = document.getElementById('myButton');
|
|
472
|
+
const handleClick = () => console.log('Button clicked!');
|
|
473
|
+
addHandler(button, 'click', handleClick);
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
##### 2. `stopBubble(event: Event): void`
|
|
477
|
+
|
|
478
|
+
阻止事件冒泡。
|
|
479
|
+
|
|
480
|
+
- `event`: 事件对象。
|
|
481
|
+
|
|
482
|
+
```javascript
|
|
483
|
+
const handleClick = (event) => {
|
|
484
|
+
console.log('Button clicked!');
|
|
485
|
+
stopBubble(event);
|
|
486
|
+
};
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
##### 3. `stopDefault(event: Event): void`
|
|
490
|
+
|
|
491
|
+
阻止事件的默认行为。
|
|
492
|
+
|
|
493
|
+
- `event`: 事件对象。
|
|
494
|
+
|
|
495
|
+
```javascript
|
|
496
|
+
const handleFormSubmit = (event) => {
|
|
497
|
+
console.log('Form submitted!');
|
|
498
|
+
stopDefault(event);
|
|
499
|
+
};
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
##### 4. `removeHandler(ele: HTMLElement, type: string, handler: EventListener): void`
|
|
503
|
+
|
|
504
|
+
移除元素的事件监听器。
|
|
505
|
+
|
|
506
|
+
- `ele`: 目标元素。
|
|
507
|
+
- `type`: 事件类型。
|
|
508
|
+
- `handler`: 要移除的事件处理函数。
|
|
509
|
+
|
|
510
|
+
```javascript
|
|
511
|
+
const button = document.getElementById('myButton');
|
|
512
|
+
const handleClick = () => console.log('Button clicked!');
|
|
513
|
+
addHandler(button, 'click', handleClick);
|
|
514
|
+
// 其他操作...
|
|
515
|
+
removeHandler(button, 'click', handleClick);
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
##### 5. `dispatchEvent(ele: HTMLElement, data: any): void`
|
|
519
|
+
|
|
520
|
+
触发自定义事件。
|
|
521
|
+
|
|
522
|
+
- `ele`: 目标元素。
|
|
523
|
+
- `data`: 自定义事件的数据。
|
|
524
|
+
|
|
525
|
+
```javascript
|
|
526
|
+
const customEvent = new CustomEvent('customEvent', { detail: { key: 'value' } });
|
|
527
|
+
const targetElement = document.getElementById('myElement');
|
|
528
|
+
dispatchEvent(targetElement, customEvent);
|
|
529
|
+
```
|
|
530
|
+
#### storage 模块
|
|
531
|
+
|
|
532
|
+
##### 1. `setStorage(key: string, val: any): void`
|
|
533
|
+
|
|
534
|
+
将值存储到本地存储中。
|
|
535
|
+
|
|
536
|
+
- `key`: 存储的键名。
|
|
537
|
+
- `val`: 要存储的值。
|
|
538
|
+
|
|
539
|
+
```javascript
|
|
540
|
+
const userData = { username: 'john_doe', email: 'john@example.com' };
|
|
541
|
+
setStorage('user_data', userData);
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
##### 2. `getStorage(key: string): any`
|
|
545
|
+
|
|
546
|
+
从本地存储中获取值。
|
|
547
|
+
|
|
548
|
+
- `key`: 要获取的键名。
|
|
549
|
+
|
|
550
|
+
```javascript
|
|
551
|
+
const storedUserData = getStorage('user_data');
|
|
552
|
+
console.log(storedUserData);
|
|
553
|
+
// 输出: { username: 'john_doe', email: 'john@example.com' }
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
##### 3. `clearStorage(key?: string): void`
|
|
557
|
+
|
|
558
|
+
清除本地存储中的值。
|
|
559
|
+
|
|
560
|
+
- `key`: 可选,要清除的键名。如果未提供键名,则清除所有存储。
|
|
561
|
+
|
|
562
|
+
```javascript
|
|
563
|
+
clearStorage('user_data'); // 清除特定键名的存储值
|
|
564
|
+
// 或者
|
|
565
|
+
clearStorage(); // 清除所有本地存储的值
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
#### log 模块
|
|
569
|
+
|
|
570
|
+
##### 1. `logOneLine(str: string, overwrite: boolean = false, wrap: boolean = true): void`
|
|
571
|
+
|
|
572
|
+
在一行中输出日志。
|
|
573
|
+
|
|
574
|
+
- `str`: 要输出的字符串。
|
|
575
|
+
- `overwrite`: 是否覆盖当前行,默认为 `false`。
|
|
576
|
+
- `wrap`: 是否在输出后换行,默认为 `true`。
|
|
577
|
+
|
|
578
|
+
```javascript
|
|
579
|
+
logOneLine('This is a single line log message.');
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
##### 2. `logLoop(opts?: { loopList?: string[], isStop?: boolean, timer?: number, index?: number }): { loopList?: string[], isStop?: boolean, timer?: number, index?: number }`
|
|
583
|
+
|
|
584
|
+
在控制台中输出循环动画。
|
|
585
|
+
|
|
586
|
+
- `opts`: 可选参数对象,包含以下属性:
|
|
587
|
+
- `loopList`: 动画字符列表,默认为 `['\\', '|', '/', '—', '—']`。
|
|
588
|
+
- `isStop`: 是否停止循环,默认为 `false`。
|
|
589
|
+
- `timer`: 动画切换的时间间隔(毫秒),默认为 `100`。
|
|
590
|
+
- `index`: 当前动画字符的索引,默认为 `0`。
|
|
591
|
+
|
|
592
|
+
```javascript
|
|
593
|
+
logLoop(); // 启动默认循环动画
|
|
594
|
+
// 或者
|
|
595
|
+
logLoop({ loopList: ['-', '+', '-', '+'], timer: 200 }); // 启动自定义循环动画
|
|
596
|
+
```
|
|
597
|
+
#### animation 模块
|
|
598
|
+
|
|
599
|
+
##### 1. `class AnimateFrame`
|
|
600
|
+
|
|
601
|
+
提供帧动画的类。
|
|
602
|
+
|
|
603
|
+
- `start(duration?: number): void`: 启动帧动画,可选参数 `duration` 为帧数控制。
|
|
604
|
+
- `stop(): void`: 停止帧动画。
|
|
605
|
+
|
|
606
|
+
```javascript
|
|
607
|
+
const animateFrame = new AnimateFrame((timestamp) => {
|
|
608
|
+
// 在此处更新动画状态
|
|
609
|
+
console.log('AnimationFrame callback:', timestamp);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
animateFrame.start(60); // 启动帧动画,每秒 60 帧
|
|
613
|
+
// 其他操作...
|
|
614
|
+
animateFrame.stop(); // 停止帧动画
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
##### 2. `quadraticBezier(_x: number, _y: number, t: number): [number, number]`
|
|
618
|
+
|
|
619
|
+
计算二次贝塞尔曲线上的点坐标。
|
|
620
|
+
|
|
621
|
+
- `_x`: 控制点1 x 坐标。
|
|
622
|
+
- `_y`: 控制点1 y 坐标。
|
|
623
|
+
- `t`: 时间参数,取值范围 [0, 1]。
|
|
624
|
+
|
|
625
|
+
```javascript
|
|
626
|
+
const result = quadraticBezier(0, 0, 1, 1, 0.5);
|
|
627
|
+
console.log(result);
|
|
628
|
+
// 输出: [0.75, 0.75]
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
##### 3. `cubicBezier(_x1: number, _y1: number, _x2: number, _y2: number, t: number): [number, number]`
|
|
632
|
+
|
|
633
|
+
计算三次贝塞尔曲线上的点坐标。
|
|
634
|
+
|
|
635
|
+
- `_x1`: 控制点1 x 坐标。
|
|
636
|
+
- `_y1`: 控制点1 y 坐标。
|
|
637
|
+
- `_x2`: 控制点2 x 坐标。
|
|
638
|
+
- `_y2`: 控制点2 y 坐标。
|
|
639
|
+
- `t`: 时间参数,取值范围 [0, 1]。
|
|
640
|
+
|
|
641
|
+
```javascript
|
|
642
|
+
const result = cubicBezier(0, 0, 0.5, 1, 0.5);
|
|
643
|
+
console.log(result);
|
|
644
|
+
// 输出: [0.375, 0.625]
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
##### 4. `factorial(n: number): number`
|
|
648
|
+
|
|
649
|
+
计算阶乘。
|
|
650
|
+
|
|
651
|
+
- `n`: 非负整数。
|
|
652
|
+
|
|
653
|
+
```javascript
|
|
654
|
+
const result = factorial(5);
|
|
655
|
+
console.log(result);
|
|
656
|
+
// 输出: 120
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
##### 5. `combination(n: number, k: number): number`
|
|
660
|
+
|
|
661
|
+
计算组合数。
|
|
662
|
+
|
|
663
|
+
- `n`: 总数。
|
|
664
|
+
- `k`: 选择的个数。
|
|
665
|
+
|
|
666
|
+
```javascript
|
|
667
|
+
const result = combination(5, 2);
|
|
668
|
+
console.log(result);
|
|
669
|
+
// 输出: 10
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
##### 6. `NBezier(points: number[][], t: number): [number, number]`
|
|
673
|
+
|
|
674
|
+
计算 N 次贝塞尔曲线上的点坐标。
|
|
675
|
+
|
|
676
|
+
- `points`: 控制点数组,每个点是一个二阶数组。
|
|
677
|
+
- `t`: 时间参数,取值范围 [0, 1]。
|
|
678
|
+
|
|
679
|
+
```javascript
|
|
680
|
+
const points = [[0, 0], [1, 1], [2, 0]];
|
|
681
|
+
const result = NBezier(points, 0.5);
|
|
682
|
+
console.log(result);
|
|
683
|
+
// 输出: [1.5, 0.75]
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
#### event-message-center
|
|
687
|
+
https://gitee.com/DieHunter/message-center
|
|
688
|
+
#### task-queue-lib
|
|
689
|
+
https://gitee.com/DieHunter/task-queue
|
|
690
|
+
#### js-request-lib
|
|
691
|
+
https://gitee.com/DieHunter/js-request-lib
|