utils-lib-js 1.6.1 → 1.6.3
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 +158 -8
- package/README.md +82 -0
- package/dist/bundle/array.d.ts +10 -0
- package/dist/bundle/base.d.ts +14 -0
- package/dist/bundle/element.d.ts +6 -0
- package/dist/bundle/event.d.ts +14 -0
- package/dist/bundle/function.d.ts +12 -0
- package/dist/bundle/index.d.ts +51 -0
- package/dist/bundle/index.js +1023 -0
- package/dist/bundle/object.d.ts +30 -0
- package/dist/bundle/request.d.ts +60 -0
- package/dist/bundle/static.d.ts +16 -0
- package/dist/bundle/storage.d.ts +9 -0
- package/dist/bundle/types.d.ts +103 -0
- package/dist/cjs/array.d.ts +10 -10
- package/dist/cjs/array.js +19 -19
- package/dist/cjs/base.d.ts +14 -14
- package/dist/cjs/base.js +56 -56
- package/dist/cjs/element.d.ts +6 -6
- package/dist/cjs/element.js +16 -16
- package/dist/cjs/event.d.ts +14 -14
- package/dist/cjs/event.js +53 -53
- package/dist/cjs/function.d.ts +12 -12
- package/dist/cjs/function.js +66 -66
- package/dist/cjs/index.d.ts +51 -50
- package/dist/cjs/index.js +54 -52
- package/dist/cjs/object.d.ts +30 -30
- package/dist/cjs/object.js +190 -190
- package/dist/cjs/request.d.ts +60 -60
- package/dist/cjs/request.js +239 -239
- package/dist/cjs/static.d.ts +16 -16
- package/dist/cjs/static.js +18 -18
- package/dist/cjs/storage.d.ts +9 -9
- package/dist/cjs/storage.js +41 -41
- package/dist/cjs/types.d.ts +103 -103
- package/dist/cjs/types.js +2 -2
- package/dist/esm/array.d.ts +10 -10
- package/dist/esm/array.js +13 -13
- package/dist/esm/base.d.ts +14 -14
- package/dist/esm/base.js +48 -48
- package/dist/esm/element.d.ts +6 -6
- package/dist/esm/element.js +12 -12
- package/dist/esm/event.d.ts +14 -14
- package/dist/esm/event.js +45 -45
- package/dist/esm/function.d.ts +12 -12
- package/dist/esm/function.js +59 -59
- package/dist/esm/index.d.ts +51 -50
- package/dist/esm/index.js +35 -33
- package/dist/esm/object.d.ts +30 -30
- package/dist/esm/object.js +174 -174
- package/dist/esm/request.d.ts +60 -60
- package/dist/esm/request.js +236 -236
- package/dist/esm/static.d.ts +16 -16
- package/dist/esm/static.js +15 -15
- package/dist/esm/storage.d.ts +9 -9
- package/dist/esm/storage.js +35 -35
- package/dist/esm/types.d.ts +103 -103
- package/dist/esm/types.js +1 -1
- package/dist/umd/array.d.ts +10 -0
- package/dist/umd/base.d.ts +14 -0
- package/dist/umd/element.d.ts +6 -0
- package/dist/umd/event.d.ts +14 -0
- package/dist/umd/function.d.ts +12 -0
- package/dist/umd/index.d.ts +51 -0
- package/dist/umd/index.js +1024 -0
- package/dist/umd/object.d.ts +30 -0
- package/dist/umd/request.d.ts +60 -0
- package/dist/umd/static.d.ts +16 -0
- package/dist/umd/storage.d.ts +9 -0
- package/dist/umd/types.d.ts +103 -0
- package/package.json +12 -4
- package/pnpm-lock.yaml +279 -8
- package/rollup.config.js +35 -0
- package/tsconfig.umd.json +6 -0
package/README.en.md
CHANGED
|
@@ -28,33 +28,41 @@ JavaScript工具函数,封装的一些常用的js函数
|
|
|
28
28
|
接口:
|
|
29
29
|
|
|
30
30
|
export type IKey = string | symbol | number
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
##### 对象类型
|
|
33
|
+
|
|
32
34
|
export interface IObject<T> {
|
|
33
35
|
[key: IKey]: T | IObject<any>
|
|
34
36
|
}
|
|
37
|
+
|
|
35
38
|
export interface IPromise extends IObject<any> {
|
|
36
39
|
promise: Promise<void>
|
|
37
40
|
resolve: (res: any) => unknown
|
|
38
41
|
reject: (err: any) => unknown
|
|
39
42
|
}
|
|
43
|
+
|
|
40
44
|
export type IInstance<T> = {
|
|
41
45
|
_instance: Function
|
|
42
46
|
} & T
|
|
47
|
+
|
|
43
48
|
export type IDemoteArray<T> = Array<IDemoteArray<T> | T>
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
##### base
|
|
51
|
+
|
|
46
52
|
/**产生区间随机数
|
|
47
53
|
* @param {number} min 最小区间
|
|
48
54
|
* @param {number} max 最大区间
|
|
49
55
|
* @param {boolean} bool 包含最大值
|
|
50
56
|
* @return {number} 随机数
|
|
51
57
|
**/
|
|
58
|
+
|
|
52
59
|
export type IRandomNum = (min: number, max: number, bool?: boolean) => number
|
|
53
60
|
|
|
54
61
|
/**获取url的参数
|
|
55
62
|
* @param {string} url 待截取的地址
|
|
56
63
|
* @return {object} 参数对象
|
|
57
64
|
**/
|
|
65
|
+
|
|
58
66
|
export type IUrlSplit = (url: string) => IObject<any>
|
|
59
67
|
|
|
60
68
|
/**添加url的参数
|
|
@@ -62,12 +70,14 @@ export type IUrlSplit = (url: string) => IObject<any>
|
|
|
62
70
|
* @param {object} query 待添加的参数
|
|
63
71
|
* @return {string} 添加参数后的url
|
|
64
72
|
**/
|
|
73
|
+
|
|
65
74
|
export type IUrlJoin = (url: string, query: object) => string
|
|
66
75
|
|
|
67
76
|
/**获取数据类型
|
|
68
77
|
* @param {any} data 待检测数据
|
|
69
78
|
* @return {string} 数据类型
|
|
70
79
|
**/
|
|
80
|
+
|
|
71
81
|
export type IGetType<T> = (data: any) => typeof data | T[keyof T] | "null";
|
|
72
82
|
|
|
73
83
|
/**批量判断数据类型
|
|
@@ -75,16 +85,19 @@ export type IGetType<T> = (data: any) => typeof data | T[keyof T] | "null";
|
|
|
75
85
|
* @param {any} whiteList 数据类型名单
|
|
76
86
|
* @return {boolean} 是否在白名单中
|
|
77
87
|
**/
|
|
88
|
+
|
|
78
89
|
export type IGetTypeByList = (data: any, whiteList: string[]) => boolean;
|
|
79
90
|
|
|
80
91
|
|
|
81
|
-
|
|
92
|
+
##### object
|
|
93
|
+
|
|
82
94
|
/**lodash中的 _.get(),获取对象某级属性
|
|
83
95
|
* @param {IObject} object 目标对象
|
|
84
96
|
* @param {string} key 对象层级
|
|
85
97
|
* @param {any} defaultValue 未取得时默认值
|
|
86
98
|
* @return {IObject[IKey]} 对象某个属性
|
|
87
99
|
**/
|
|
100
|
+
|
|
88
101
|
export type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: string, defaultValue?: any) => U
|
|
89
102
|
|
|
90
103
|
/**lodash中的 _.set(),赋值对象某级属性
|
|
@@ -93,6 +106,7 @@ export type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: s
|
|
|
93
106
|
* @param {any} value 需要赋的值
|
|
94
107
|
* @return {IObject} 目标对象
|
|
95
108
|
**/
|
|
109
|
+
|
|
96
110
|
export type ISetValue = <T>(object: IObject<T>, key: string, value?: any) => IObject<T>
|
|
97
111
|
|
|
98
112
|
/**对象混入
|
|
@@ -101,18 +115,21 @@ export type ISetValue = <T>(object: IObject<T>, key: string, value?: any) => IOb
|
|
|
101
115
|
* @param {boolean} overwrite 是否重写覆盖原有属性
|
|
102
116
|
* @return {IObject} 目标对象
|
|
103
117
|
**/
|
|
118
|
+
|
|
104
119
|
export type IMixIn = <U extends IObject<any>>(target?: U, source?: IObject<any>, overwrite?: boolean) => U
|
|
105
120
|
|
|
106
121
|
/**枚举值反向映射
|
|
107
122
|
* @param {IObject<string>} target 目标对象
|
|
108
123
|
* @return {IObject<string>} 目标对象
|
|
109
124
|
**/
|
|
125
|
+
|
|
110
126
|
export type IEnumInversion = (target: IObject<string>) => IObject<string>
|
|
111
127
|
|
|
112
128
|
/**对象复制
|
|
113
129
|
* @param {IObject<any>} target 目标对象
|
|
114
130
|
* @return {IObject} 目标对象
|
|
115
131
|
**/
|
|
132
|
+
|
|
116
133
|
export type ICloneDeep = (target?: any) => any
|
|
117
134
|
|
|
118
135
|
/**生成 对象 类型的初始值
|
|
@@ -120,18 +137,21 @@ export type ICloneDeep = (target?: any) => any
|
|
|
120
137
|
* @param {any} __init 初始值
|
|
121
138
|
* @return {any} 目标对象
|
|
122
139
|
**/
|
|
140
|
+
|
|
123
141
|
export type ICreateObjectVariable = (type: string, source?: any) => any
|
|
124
142
|
|
|
125
143
|
/**Object.create 根据源对象产出新对象
|
|
126
144
|
* @param {Function|Object} source 源对象
|
|
127
145
|
* @return {Function|Object} 对象产物
|
|
128
146
|
**/
|
|
147
|
+
|
|
129
148
|
export type ICreateObject = <T, U extends T>(source: T) => U
|
|
130
149
|
|
|
131
150
|
/**类的继承
|
|
132
151
|
* @param {Function} source 源对象
|
|
133
152
|
* @return {Function} 继承产物
|
|
134
153
|
**/
|
|
154
|
+
|
|
135
155
|
export type IInherit = <T extends Function>(source: T, target?: Function) => Function
|
|
136
156
|
|
|
137
157
|
/**生成类的实例单例
|
|
@@ -140,32 +160,38 @@ export type IInherit = <T extends Function>(source: T, target?: Function) => Fun
|
|
|
140
160
|
* @param {any[]} params 构造函数的参数
|
|
141
161
|
* @return {IObject} 实例化的单例
|
|
142
162
|
**/
|
|
163
|
+
|
|
143
164
|
export type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite?: boolean, ...params: any[]) => Function
|
|
144
165
|
|
|
145
166
|
/**通过装饰器将属性混入类中
|
|
146
167
|
* @param {IObject<any>} params 混入的属性
|
|
147
168
|
* @return {ClassDecorator} 装饰器钩子函数
|
|
148
169
|
**/
|
|
170
|
+
|
|
149
171
|
export type IClassDecorator = (params: IObject<any>) => <TFunction extends Function>(target: TFunction) => void
|
|
150
172
|
|
|
151
173
|
/**JSON.parse封装
|
|
152
174
|
* @param {string} target 字符串
|
|
153
175
|
* @return {IObject<any>} 对象
|
|
154
176
|
**/
|
|
177
|
+
|
|
155
178
|
export type IStringToJson = (target: string) => IObject<any>
|
|
156
179
|
|
|
157
180
|
/**JSON.stringify封装
|
|
158
181
|
* @param {IObject<any>} target 对象
|
|
159
182
|
* @return {string} 字符串
|
|
160
183
|
**/
|
|
184
|
+
|
|
161
185
|
export type IJsonToString = (target: IObject<any>) => string
|
|
162
186
|
|
|
163
|
-
|
|
187
|
+
##### function
|
|
188
|
+
|
|
164
189
|
/**节流(throttle):高频事件触发,但在 n 秒内只会执行一次
|
|
165
190
|
* @param {Function} fn 节流处理的函数
|
|
166
191
|
* @param {number} time 执行间隔/毫秒
|
|
167
192
|
* @return {Function} 处理后的函数
|
|
168
193
|
**/
|
|
194
|
+
|
|
169
195
|
export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void
|
|
170
196
|
|
|
171
197
|
/**防抖(debounce):触发高频事件后 n 秒内函数只会执行一次
|
|
@@ -173,31 +199,37 @@ export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void
|
|
|
173
199
|
* @param {number} time 允许运行函数间隔/毫秒
|
|
174
200
|
* @return {Function} 处理后的函数
|
|
175
201
|
**/
|
|
202
|
+
|
|
176
203
|
export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void
|
|
177
204
|
|
|
178
205
|
/**
|
|
179
206
|
* Promise扁平化,避免Promise嵌套
|
|
180
207
|
* @returns {Promise,resolve,reject}
|
|
181
208
|
*/
|
|
209
|
+
|
|
182
210
|
export type IDefer = () => IPromise
|
|
183
211
|
|
|
184
212
|
/**await与try catch 捕获异常处理方法
|
|
185
213
|
* @param {Promise<any>} defer 延迟函数
|
|
186
214
|
* @returns {Promise<any>} [error, result]
|
|
187
215
|
*/
|
|
216
|
+
|
|
188
217
|
export type ICatchAwait<T extends Promise<any>> = (defer: T) => T
|
|
189
218
|
|
|
190
|
-
|
|
219
|
+
##### array
|
|
220
|
+
|
|
191
221
|
/**数组乱序
|
|
192
222
|
* @param {Array<any>} arr 目标数组
|
|
193
223
|
* @returns {Array<any>} 乱序后的数组
|
|
194
224
|
*/
|
|
225
|
+
|
|
195
226
|
export type IArrayRandom<T extends any[]> = (arr: T) => T
|
|
196
227
|
|
|
197
228
|
/**数组数组去重
|
|
198
229
|
* @param {Array<any>} arr 目标数组
|
|
199
230
|
* @returns {Array<any>} 去重后的数组
|
|
200
231
|
*/
|
|
232
|
+
|
|
201
233
|
export type IArrayUniq<T extends any[]> = (arr: T) => T
|
|
202
234
|
|
|
203
235
|
/**数组扁平化
|
|
@@ -207,44 +239,52 @@ export type IArrayUniq<T extends any[]> = (arr: T) => T
|
|
|
207
239
|
|
|
208
240
|
export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T
|
|
209
241
|
|
|
210
|
-
|
|
242
|
+
##### element
|
|
243
|
+
|
|
211
244
|
/**IElementParams
|
|
212
245
|
* @param {string} ele 标签类型
|
|
213
246
|
* @param {CSSStyleDeclaration} style 样式
|
|
214
247
|
* @param {Attr} attr 属性
|
|
215
248
|
* @param {object} parent 父元素
|
|
216
249
|
*/
|
|
250
|
+
|
|
217
251
|
interface IElementParams<T> {
|
|
218
252
|
ele: T | string
|
|
219
253
|
style: CSSStyleDeclaration
|
|
220
254
|
attr: Attr
|
|
221
255
|
parent: T
|
|
222
256
|
}
|
|
257
|
+
|
|
223
258
|
/**新增标签,设置属性及样式
|
|
224
259
|
* @param {IElementParams} params 配置
|
|
225
260
|
* @return {ElementObject} 生成的标签
|
|
226
261
|
*/
|
|
262
|
+
|
|
227
263
|
export type ICreateElement<T = HTMLElement> = (params: IElementParams<T>) => T
|
|
228
264
|
|
|
229
|
-
|
|
265
|
+
##### event
|
|
266
|
+
|
|
230
267
|
/**浏览器事件
|
|
231
268
|
* @param {Document} ele 标签
|
|
232
269
|
* @param {string} type 事件类型
|
|
233
270
|
* @param {(e: Event) => void} handler 事件回调
|
|
234
271
|
* @return {void}
|
|
235
272
|
*/
|
|
273
|
+
|
|
236
274
|
export type IAddHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void
|
|
237
275
|
|
|
238
276
|
/**取消事件冒泡
|
|
239
277
|
* @param {Event} e 浏览器事件对象
|
|
240
278
|
* @return {void}
|
|
241
279
|
*/
|
|
280
|
+
|
|
242
281
|
export type IStopBubble = (e: Event) => void
|
|
243
282
|
|
|
244
283
|
/**取消默认事件
|
|
245
284
|
* @param {Event} e 浏览器事件对象
|
|
246
285
|
* @return {void}
|
|
247
286
|
*/
|
|
287
|
+
|
|
248
288
|
export type IStopDefault = (e: Event) => void
|
|
249
289
|
|
|
250
290
|
/**取消浏览器事件
|
|
@@ -253,34 +293,54 @@ export type IStopDefault = (e: Event) => void
|
|
|
253
293
|
* @param {(e: Event) => void} handler 事件回调
|
|
254
294
|
* @return {void}
|
|
255
295
|
*/
|
|
296
|
+
|
|
256
297
|
export type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void
|
|
257
298
|
|
|
258
299
|
/**取消默认事件
|
|
259
300
|
* @param {Event} e 浏览器事件对象
|
|
260
301
|
* @return {void}
|
|
261
302
|
*/
|
|
303
|
+
|
|
262
304
|
export type IDispatchEvent = <T extends Document>(ele: T, data: any) => void
|
|
263
305
|
|
|
264
|
-
|
|
306
|
+
##### request
|
|
265
307
|
|
|
266
308
|
export type IRequestParams<T> = T | IObject<any> | null
|
|
309
|
+
|
|
267
310
|
// 请求路径
|
|
311
|
+
|
|
268
312
|
export type IUrl = string
|
|
313
|
+
|
|
269
314
|
// 环境判断
|
|
315
|
+
|
|
270
316
|
export type IEnv = 'Window' | 'Node'
|
|
317
|
+
|
|
271
318
|
// fetch返回取值方式
|
|
319
|
+
|
|
272
320
|
export type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer"
|
|
321
|
+
|
|
273
322
|
// 请求方式
|
|
323
|
+
|
|
274
324
|
export type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION"
|
|
325
|
+
|
|
275
326
|
// body结构
|
|
327
|
+
|
|
276
328
|
export type IRequestBody = IRequestParams<BodyInit>
|
|
329
|
+
|
|
277
330
|
// heads结构
|
|
331
|
+
|
|
278
332
|
export type IRequestHeaders = IRequestParams<HeadersInit>
|
|
333
|
+
|
|
279
334
|
// 请求基础函数
|
|
335
|
+
|
|
280
336
|
export type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>
|
|
337
|
+
|
|
281
338
|
// 请求函数体
|
|
339
|
+
|
|
282
340
|
export type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>
|
|
341
|
+
|
|
283
342
|
// 请求参数
|
|
343
|
+
|
|
284
344
|
export type IRequestOptions = {
|
|
285
345
|
method?: IRequestMethods
|
|
286
346
|
query?: IRequestParams<IObject<any>>
|
|
@@ -291,14 +351,18 @@ export type IRequestOptions = {
|
|
|
291
351
|
timer?: number | unknown | null
|
|
292
352
|
[key: string]: any
|
|
293
353
|
}
|
|
354
|
+
|
|
294
355
|
// 拦截器
|
|
356
|
+
|
|
295
357
|
export type IInterceptors = {
|
|
296
358
|
use(type: "request" | "response" | "error", fn: Function): void
|
|
297
359
|
get reqFn(): Function
|
|
298
360
|
get resFn(): Function
|
|
299
361
|
get errFn(): Function
|
|
300
362
|
}
|
|
363
|
+
|
|
301
364
|
// 公共函数
|
|
365
|
+
|
|
302
366
|
export type IRequestBase = {
|
|
303
367
|
readonly origin: string
|
|
304
368
|
chackUrl: (url: IUrl) => boolean
|
|
@@ -312,13 +376,17 @@ export type IRequestBase = {
|
|
|
312
376
|
http: IRequestBaseFn
|
|
313
377
|
getDataByType: (type: IDataType, response: Response) => Promise<any>
|
|
314
378
|
}
|
|
379
|
+
|
|
315
380
|
// 初始化参数
|
|
381
|
+
|
|
316
382
|
export type IRequestInit = {
|
|
317
383
|
initDefaultParams: (url: IUrl, opts: IRequestOptions) => any
|
|
318
384
|
initFetchParams: (url: IUrl, opts: IRequestOptions) => any
|
|
319
385
|
initHttpParams: (url: IUrl, opts: IRequestOptions) => any
|
|
320
386
|
}
|
|
387
|
+
|
|
321
388
|
// 请求主体类
|
|
389
|
+
|
|
322
390
|
export type IRequest = {
|
|
323
391
|
GET: IRequestFn
|
|
324
392
|
POST: IRequestFn
|
|
@@ -328,3 +396,85 @@ export type IRequest = {
|
|
|
328
396
|
HEAD: IRequestFn
|
|
329
397
|
PATCH: IRequestFn
|
|
330
398
|
} & IRequestBase
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
<!-- 消息中心 -->
|
|
402
|
+
// 消息中心
|
|
403
|
+
export declare interface Handlers {
|
|
404
|
+
[key: string]: Array<Function>
|
|
405
|
+
}
|
|
406
|
+
export declare interface IMessageCenter {
|
|
407
|
+
events: Handlers
|
|
408
|
+
_instance?: IMessageCenter
|
|
409
|
+
on: (type: string, handler: Function) => this
|
|
410
|
+
emit: (type: string, data?: any) => this
|
|
411
|
+
un: (type: string, handler?: Function) => this
|
|
412
|
+
once: (type: string, handler: Function) => this
|
|
413
|
+
clear: () => this
|
|
414
|
+
has: (type: string) => boolean
|
|
415
|
+
handlerLength: (type: string) => number
|
|
416
|
+
watch: (type: string, handler: Function) => this
|
|
417
|
+
invoke: (type: string, data?: any) => Promise<void>
|
|
418
|
+
}
|
|
419
|
+
https://gitee.com/DieHunter/message-center
|
|
420
|
+
|
|
421
|
+
<!-- 任务队列 -->
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 单条队列
|
|
425
|
+
* defer: 待运行的异步函数
|
|
426
|
+
* params?: defer的参数,也可以用bind直接传递
|
|
427
|
+
*
|
|
428
|
+
*/
|
|
429
|
+
export interface IQueue {
|
|
430
|
+
defer: Function
|
|
431
|
+
name?: string
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* 队列参数
|
|
435
|
+
* children: 队列列表
|
|
436
|
+
* name: 队列唯一标识
|
|
437
|
+
* result: 运行完成后的结果
|
|
438
|
+
*
|
|
439
|
+
*/
|
|
440
|
+
export interface IQueues {
|
|
441
|
+
children: Array<Function>
|
|
442
|
+
name: string
|
|
443
|
+
result?: any[]
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* 队列缓存
|
|
447
|
+
*/
|
|
448
|
+
export type IQueueTemp = {
|
|
449
|
+
[key: string]: IQueues
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* 系统队列
|
|
453
|
+
*/
|
|
454
|
+
export type IQueueList = Array<IQueue>
|
|
455
|
+
/**
|
|
456
|
+
* 队列状态 idle:空闲 pending:等待 fulfilled:完成 rejected:失败
|
|
457
|
+
*/
|
|
458
|
+
export type IState = "idle" | "pending" | "fulfilled" | "rejected"
|
|
459
|
+
/**
|
|
460
|
+
* 任务队列参数
|
|
461
|
+
*/
|
|
462
|
+
export type ITaskQueueProps = {
|
|
463
|
+
maxLen: number
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* 任务队列
|
|
467
|
+
*/
|
|
468
|
+
export type ITaskQueue = {
|
|
469
|
+
readonly fix: string
|
|
470
|
+
props: ITaskQueueProps
|
|
471
|
+
queueTemp: IQueueTemp
|
|
472
|
+
queues: IQueueList
|
|
473
|
+
state: IState
|
|
474
|
+
push: (queue: IQueues) => Promise<void>
|
|
475
|
+
unshift: (length: number) => IQueueList
|
|
476
|
+
run: (reject: any) => unknown
|
|
477
|
+
clear: () => void
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
https://gitee.com/DieHunter/task-queue
|
package/README.md
CHANGED
|
@@ -396,3 +396,85 @@ export type IRequest = {
|
|
|
396
396
|
HEAD: IRequestFn
|
|
397
397
|
PATCH: IRequestFn
|
|
398
398
|
} & IRequestBase
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
<!-- 消息中心 -->
|
|
402
|
+
// 消息中心
|
|
403
|
+
export declare interface Handlers {
|
|
404
|
+
[key: string]: Array<Function>
|
|
405
|
+
}
|
|
406
|
+
export declare interface IMessageCenter {
|
|
407
|
+
events: Handlers
|
|
408
|
+
_instance?: IMessageCenter
|
|
409
|
+
on: (type: string, handler: Function) => this
|
|
410
|
+
emit: (type: string, data?: any) => this
|
|
411
|
+
un: (type: string, handler?: Function) => this
|
|
412
|
+
once: (type: string, handler: Function) => this
|
|
413
|
+
clear: () => this
|
|
414
|
+
has: (type: string) => boolean
|
|
415
|
+
handlerLength: (type: string) => number
|
|
416
|
+
watch: (type: string, handler: Function) => this
|
|
417
|
+
invoke: (type: string, data?: any) => Promise<void>
|
|
418
|
+
}
|
|
419
|
+
https://gitee.com/DieHunter/message-center
|
|
420
|
+
|
|
421
|
+
<!-- 任务队列 -->
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 单条队列
|
|
425
|
+
* defer: 待运行的异步函数
|
|
426
|
+
* params?: defer的参数,也可以用bind直接传递
|
|
427
|
+
*
|
|
428
|
+
*/
|
|
429
|
+
export interface IQueue {
|
|
430
|
+
defer: Function
|
|
431
|
+
name?: string
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* 队列参数
|
|
435
|
+
* children: 队列列表
|
|
436
|
+
* name: 队列唯一标识
|
|
437
|
+
* result: 运行完成后的结果
|
|
438
|
+
*
|
|
439
|
+
*/
|
|
440
|
+
export interface IQueues {
|
|
441
|
+
children: Array<Function>
|
|
442
|
+
name: string
|
|
443
|
+
result?: any[]
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* 队列缓存
|
|
447
|
+
*/
|
|
448
|
+
export type IQueueTemp = {
|
|
449
|
+
[key: string]: IQueues
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* 系统队列
|
|
453
|
+
*/
|
|
454
|
+
export type IQueueList = Array<IQueue>
|
|
455
|
+
/**
|
|
456
|
+
* 队列状态 idle:空闲 pending:等待 fulfilled:完成 rejected:失败
|
|
457
|
+
*/
|
|
458
|
+
export type IState = "idle" | "pending" | "fulfilled" | "rejected"
|
|
459
|
+
/**
|
|
460
|
+
* 任务队列参数
|
|
461
|
+
*/
|
|
462
|
+
export type ITaskQueueProps = {
|
|
463
|
+
maxLen: number
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* 任务队列
|
|
467
|
+
*/
|
|
468
|
+
export type ITaskQueue = {
|
|
469
|
+
readonly fix: string
|
|
470
|
+
props: ITaskQueueProps
|
|
471
|
+
queueTemp: IQueueTemp
|
|
472
|
+
queues: IQueueList
|
|
473
|
+
state: IState
|
|
474
|
+
push: (queue: IQueues) => Promise<void>
|
|
475
|
+
unshift: (length: number) => IQueueList
|
|
476
|
+
run: (reject: any) => unknown
|
|
477
|
+
clear: () => void
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
https://gitee.com/DieHunter/task-queue
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./index.js";
|
|
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;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IRandomNum, IUrlSplit, IUrlJoin, IGetType, IGetTypeByList, types } from "./index.js";
|
|
2
|
+
export declare const randomNum: IRandomNum;
|
|
3
|
+
export declare const urlSplit: IUrlSplit;
|
|
4
|
+
export declare const urlJoin: IUrlJoin;
|
|
5
|
+
export declare const getType: IGetType<types>;
|
|
6
|
+
export declare const getTypeByList: IGetTypeByList;
|
|
7
|
+
declare const _default: {
|
|
8
|
+
randomNum: IRandomNum;
|
|
9
|
+
urlSplit: IUrlSplit;
|
|
10
|
+
urlJoin: IUrlJoin;
|
|
11
|
+
getType: IGetType<types>;
|
|
12
|
+
getTypeByList: IGetTypeByList;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IAddHandler, IStopBubble, IStopDefault, IRemoveHandler, IDispatchEvent } from "./index.js";
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ICatchAwait, IThrottle, IDebounce, IDefer } from "./index.js";
|
|
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
|
+
declare const _default: {
|
|
7
|
+
throttle: IThrottle;
|
|
8
|
+
debounce: IDebounce;
|
|
9
|
+
defer: IDefer;
|
|
10
|
+
catchAwait: ICatchAwait<Promise<any>>;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export * from "./object.js";
|
|
2
|
+
export * from "./base.js";
|
|
3
|
+
export * from "./array.js";
|
|
4
|
+
export * from "./function.js";
|
|
5
|
+
export * from "./element.js";
|
|
6
|
+
export * from "./static.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./request.js";
|
|
9
|
+
export * from "./event.js";
|
|
10
|
+
export * from "./storage.js";
|
|
11
|
+
export * from "event-message-center";
|
|
12
|
+
export * from "task-queue-lib";
|
|
13
|
+
declare const _default: {
|
|
14
|
+
setStorage: (key: string, val: any) => void;
|
|
15
|
+
getStorage: (key: string) => any;
|
|
16
|
+
clearStorage: (key: string) => void;
|
|
17
|
+
addHandler: import("./types.js").IAddHandler;
|
|
18
|
+
stopBubble: import("./types.js").IStopBubble;
|
|
19
|
+
stopDefault: import("./types.js").IStopDefault;
|
|
20
|
+
removeHandler: import("./types.js").IRemoveHandler;
|
|
21
|
+
dispatchEvent: import("./types.js").IDispatchEvent;
|
|
22
|
+
Request: typeof import("./request.js").Request;
|
|
23
|
+
types: typeof import("./static.js").types;
|
|
24
|
+
createElement: import("./types.js").ICreateElement;
|
|
25
|
+
throttle: import("./types.js").IThrottle;
|
|
26
|
+
debounce: import("./types.js").IDebounce;
|
|
27
|
+
defer: import("./types.js").IDefer;
|
|
28
|
+
catchAwait: import("./types.js").ICatchAwait<Promise<any>>;
|
|
29
|
+
arrayRandom: import("./types.js").IArrayRandom<any[]>;
|
|
30
|
+
arrayUniq: import("./types.js").IArrayUniq<any[]>;
|
|
31
|
+
arrayDemote: import("./types.js").IArrayDemote<import("./types.js").IDemoteArray<any>>;
|
|
32
|
+
randomNum: import("./types.js").IRandomNum;
|
|
33
|
+
urlSplit: import("./types.js").IUrlSplit;
|
|
34
|
+
urlJoin: import("./types.js").IUrlJoin;
|
|
35
|
+
getType: import("./types.js").IGetType<import("./static.js").types>;
|
|
36
|
+
getTypeByList: import("./types.js").IGetTypeByList;
|
|
37
|
+
getValue: import("./types.js").IGetValue;
|
|
38
|
+
setValue: import("./types.js").ISetValue;
|
|
39
|
+
mixIn: import("./types.js").IMixIn;
|
|
40
|
+
enumInversion: import("./types.js").IEnumInversion;
|
|
41
|
+
isNotObject: (source: any, type: any) => boolean;
|
|
42
|
+
cloneDeep: import("./types.js").ICloneDeep;
|
|
43
|
+
createObjectVariable: import("./types.js").ICreateObjectVariable;
|
|
44
|
+
createObject: import("./types.js").ICreateObject;
|
|
45
|
+
inherit: import("./types.js").IInherit;
|
|
46
|
+
getInstance: import("./types.js").IGetInstance;
|
|
47
|
+
classDecorator: import("./types.js").IClassDecorator;
|
|
48
|
+
stringToJson: import("./types.js").IStringToJson;
|
|
49
|
+
jsonToString: import("./types.js").IJsonToString;
|
|
50
|
+
};
|
|
51
|
+
export default _default;
|