utils-lib-js 1.7.17 → 1.7.19
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 +337 -319
- package/README.md +23 -1
- package/dist/bundle/animate.d.ts +25 -0
- package/dist/bundle/array.d.ts +1 -1
- package/dist/bundle/base.d.ts +2 -1
- package/dist/bundle/element.d.ts +1 -1
- package/dist/bundle/event.d.ts +1 -1
- package/dist/bundle/function.d.ts +1 -1
- package/dist/bundle/index.d.ts +7 -0
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/log.d.ts +1 -1
- package/dist/bundle/object.d.ts +1 -1
- package/dist/bundle/request.d.ts +1 -1
- package/dist/bundle/types.d.ts +9 -0
- package/dist/cjs/animate.d.ts +25 -0
- package/dist/cjs/array.d.ts +1 -1
- package/dist/cjs/base.d.ts +2 -1
- package/dist/cjs/element.d.ts +1 -1
- package/dist/cjs/event.d.ts +1 -1
- package/dist/cjs/function.d.ts +1 -1
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +144 -64
- package/dist/cjs/log.d.ts +1 -1
- package/dist/cjs/object.d.ts +1 -1
- package/dist/cjs/request.d.ts +1 -1
- package/dist/cjs/types.d.ts +9 -0
- package/dist/esm/animate.d.ts +25 -0
- package/dist/esm/array.d.ts +1 -1
- package/dist/esm/base.d.ts +2 -1
- package/dist/esm/element.d.ts +1 -1
- package/dist/esm/event.d.ts +1 -1
- package/dist/esm/function.d.ts +1 -1
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +139 -65
- package/dist/esm/log.d.ts +1 -1
- package/dist/esm/object.d.ts +1 -1
- package/dist/esm/request.d.ts +1 -1
- package/dist/esm/types.d.ts +9 -0
- package/dist/umd/animate.d.ts +25 -0
- package/dist/umd/array.d.ts +1 -1
- package/dist/umd/base.d.ts +2 -1
- package/dist/umd/element.d.ts +1 -1
- package/dist/umd/event.d.ts +1 -1
- package/dist/umd/function.d.ts +1 -1
- package/dist/umd/index.d.ts +7 -0
- package/dist/umd/index.js +144 -64
- package/dist/umd/log.d.ts +1 -1
- package/dist/umd/object.d.ts +1 -1
- package/dist/umd/request.d.ts +1 -1
- package/dist/umd/types.d.ts +9 -0
- package/package.json +49 -49
- package/pnpm-lock.yaml +0 -423
package/README.en.md
CHANGED
|
@@ -1,516 +1,534 @@
|
|
|
1
1
|
# utils-lib-js
|
|
2
2
|
|
|
3
|
-
####
|
|
4
|
-
JavaScript
|
|
3
|
+
#### Introduction
|
|
4
|
+
JavaScript utility functions, packaging some commonly used js functions
|
|
5
5
|
|
|
6
|
-
####
|
|
7
|
-
|
|
6
|
+
#### Software Architecture
|
|
7
|
+
Software architecture specification
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
####
|
|
10
|
+
#### installation tutorial
|
|
11
11
|
|
|
12
12
|
1. pnpm i
|
|
13
13
|
2. pnpm build
|
|
14
14
|
|
|
15
|
-
####
|
|
15
|
+
#### Usage instructions
|
|
16
16
|
|
|
17
|
-
1.
|
|
18
|
-
2.
|
|
17
|
+
1. pnpm build
|
|
18
|
+
2. pnpm debug (debug source)
|
|
19
19
|
|
|
20
|
-
####
|
|
20
|
+
#### Contribute
|
|
21
21
|
|
|
22
|
-
1.
|
|
23
|
-
2.
|
|
24
|
-
3.
|
|
25
|
-
4.
|
|
22
|
+
1. Fork the local warehouse
|
|
23
|
+
2. Create a branch of Feat_xxx
|
|
24
|
+
3. Submit the code
|
|
25
|
+
4. Create a Pull Request
|
|
26
26
|
|
|
27
|
-
####
|
|
28
|
-
|
|
27
|
+
#### function
|
|
28
|
+
Interface:
|
|
29
29
|
|
|
30
30
|
export type IKey = string | symbol | number
|
|
31
31
|
|
|
32
|
-
#####
|
|
32
|
+
##### Object type
|
|
33
33
|
|
|
34
34
|
export interface IObject<T> {
|
|
35
|
-
|
|
35
|
+
[key: IKey]: T | IObject<any>
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface IPromise extends IObject<any> {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
promise: Promise<void>
|
|
40
|
+
resolve: (res: any) => unknown
|
|
41
|
+
reject: (err: any) => unknown
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export type IInstance<T> = {
|
|
45
|
-
|
|
45
|
+
_instance: Function
|
|
46
46
|
} & T
|
|
47
47
|
|
|
48
48
|
export type IDemoteArray<T> = Array<IDemoteArray<T> | T>
|
|
49
49
|
|
|
50
50
|
##### base
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
* @param {number} min
|
|
54
|
-
* @param {number} max
|
|
55
|
-
* @param {boolean} bool
|
|
56
|
-
* @return {number}
|
|
57
|
-
|
|
52
|
+
/** Generates interval random numbers
|
|
53
|
+
* @param {number} min Minimum interval
|
|
54
|
+
* @param {number} max Maximum range
|
|
55
|
+
* @param {boolean} bool Contains the maximum value
|
|
56
|
+
* @return {number} A random number
|
|
57
|
+
* * /
|
|
58
58
|
|
|
59
|
-
export type IRandomNum = (min: number, max: number, bool
|
|
59
|
+
export type IRandomNum = (min: number, max: number, bool? : boolean) => number
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
* @param {string} url
|
|
63
|
-
* @return {object}
|
|
64
|
-
|
|
61
|
+
/** Gets the parameters of the url
|
|
62
|
+
* @param {string} url Indicates the address to be intercepted
|
|
63
|
+
* @return {object} Parameter object
|
|
64
|
+
* * /
|
|
65
65
|
|
|
66
66
|
export type IUrlSplit = (url: string) => IObject<any>
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
* @param {string} url
|
|
70
|
-
* @param {object} query
|
|
71
|
-
* @return {string}
|
|
72
|
-
|
|
68
|
+
/** Adds parameters for the url
|
|
69
|
+
* @param {string} url Address to which the parameter is to be added
|
|
70
|
+
* @param {object} query Specifies the parameter to be added
|
|
71
|
+
* @return {string} The url after the parameter is added
|
|
72
|
+
* * /
|
|
73
73
|
|
|
74
74
|
export type IUrlJoin = (url: string, query: object) => string
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
* @param {any} data
|
|
78
|
-
* @return {string}
|
|
79
|
-
|
|
76
|
+
/** Gets the data type
|
|
77
|
+
* @param {any} data Indicates the data to be detected
|
|
78
|
+
* @return {string} Data type
|
|
79
|
+
* * /
|
|
80
80
|
|
|
81
81
|
export type IGetType<T> = (data: any) => typeof data | T[keyof T] | "null";
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
* @param {any} data
|
|
85
|
-
* @param {any} whiteList
|
|
86
|
-
* @return {boolean}
|
|
87
|
-
|
|
83
|
+
/** Determine the data type in batches
|
|
84
|
+
* @param {any} data Indicates the data to be detected
|
|
85
|
+
* @param {any} whiteList Indicates a list of data types
|
|
86
|
+
* @return {boolean} Whether it is in the whitelist
|
|
87
|
+
* * /
|
|
88
88
|
|
|
89
89
|
export type IGetTypeByList = (data: any, whiteList: string[]) => boolean;
|
|
90
90
|
|
|
91
91
|
|
|
92
92
|
##### object
|
|
93
93
|
|
|
94
|
-
/**lodash
|
|
95
|
-
* @param {IObject} object
|
|
96
|
-
* @param {string} key
|
|
97
|
-
* @param {any} defaultValue
|
|
98
|
-
* @return {IObject[IKey]}
|
|
99
|
-
|
|
94
|
+
/**lodash _.get() to get a certain level attribute of the object
|
|
95
|
+
* @param {IObject} object Indicates the target object
|
|
96
|
+
* @param {string} key object hierarchy
|
|
97
|
+
* @param {any} defaultValue Default value if not obtained
|
|
98
|
+
* @return {IObject[IKey]} A property of an object
|
|
99
|
+
* * /
|
|
100
100
|
|
|
101
|
-
export type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: string, defaultValue
|
|
101
|
+
export type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: string, defaultValue? : any) => U
|
|
102
102
|
|
|
103
|
-
/**lodash
|
|
104
|
-
* @param {IObject} object
|
|
105
|
-
* @param {string} key
|
|
106
|
-
* @param {any} value
|
|
107
|
-
* @return {IObject}
|
|
108
|
-
|
|
103
|
+
/**lodash _.set(), which assigns a level attribute to the object
|
|
104
|
+
* @param {IObject} object Indicates the target object
|
|
105
|
+
* @param {string} key object hierarchy
|
|
106
|
+
* @param {any} value Specifies the value to be assigned
|
|
107
|
+
* @return {IObject} Target object
|
|
108
|
+
* * /
|
|
109
109
|
|
|
110
|
-
export type ISetValue = <T>(object: IObject<T>, key: string, value
|
|
110
|
+
export type ISetValue = <T>(object: IObject<T>, key: string, value? : any) => IObject<T>
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
* @param {IObject} target
|
|
114
|
-
* @param {string} source
|
|
115
|
-
* @param {boolean} overwrite
|
|
116
|
-
* @return {IObject}
|
|
117
|
-
|
|
112
|
+
/** Object mixed in
|
|
113
|
+
* @param {IObject} target Indicates the target object
|
|
114
|
+
* @param {string} source Set of objects to be mixed in
|
|
115
|
+
* @param {boolean} overwrite Whether to overwrite the original attribute
|
|
116
|
+
* @return {IObject} Target object
|
|
117
|
+
* * /
|
|
118
118
|
|
|
119
|
-
export type IMixIn = <U extends IObject<any>>(target
|
|
119
|
+
export type IMixIn = <U extends IObject<any>>(target? : U, source? : IObject<any>, overwrite? : boolean) => U
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
* @param {IObject<string>} target
|
|
123
|
-
* @return {IObject<string>}
|
|
124
|
-
|
|
121
|
+
/** Enumeration value reverse mapping
|
|
122
|
+
* @param {IObject<string>} target Indicates the target object
|
|
123
|
+
* @return {IObject<string>} Target object
|
|
124
|
+
* * /
|
|
125
125
|
|
|
126
126
|
export type IEnumInversion = (target: IObject<string>) => IObject<string>
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
* @param {IObject<any>} target
|
|
130
|
-
* @return {IObject}
|
|
131
|
-
|
|
128
|
+
/** Object replication
|
|
129
|
+
* @param {IObject<any>} target Indicates the target object
|
|
130
|
+
* @return {IObject} Target object
|
|
131
|
+
* * /
|
|
132
132
|
|
|
133
|
-
export type ICloneDeep = (target
|
|
133
|
+
export type ICloneDeep = (target? : any) => any
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
* @param {string} type
|
|
137
|
-
* @param {any} __init
|
|
138
|
-
* @return {any}
|
|
139
|
-
|
|
135
|
+
/** Generates the initial value of the object type
|
|
136
|
+
* @param {string} type Indicates the data type
|
|
137
|
+
* @param {any} __init Initial value
|
|
138
|
+
* @return {any} Target object
|
|
139
|
+
* * /
|
|
140
140
|
|
|
141
|
-
export type ICreateObjectVariable = (type: string, source
|
|
141
|
+
export type ICreateObjectVariable = (type: string, source? : any) => any
|
|
142
142
|
|
|
143
|
-
/**
|
|
144
|
-
* @param {Function|Object} source
|
|
145
|
-
* @return {Function|Object}
|
|
146
|
-
|
|
143
|
+
/** object. create generates a new Object based on the source object
|
|
144
|
+
* @param {Function|Object} source Source object
|
|
145
|
+
* @return {Function|Object} Object product
|
|
146
|
+
* * /
|
|
147
147
|
|
|
148
148
|
export type ICreateObject = <T, U extends T>(source: T) => U
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
* @param {Function} source
|
|
152
|
-
* @return {Function}
|
|
153
|
-
|
|
150
|
+
Inheritance of the /** class
|
|
151
|
+
* @param {Function} source Source object
|
|
152
|
+
* @return {Function} inheritance product
|
|
153
|
+
* * /
|
|
154
154
|
|
|
155
|
-
export type IInherit = <T extends Function>(source: T, target
|
|
155
|
+
export type IInherit = <T extends Function>(source: T, target? : Function) => Function
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
* @param {Function} classProto
|
|
159
|
-
* @param {Boolean} overwrite
|
|
160
|
-
* @param {any[]} params
|
|
161
|
-
* @return {IObject}
|
|
162
|
-
|
|
157
|
+
/** Generates an instance singleton of the class
|
|
158
|
+
* @param {Function} classProto class
|
|
159
|
+
* @param {Boolean} overwrite Whether to overwrite an existing singleton
|
|
160
|
+
* @param {any[]} Parameter of the params constructor
|
|
161
|
+
* @return {IObject} instantiated singleton
|
|
162
|
+
* * /
|
|
163
163
|
|
|
164
|
-
export type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite
|
|
164
|
+
export type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite? : boolean, ... params: any[]) => Function
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
* @param {IObject<any>} params
|
|
168
|
-
* @return {ClassDecorator}
|
|
169
|
-
|
|
166
|
+
/** Mixes attributes into classes via decorators
|
|
167
|
+
* @param {IObject<any>} params mixed property
|
|
168
|
+
* @return {ClassDecorator} Decorator hook function
|
|
169
|
+
* * /
|
|
170
170
|
|
|
171
171
|
export type IClassDecorator = (params: IObject<any>) => <TFunction extends Function>(target: TFunction) => void
|
|
172
172
|
|
|
173
|
-
/**JSON.parse
|
|
174
|
-
* @param {string} target
|
|
175
|
-
* @return {IObject<any>}
|
|
176
|
-
|
|
173
|
+
/**JSON.parse package
|
|
174
|
+
* @param {string} target string
|
|
175
|
+
* @return {IObject<any>} object
|
|
176
|
+
* * /
|
|
177
177
|
|
|
178
178
|
export type IStringToJson = (target: string) => IObject<any>
|
|
179
179
|
|
|
180
|
-
/**JSON.stringify
|
|
181
|
-
* @param {IObject<any>} target
|
|
182
|
-
* @return {string}
|
|
183
|
-
|
|
180
|
+
/**JSON.stringify encapsulation
|
|
181
|
+
* @param {IObject<any>} target object
|
|
182
|
+
* @return {string} A string
|
|
183
|
+
* * /
|
|
184
184
|
|
|
185
185
|
export type IJsonToString = (target: IObject<any>) => string
|
|
186
186
|
|
|
187
187
|
##### function
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
* @param {Function} fn
|
|
191
|
-
* @param {number} time
|
|
192
|
-
* @return {Function}
|
|
193
|
-
|
|
189
|
+
/** throttle: A high-frequency event is triggered, but only once in n seconds
|
|
190
|
+
* @param {Function} fn Function for throttling
|
|
191
|
+
* @param {number} time Execution interval/ms
|
|
192
|
+
* @return {Function} Function after processing
|
|
193
|
+
* * /
|
|
194
194
|
|
|
195
|
-
export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void
|
|
195
|
+
export type IThrottle = (fn: Function, time: number) => (... args: any[]) => void
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
* @param {Function} fn
|
|
199
|
-
* @param {number} time
|
|
200
|
-
* @return {Function}
|
|
201
|
-
|
|
197
|
+
/** debounce: The function executes only once within n seconds after a high-frequency event is triggered
|
|
198
|
+
* @param {Function} fn Function for anti-shake processing
|
|
199
|
+
* @param {number} time Allows running function intervals/milliseconds
|
|
200
|
+
* @return {Function} Function after processing
|
|
201
|
+
* * /
|
|
202
202
|
|
|
203
|
-
export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void
|
|
203
|
+
export type IDebounce = (fn: Function, time: number) => (... args: any[]) => void
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
205
|
+
/ * *
|
|
206
|
+
* Promise flattening to avoid Promise nesting
|
|
207
|
+
* @param {number} timer times out
|
|
208
|
+
* @returns {Promise,resolve,reject}
|
|
209
|
+
* /
|
|
210
210
|
export type IDefer = (timer: number) => IPromise
|
|
211
211
|
|
|
212
|
-
/**await
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
212
|
+
/**await and try catch catch exception handling methods
|
|
213
|
+
* @param {Promise<any>} defer the delay function
|
|
214
|
+
* @returns {Promise<any>} [error, result]
|
|
215
|
+
* /
|
|
217
216
|
export type ICatchAwait<T extends Promise<any>> = (defer: T) => T
|
|
218
|
-
|
|
219
217
|
##### array
|
|
220
218
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
/** The array is out of order
|
|
220
|
+
* @param {Array<any>} arr target array
|
|
221
|
+
* @returns {Array<any>} The array is out of order
|
|
222
|
+
* /
|
|
223
|
+
|
|
226
224
|
export type IArrayRandom<T extends any[]> = (arr: T) => T
|
|
227
225
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
/** array array weight removal
|
|
227
|
+
* @param {Array<any>} arr target array
|
|
228
|
+
* @returns {Array<any>} Specifies the array after deduplication
|
|
229
|
+
* /
|
|
232
230
|
|
|
233
231
|
export type IArrayUniq<T extends any[]> = (arr: T) => T
|
|
234
232
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
233
|
+
/** Array flattens
|
|
234
|
+
* @param {Array<any>} arr target array
|
|
235
|
+
* @returns {Array<any>} A flat array
|
|
236
|
+
* /
|
|
239
237
|
|
|
240
|
-
export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result
|
|
238
|
+
export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result? : T) => T
|
|
241
239
|
|
|
242
240
|
##### element
|
|
243
241
|
|
|
244
242
|
/**IElementParams
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
243
|
+
* @param {string} ele Label type
|
|
244
|
+
* @param {CSSStyleDeclaration} style
|
|
245
|
+
* @param {Attr} attr attribute
|
|
246
|
+
* @param {object} parent Parent element
|
|
247
|
+
* /
|
|
250
248
|
|
|
251
249
|
interface IElementParams<T> {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
250
|
+
ele: T | string
|
|
251
|
+
style: CSSStyleDeclaration
|
|
252
|
+
attr: Attr
|
|
253
|
+
parent: T
|
|
256
254
|
}
|
|
257
255
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
256
|
+
/** Add labels, set properties and styles
|
|
257
|
+
* @param {IElementParams} params configuration
|
|
258
|
+
* @return {ElementObject} Generated label
|
|
259
|
+
* /
|
|
262
260
|
|
|
263
261
|
export type ICreateElement<T = HTMLElement> = (params: IElementParams<T>) => T
|
|
264
262
|
|
|
265
263
|
##### event
|
|
266
264
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
265
|
+
/** Browser events
|
|
266
|
+
* @param {Document} ele tag
|
|
267
|
+
* @param {string} type Event type
|
|
268
|
+
* @param {(e: Event) => void} handler Event callback
|
|
269
|
+
* @return {void}
|
|
270
|
+
* /
|
|
273
271
|
|
|
274
272
|
export type IAddHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void
|
|
275
273
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
274
|
+
/** Cancel event bubbling
|
|
275
|
+
* @param {Event} e Browser event object
|
|
276
|
+
* @return {void}
|
|
277
|
+
* /
|
|
280
278
|
|
|
281
279
|
export type IStopBubble = (e: Event) => void
|
|
282
280
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
281
|
+
/** Cancels the default event
|
|
282
|
+
* @param {Event} e Browser event object
|
|
283
|
+
* @return {void}
|
|
284
|
+
* /
|
|
287
285
|
|
|
288
286
|
export type IStopDefault = (e: Event) => void
|
|
289
287
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
288
|
+
/** Cancels browser events
|
|
289
|
+
* @param {Document} ele tag
|
|
290
|
+
* @param {string} type Event type
|
|
291
|
+
* @param {(e: Event) => void} handler Event callback
|
|
292
|
+
* @return {void}
|
|
293
|
+
* /
|
|
296
294
|
|
|
297
295
|
export type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void
|
|
298
296
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
297
|
+
/** Cancels the default event
|
|
298
|
+
* @param {Event} e Browser event object
|
|
299
|
+
* @return {void}
|
|
300
|
+
* /
|
|
303
301
|
|
|
304
302
|
export type IDispatchEvent = <T extends Document>(ele: T, data: any) => void
|
|
305
303
|
|
|
306
304
|
|
|
307
305
|
##### log
|
|
308
306
|
|
|
309
|
-
/**
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
export type ILogOneLine = (str: string, overwrite
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
307
|
+
/** Single line output
|
|
308
|
+
* @param {string} str Output character
|
|
309
|
+
* @param {boolean} overwrite overwrites the previous output
|
|
310
|
+
* @param {boolean} warp Wrap the last line
|
|
311
|
+
* @return {void}
|
|
312
|
+
* /
|
|
313
|
+
export type ILogOneLine = (str: string, overwrite? : boolean, warp? : boolean) => void
|
|
314
|
+
|
|
315
|
+
/** Loops out a queue
|
|
316
|
+
* @param {string[]} loopList Indicates the output character queue
|
|
317
|
+
* @param {number} index The number of characters
|
|
318
|
+
* @param {boolean} isStop Control pause loop
|
|
319
|
+
* @param {number} timer Indicates two interval times
|
|
320
|
+
* /
|
|
323
321
|
export type ILogLoopParams = {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
322
|
+
loopList? : string[]
|
|
323
|
+
index? : number
|
|
324
|
+
isStop? : boolean
|
|
325
|
+
timer? : number
|
|
328
326
|
}
|
|
329
|
-
export type ILogLoop = (opts
|
|
327
|
+
export type ILogLoop = (opts? : ILogLoopParams) => ILogLoopParams | void
|
|
330
328
|
|
|
331
329
|
##### request
|
|
332
330
|
|
|
333
331
|
export type IRequestParams<T> = T | IObject<any> | null
|
|
334
332
|
|
|
335
|
-
//
|
|
333
|
+
// Request path
|
|
336
334
|
|
|
337
335
|
export type IUrl = string
|
|
338
336
|
|
|
339
|
-
//
|
|
337
|
+
// Environmental judgment
|
|
340
338
|
|
|
341
339
|
export type IEnv = 'Window' | 'Node'
|
|
342
340
|
|
|
343
|
-
// fetch
|
|
341
|
+
// fetch Returns the value
|
|
344
342
|
|
|
345
343
|
export type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer"
|
|
346
344
|
|
|
347
|
-
//
|
|
345
|
+
// Request mode
|
|
348
346
|
|
|
349
347
|
export type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION"
|
|
350
348
|
|
|
351
|
-
// body
|
|
349
|
+
// body structure
|
|
352
350
|
|
|
353
351
|
export type IRequestBody = IRequestParams<BodyInit>
|
|
354
352
|
|
|
355
|
-
// heads
|
|
353
|
+
// heads structure
|
|
356
354
|
|
|
357
355
|
export type IRequestHeaders = IRequestParams<HeadersInit>
|
|
358
356
|
|
|
359
|
-
//
|
|
357
|
+
// Request the base function
|
|
360
358
|
|
|
361
359
|
export type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>
|
|
362
360
|
|
|
363
|
-
//
|
|
361
|
+
// Request function body
|
|
364
362
|
|
|
365
|
-
export type IRequestFn = (url
|
|
363
|
+
export type IRequestFn = (url? : IUrl, query? : IObject<any>, body? : IRequestBody, opts? : IRequestOptions) => Promise<any>
|
|
366
364
|
|
|
367
|
-
//
|
|
365
|
+
// Request parameters
|
|
368
366
|
|
|
369
367
|
export type IRequestOptions = {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
368
|
+
method? : IRequestMethods
|
|
369
|
+
query? : IRequestParams<IObject<any>>
|
|
370
|
+
body? : IRequestBody
|
|
371
|
+
headers? : IRequestHeaders
|
|
372
|
+
controller? : AbortController
|
|
373
|
+
timeout? : number
|
|
374
|
+
timer? : number | unknown | null
|
|
375
|
+
[key: string]: any
|
|
378
376
|
}
|
|
379
377
|
|
|
380
|
-
//
|
|
378
|
+
// Interceptor
|
|
381
379
|
|
|
382
380
|
export type IInterceptors = {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
381
|
+
use(type: "request" | "response" | "error", fn: Function): void
|
|
382
|
+
get reqFn(): Function
|
|
383
|
+
get resFn(): Function
|
|
384
|
+
get errFn(): Function
|
|
387
385
|
}
|
|
388
386
|
|
|
389
|
-
//
|
|
387
|
+
// Public function
|
|
390
388
|
|
|
391
389
|
export type IRequestBase = {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
390
|
+
readonly origin: string
|
|
391
|
+
chackUrl: (url: IUrl) => boolean
|
|
392
|
+
envDesc: () => IEnv
|
|
393
|
+
errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R
|
|
394
|
+
clearTimer: (opts: IRequestOptions) => void
|
|
395
|
+
initAbort: <T = IRequestOptions>(opts: T) => T
|
|
396
|
+
requestType: () => IRequestBaseFn
|
|
397
|
+
fixOrigin: (fixStr: string) => string
|
|
398
|
+
fetch: IRequestBaseFn
|
|
399
|
+
http: IRequestBaseFn
|
|
400
|
+
getDataByType: (type: IDataType, response: Response) => Promise<any>
|
|
403
401
|
}
|
|
404
402
|
|
|
405
|
-
//
|
|
403
|
+
// Initialize parameters
|
|
406
404
|
|
|
407
405
|
export type IRequestInit = {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
406
|
+
initDefaultParams: (url: IUrl, opts: IRequestOptions) => any
|
|
407
|
+
initFetchParams: (url: IUrl, opts: IRequestOptions) => any
|
|
408
|
+
initHttpParams: (url: IUrl, opts: IRequestOptions) => any
|
|
411
409
|
}
|
|
412
410
|
|
|
413
|
-
//
|
|
411
|
+
// Request principal class
|
|
414
412
|
|
|
415
413
|
export type IRequest = {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
414
|
+
GET: IRequestFn
|
|
415
|
+
POST: IRequestFn
|
|
416
|
+
DELETE: IRequestFn
|
|
417
|
+
PUT: IRequestFn
|
|
418
|
+
OPTIONS: IRequestFn
|
|
419
|
+
HEAD: IRequestFn
|
|
420
|
+
PATCH: IRequestFn
|
|
423
421
|
} & IRequestBase
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
<!-- 消息中心 -->
|
|
427
|
-
// 消息中心
|
|
422
|
+
<! -- News Center -->
|
|
423
|
+
// Message Center
|
|
428
424
|
export declare interface Handlers {
|
|
429
|
-
|
|
425
|
+
[key: string]: Array<Function>
|
|
430
426
|
}
|
|
431
427
|
export declare interface IMessageCenter {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
428
|
+
events: Handlers
|
|
429
|
+
_instance? : IMessageCenter
|
|
430
|
+
on: (type: string, handler: Function) => this
|
|
431
|
+
emit: (type: string, data? : any) => this
|
|
432
|
+
un: (type: string, handler? : Function) => this
|
|
433
|
+
once: (type: string, handler: Function) => this
|
|
434
|
+
clear: () => this
|
|
435
|
+
has: (type: string) => boolean
|
|
436
|
+
handlerLength: (type: string) => number
|
|
437
|
+
watch: (type: string, handler: Function) => this
|
|
438
|
+
invoke: (type: string, data? : any) => Promise<void>
|
|
443
439
|
}
|
|
444
440
|
|
|
445
441
|
https://gitee.com/DieHunter/message-center
|
|
446
442
|
|
|
447
|
-
|
|
443
|
+
<! -- Task Queue -->
|
|
448
444
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
445
|
+
/ * *
|
|
446
|
+
* Single queue
|
|
447
|
+
* defer: asynchronous function to be run
|
|
448
|
+
* params? The: defer parameter can also be passed directly using bind
|
|
449
|
+
*
|
|
450
|
+
* /
|
|
455
451
|
export interface IQueue {
|
|
456
|
-
|
|
457
|
-
|
|
452
|
+
defer: Function
|
|
453
|
+
name? : string
|
|
458
454
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
455
|
+
/ * *
|
|
456
|
+
* Queue parameter
|
|
457
|
+
* children: Queue list
|
|
458
|
+
* name: indicates the unique identifier of the queue
|
|
459
|
+
* result: indicates the result after the run is complete
|
|
460
|
+
*
|
|
461
|
+
* /
|
|
466
462
|
export interface IQueues {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
463
|
+
children: Array<Function>
|
|
464
|
+
name: string
|
|
465
|
+
result? : any[]
|
|
470
466
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
467
|
+
/ * *
|
|
468
|
+
* queue cache
|
|
469
|
+
* /
|
|
474
470
|
export type IQueueTemp = {
|
|
475
|
-
|
|
471
|
+
[key: string]: IQueues
|
|
476
472
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
473
|
+
/ * *
|
|
474
|
+
* System queue
|
|
475
|
+
* /
|
|
480
476
|
export type IQueueList = Array<IQueue>
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
477
|
+
/ * *
|
|
478
|
+
* The queue status idle: idle pending: waiting fulfilled: completed rejected: failed
|
|
479
|
+
* /
|
|
484
480
|
export type IState = "idle" | "pending" | "fulfilled" | "rejected"
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
481
|
+
/ * *
|
|
482
|
+
* Task queue parameters
|
|
483
|
+
* /
|
|
488
484
|
export type ITaskQueueProps = {
|
|
489
|
-
|
|
485
|
+
maxLen: number
|
|
490
486
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
487
|
+
/ * *
|
|
488
|
+
* Task queue
|
|
489
|
+
* /
|
|
494
490
|
export type ITaskQueue = {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
491
|
+
readonly fix: string
|
|
492
|
+
props: ITaskQueueProps
|
|
493
|
+
queueTemp: IQueueTemp
|
|
494
|
+
queues: IQueueList
|
|
495
|
+
state: IState
|
|
496
|
+
push: (queue: IQueues) => Promise<void>
|
|
497
|
+
unshift: (length: number) => IQueueList
|
|
498
|
+
run: (reject: any) => unknown
|
|
499
|
+
clear: () => void
|
|
504
500
|
}
|
|
505
501
|
|
|
506
502
|
https://gitee.com/DieHunter/task-queue
|
|
507
503
|
|
|
508
|
-
/**
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
504
|
+
/** Single line output
|
|
505
|
+
* @param {string} str Output character
|
|
506
|
+
* @param {boolean} overwrite overwrites the previous output
|
|
507
|
+
* @param {boolean} warp Wrap the last line
|
|
508
|
+
* @return {void}
|
|
509
|
+
* /
|
|
514
510
|
export function logOneLine(str: string): void
|
|
515
|
-
export function logOneLine(str: string, overwrite
|
|
516
|
-
export function logOneLine(str: string, overwrite
|
|
511
|
+
export function logOneLine(str: string, overwrite? : boolean): void
|
|
512
|
+
export function logOneLine(str: string, overwrite? : boolean, warp? : boolean): void
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
// animate
|
|
516
|
+
|
|
517
|
+
/ * *
|
|
518
|
+
* Animation
|
|
519
|
+
* reference: https://gitee.com/DieHunter/myCode/tree/master/%E5%89%8D%E7%AB%AF%E5%8A%A8%E7%94%BB/js
|
|
520
|
+
*
|
|
521
|
+
* /
|
|
522
|
+
export type IAnimateFrame = {
|
|
523
|
+
id: number | null // Animation index
|
|
524
|
+
duration: number // Frame number control
|
|
525
|
+
isActive: boolean// Activate control
|
|
526
|
+
fn(timer: number): void
|
|
527
|
+
start(duration: number): void
|
|
528
|
+
stop(): void
|
|
529
|
+
animate(timer: number): void
|
|
530
|
+
}
|
|
531
|
+
declare var IAnimateFrame: {
|
|
532
|
+
new(fn: (timer: number) => void): IAnimateFrame
|
|
533
|
+
prototype: IAnimateFrame
|
|
534
|
+
}
|