utils-lib-js 1.0.8 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -26,4 +26,305 @@ JavaScript工具函数,封装的一些常用的js函数
26
26
 
27
27
  #### 功能
28
28
  接口:
29
- src\types.ts
29
+
30
+ export type IKey = string | symbol | number
31
+ // 对象类型
32
+ export interface IObject<T> {
33
+ [key: IKey]: T | IObject<any>
34
+ }
35
+ export interface IPromise extends IObject<any> {
36
+ promise: Promise<void>
37
+ resolve: (res: any) => unknown
38
+ reject: (err: any) => unknown
39
+ }
40
+ export type IInstance<T> = {
41
+ _instance: Function
42
+ } & T
43
+ export type IDemoteArray<T> = Array<IDemoteArray<T> | T>
44
+
45
+ // base
46
+ /**产生区间随机数
47
+ * @param {number} min 最小区间
48
+ * @param {number} max 最大区间
49
+ * @param {boolean} bool 包含最大值
50
+ * @return {number} 随机数
51
+ **/
52
+ export type IRandomNum = (min: number, max: number, bool?: boolean) => number
53
+
54
+ /**获取url的参数
55
+ * @param {string} url 待截取的地址
56
+ * @return {object} 参数对象
57
+ **/
58
+ export type IUrlSplit = (url: string) => IObject<any>
59
+
60
+ /**添加url的参数
61
+ * @param {string} url 待添加参数的地址
62
+ * @param {object} query 待添加的参数
63
+ * @return {string} 添加参数后的url
64
+ **/
65
+ export type IUrlJoin = (url: string, query: object) => string
66
+
67
+ /**获取数据类型
68
+ * @param {any} data 待检测数据
69
+ * @return {string} 数据类型
70
+ **/
71
+ export type IGetType<T> = (data: any) => typeof data | T[keyof T] | "null";
72
+
73
+ /**批量判断数据类型
74
+ * @param {any} data 待检测数据
75
+ * @param {any} whiteList 数据类型名单
76
+ * @return {boolean} 是否在白名单中
77
+ **/
78
+ export type IGetTypeByList = (data: any, whiteList: string[]) => boolean;
79
+
80
+
81
+ // object
82
+ /**lodash中的 _.get(),获取对象某级属性
83
+ * @param {IObject} object 目标对象
84
+ * @param {string} key 对象层级
85
+ * @param {any} defaultValue 未取得时默认值
86
+ * @return {IObject[IKey]} 对象某个属性
87
+ **/
88
+ export type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: string, defaultValue?: any) => U
89
+
90
+ /**lodash中的 _.set(),赋值对象某级属性
91
+ * @param {IObject} object 目标对象
92
+ * @param {string} key 对象层级
93
+ * @param {any} value 需要赋的值
94
+ * @return {IObject} 目标对象
95
+ **/
96
+ export type ISetValue = <T>(object: IObject<T>, key: string, value?: any) => IObject<T>
97
+
98
+ /**对象混入
99
+ * @param {IObject} target 目标对象
100
+ * @param {string} source 需要混入的对象集合
101
+ * @param {boolean} overwrite 是否重写覆盖原有属性
102
+ * @return {IObject} 目标对象
103
+ **/
104
+ export type IMixIn = <U extends IObject<any>>(target?: U, source?: IObject<any>, overwrite?: boolean) => U
105
+
106
+ /**枚举值反向映射
107
+ * @param {IObject<string>} target 目标对象
108
+ * @return {IObject<string>} 目标对象
109
+ **/
110
+ export type IEnumInversion = (target: IObject<string>) => IObject<string>
111
+
112
+ /**对象复制
113
+ * @param {IObject<any>} target 目标对象
114
+ * @return {IObject} 目标对象
115
+ **/
116
+ export type ICloneDeep = (target?: any) => any
117
+
118
+ /**生成 对象 类型的初始值
119
+ * @param {string} type 数据类型
120
+ * @param {any} __init 初始值
121
+ * @return {any} 目标对象
122
+ **/
123
+ export type ICreateObjectVariable = (type: string, source?: any) => any
124
+
125
+ /**Object.create 根据源对象产出新对象
126
+ * @param {Function|Object} source 源对象
127
+ * @return {Function|Object} 对象产物
128
+ **/
129
+ export type ICreateObject = <T, U extends T>(source: T) => U
130
+
131
+ /**类的继承
132
+ * @param {Function} source 源对象
133
+ * @return {Function} 继承产物
134
+ **/
135
+ export type IInherit = <T extends Function>(source: T, target?: Function) => Function
136
+
137
+ /**生成类的实例单例
138
+ * @param {Function} classProto 类
139
+ * @param {Boolean} overwrite 是否覆盖已有单例
140
+ * @param {any[]} params 构造函数的参数
141
+ * @return {IObject} 实例化的单例
142
+ **/
143
+ export type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite?: boolean, ...params: any[]) => Function
144
+
145
+ /**通过装饰器将属性混入类中
146
+ * @param {IObject<any>} params 混入的属性
147
+ * @return {ClassDecorator} 装饰器钩子函数
148
+ **/
149
+ export type IClassDecorator = (params: IObject<any>) => <TFunction extends Function>(target: TFunction) => void
150
+
151
+ /**JSON.parse封装
152
+ * @param {string} target 字符串
153
+ * @return {IObject<any>} 对象
154
+ **/
155
+ export type IStringToJson = (target: string) => IObject<any>
156
+
157
+ /**JSON.stringify封装
158
+ * @param {IObject<any>} target 对象
159
+ * @return {string} 字符串
160
+ **/
161
+ export type IJsonToString = (target: IObject<any>) => string
162
+
163
+ // function
164
+ /**节流(throttle):高频事件触发,但在 n 秒内只会执行一次
165
+ * @param {Function} fn 节流处理的函数
166
+ * @param {number} time 执行间隔/毫秒
167
+ * @return {Function} 处理后的函数
168
+ **/
169
+ export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void
170
+
171
+ /**防抖(debounce):触发高频事件后 n 秒内函数只会执行一次
172
+ * @param {Function} fn 防抖处理的函数
173
+ * @param {number} time 允许运行函数间隔/毫秒
174
+ * @return {Function} 处理后的函数
175
+ **/
176
+ export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void
177
+
178
+ /**
179
+ * Promise扁平化,避免Promise嵌套
180
+ * @returns {Promise,resolve,reject}
181
+ */
182
+ export type IDefer = () => IPromise
183
+
184
+ /**await与try catch 捕获异常处理方法
185
+ * @param {Promise<any>} defer 延迟函数
186
+ * @returns {Promise<any>} [error, result]
187
+ */
188
+ export type ICatchAwait<T extends Promise<any>> = (defer: T) => T
189
+
190
+ // array
191
+ /**数组乱序
192
+ * @param {Array<any>} arr 目标数组
193
+ * @returns {Array<any>} 乱序后的数组
194
+ */
195
+ export type IArrayRandom<T extends any[]> = (arr: T) => T
196
+
197
+ /**数组数组去重
198
+ * @param {Array<any>} arr 目标数组
199
+ * @returns {Array<any>} 去重后的数组
200
+ */
201
+ export type IArrayUniq<T extends any[]> = (arr: T) => T
202
+
203
+ /**数组扁平化
204
+ * @param {Array<any>} arr 目标数组
205
+ * @returns {Array<any>} 扁平化的数组
206
+ */
207
+
208
+ export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T
209
+
210
+ // element
211
+ /**IElementParams
212
+ * @param {string} ele 标签类型
213
+ * @param {CSSStyleDeclaration} style 样式
214
+ * @param {Attr} attr 属性
215
+ * @param {object} parent 父元素
216
+ */
217
+ interface IElementParams<T> {
218
+ ele: T | string
219
+ style: CSSStyleDeclaration
220
+ attr: Attr
221
+ parent: T
222
+ }
223
+ /**新增标签,设置属性及样式
224
+ * @param {IElementParams} params 配置
225
+ * @return {ElementObject} 生成的标签
226
+ */
227
+ export type ICreateElement<T = HTMLElement> = (params: IElementParams<T>) => T
228
+
229
+ // event
230
+ /**浏览器事件
231
+ * @param {Document} ele 标签
232
+ * @param {string} type 事件类型
233
+ * @param {(e: Event) => void} handler 事件回调
234
+ * @return {void}
235
+ */
236
+ export type IAddHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void
237
+
238
+ /**取消事件冒泡
239
+ * @param {Event} e 浏览器事件对象
240
+ * @return {void}
241
+ */
242
+ export type IStopBubble = (e: Event) => void
243
+
244
+ /**取消默认事件
245
+ * @param {Event} e 浏览器事件对象
246
+ * @return {void}
247
+ */
248
+ export type IStopDefault = (e: Event) => void
249
+
250
+ /**取消浏览器事件
251
+ * @param {Document} ele 标签
252
+ * @param {string} type 事件类型
253
+ * @param {(e: Event) => void} handler 事件回调
254
+ * @return {void}
255
+ */
256
+ export type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void
257
+
258
+ /**取消默认事件
259
+ * @param {Event} e 浏览器事件对象
260
+ * @return {void}
261
+ */
262
+ export type IDispatchEvent = <T extends Document>(ele: T, data: any) => void
263
+
264
+ // request
265
+
266
+ export type IRequestParams<T> = T | IObject<any> | null
267
+ // 请求路径
268
+ export type IUrl = string
269
+ // 环境判断
270
+ export type IEnv = 'Window' | 'Node'
271
+ // fetch返回取值方式
272
+ export type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer"
273
+ // 请求方式
274
+ export type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION"
275
+ // body结构
276
+ export type IRequestBody = IRequestParams<BodyInit>
277
+ // heads结构
278
+ export type IRequestHeaders = IRequestParams<HeadersInit>
279
+ // 请求基础函数
280
+ export type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>
281
+ // 请求函数体
282
+ export type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>
283
+ // 请求参数
284
+ export type IRequestOptions = {
285
+ method?: IRequestMethods
286
+ query?: IRequestParams<IObject<any>>
287
+ body?: IRequestBody
288
+ headers?: IRequestHeaders
289
+ controller?: AbortController
290
+ timeout?: number
291
+ timer?: number | unknown | null
292
+ [key: string]: any
293
+ }
294
+ // 拦截器
295
+ export type IInterceptors = {
296
+ use(type: "request" | "response" | "error", fn: Function): void
297
+ get reqFn(): Function
298
+ get resFn(): Function
299
+ get errFn(): Function
300
+ }
301
+ // 公共函数
302
+ export type IRequestBase = {
303
+ readonly origin: string
304
+ chackUrl: (url: IUrl) => boolean
305
+ envDesc: () => IEnv
306
+ errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R
307
+ clearTimer: (opts: IRequestOptions) => void
308
+ initAbort: <T = IRequestOptions>(opts: T) => T
309
+ requestType: () => IRequestBaseFn
310
+ fixOrigin: (fixStr: string) => string
311
+ fetch: IRequestBaseFn
312
+ http: IRequestBaseFn
313
+ getDataByType: (type: IDataType, response: Response) => Promise<any>
314
+ }
315
+ // 初始化参数
316
+ export type IRequestInit = {
317
+ initDefaultParams: (url: IUrl, opts: IRequestOptions) => any
318
+ initFetchParams: (url: IUrl, opts: IRequestOptions) => any
319
+ initHttpParams: (url: IUrl, opts: IRequestOptions) => any
320
+ }
321
+ // 请求主体类
322
+ export type IRequest = {
323
+ GET: IRequestFn
324
+ POST: IRequestFn
325
+ DELETE: IRequestFn
326
+ PUT: IRequestFn
327
+ OPTIONS: IRequestFn
328
+ HEAD: IRequestFn
329
+ PATCH: IRequestFn
330
+ } & IRequestBase
package/README.md CHANGED
@@ -26,4 +26,373 @@ JavaScript工具函数,封装的一些常用的js函数
26
26
 
27
27
  #### 功能
28
28
  接口:
29
- src\types.ts
29
+
30
+ export type IKey = string | symbol | number
31
+
32
+ ##### 对象类型
33
+
34
+ export interface IObject<T> {
35
+ [key: IKey]: T | IObject<any>
36
+ }
37
+
38
+ export interface IPromise extends IObject<any> {
39
+ promise: Promise<void>
40
+ resolve: (res: any) => unknown
41
+ reject: (err: any) => unknown
42
+ }
43
+
44
+ export type IInstance<T> = {
45
+ _instance: Function
46
+ } & T
47
+
48
+ export type IDemoteArray<T> = Array<IDemoteArray<T> | T>
49
+
50
+ ##### base
51
+
52
+ /**产生区间随机数
53
+ * @param {number} min 最小区间
54
+ * @param {number} max 最大区间
55
+ * @param {boolean} bool 包含最大值
56
+ * @return {number} 随机数
57
+ **/
58
+
59
+ export type IRandomNum = (min: number, max: number, bool?: boolean) => number
60
+
61
+ /**获取url的参数
62
+ * @param {string} url 待截取的地址
63
+ * @return {object} 参数对象
64
+ **/
65
+
66
+ export type IUrlSplit = (url: string) => IObject<any>
67
+
68
+ /**添加url的参数
69
+ * @param {string} url 待添加参数的地址
70
+ * @param {object} query 待添加的参数
71
+ * @return {string} 添加参数后的url
72
+ **/
73
+
74
+ export type IUrlJoin = (url: string, query: object) => string
75
+
76
+ /**获取数据类型
77
+ * @param {any} data 待检测数据
78
+ * @return {string} 数据类型
79
+ **/
80
+
81
+ export type IGetType<T> = (data: any) => typeof data | T[keyof T] | "null";
82
+
83
+ /**批量判断数据类型
84
+ * @param {any} data 待检测数据
85
+ * @param {any} whiteList 数据类型名单
86
+ * @return {boolean} 是否在白名单中
87
+ **/
88
+
89
+ export type IGetTypeByList = (data: any, whiteList: string[]) => boolean;
90
+
91
+
92
+ ##### object
93
+
94
+ /**lodash中的 _.get(),获取对象某级属性
95
+ * @param {IObject} object 目标对象
96
+ * @param {string} key 对象层级
97
+ * @param {any} defaultValue 未取得时默认值
98
+ * @return {IObject[IKey]} 对象某个属性
99
+ **/
100
+
101
+ export type IGetValue = <T, U = IObject<T> | IObject<T>[IKey]>(object: U, key: string, defaultValue?: any) => U
102
+
103
+ /**lodash中的 _.set(),赋值对象某级属性
104
+ * @param {IObject} object 目标对象
105
+ * @param {string} key 对象层级
106
+ * @param {any} value 需要赋的值
107
+ * @return {IObject} 目标对象
108
+ **/
109
+
110
+ export type ISetValue = <T>(object: IObject<T>, key: string, value?: any) => IObject<T>
111
+
112
+ /**对象混入
113
+ * @param {IObject} target 目标对象
114
+ * @param {string} source 需要混入的对象集合
115
+ * @param {boolean} overwrite 是否重写覆盖原有属性
116
+ * @return {IObject} 目标对象
117
+ **/
118
+
119
+ export type IMixIn = <U extends IObject<any>>(target?: U, source?: IObject<any>, overwrite?: boolean) => U
120
+
121
+ /**枚举值反向映射
122
+ * @param {IObject<string>} target 目标对象
123
+ * @return {IObject<string>} 目标对象
124
+ **/
125
+
126
+ export type IEnumInversion = (target: IObject<string>) => IObject<string>
127
+
128
+ /**对象复制
129
+ * @param {IObject<any>} target 目标对象
130
+ * @return {IObject} 目标对象
131
+ **/
132
+
133
+ export type ICloneDeep = (target?: any) => any
134
+
135
+ /**生成 对象 类型的初始值
136
+ * @param {string} type 数据类型
137
+ * @param {any} __init 初始值
138
+ * @return {any} 目标对象
139
+ **/
140
+
141
+ export type ICreateObjectVariable = (type: string, source?: any) => any
142
+
143
+ /**Object.create 根据源对象产出新对象
144
+ * @param {Function|Object} source 源对象
145
+ * @return {Function|Object} 对象产物
146
+ **/
147
+
148
+ export type ICreateObject = <T, U extends T>(source: T) => U
149
+
150
+ /**类的继承
151
+ * @param {Function} source 源对象
152
+ * @return {Function} 继承产物
153
+ **/
154
+
155
+ export type IInherit = <T extends Function>(source: T, target?: Function) => Function
156
+
157
+ /**生成类的实例单例
158
+ * @param {Function} classProto 类
159
+ * @param {Boolean} overwrite 是否覆盖已有单例
160
+ * @param {any[]} params 构造函数的参数
161
+ * @return {IObject} 实例化的单例
162
+ **/
163
+
164
+ export type IGetInstance = (classProto: IInstance<FunctionConstructor>, overwrite?: boolean, ...params: any[]) => Function
165
+
166
+ /**通过装饰器将属性混入类中
167
+ * @param {IObject<any>} params 混入的属性
168
+ * @return {ClassDecorator} 装饰器钩子函数
169
+ **/
170
+
171
+ export type IClassDecorator = (params: IObject<any>) => <TFunction extends Function>(target: TFunction) => void
172
+
173
+ /**JSON.parse封装
174
+ * @param {string} target 字符串
175
+ * @return {IObject<any>} 对象
176
+ **/
177
+
178
+ export type IStringToJson = (target: string) => IObject<any>
179
+
180
+ /**JSON.stringify封装
181
+ * @param {IObject<any>} target 对象
182
+ * @return {string} 字符串
183
+ **/
184
+
185
+ export type IJsonToString = (target: IObject<any>) => string
186
+
187
+ ##### function
188
+
189
+ /**节流(throttle):高频事件触发,但在 n 秒内只会执行一次
190
+ * @param {Function} fn 节流处理的函数
191
+ * @param {number} time 执行间隔/毫秒
192
+ * @return {Function} 处理后的函数
193
+ **/
194
+
195
+ export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void
196
+
197
+ /**防抖(debounce):触发高频事件后 n 秒内函数只会执行一次
198
+ * @param {Function} fn 防抖处理的函数
199
+ * @param {number} time 允许运行函数间隔/毫秒
200
+ * @return {Function} 处理后的函数
201
+ **/
202
+
203
+ export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void
204
+
205
+ /**
206
+ * Promise扁平化,避免Promise嵌套
207
+ * @returns {Promise,resolve,reject}
208
+ */
209
+
210
+ export type IDefer = () => IPromise
211
+
212
+ /**await与try catch 捕获异常处理方法
213
+ * @param {Promise<any>} defer 延迟函数
214
+ * @returns {Promise<any>} [error, result]
215
+ */
216
+
217
+ export type ICatchAwait<T extends Promise<any>> = (defer: T) => T
218
+
219
+ ##### array
220
+
221
+ /**数组乱序
222
+ * @param {Array<any>} arr 目标数组
223
+ * @returns {Array<any>} 乱序后的数组
224
+ */
225
+
226
+ export type IArrayRandom<T extends any[]> = (arr: T) => T
227
+
228
+ /**数组数组去重
229
+ * @param {Array<any>} arr 目标数组
230
+ * @returns {Array<any>} 去重后的数组
231
+ */
232
+
233
+ export type IArrayUniq<T extends any[]> = (arr: T) => T
234
+
235
+ /**数组扁平化
236
+ * @param {Array<any>} arr 目标数组
237
+ * @returns {Array<any>} 扁平化的数组
238
+ */
239
+
240
+ export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T
241
+
242
+ ##### element
243
+
244
+ /**IElementParams
245
+ * @param {string} ele 标签类型
246
+ * @param {CSSStyleDeclaration} style 样式
247
+ * @param {Attr} attr 属性
248
+ * @param {object} parent 父元素
249
+ */
250
+
251
+ interface IElementParams<T> {
252
+ ele: T | string
253
+ style: CSSStyleDeclaration
254
+ attr: Attr
255
+ parent: T
256
+ }
257
+
258
+ /**新增标签,设置属性及样式
259
+ * @param {IElementParams} params 配置
260
+ * @return {ElementObject} 生成的标签
261
+ */
262
+
263
+ export type ICreateElement<T = HTMLElement> = (params: IElementParams<T>) => T
264
+
265
+ ##### event
266
+
267
+ /**浏览器事件
268
+ * @param {Document} ele 标签
269
+ * @param {string} type 事件类型
270
+ * @param {(e: Event) => void} handler 事件回调
271
+ * @return {void}
272
+ */
273
+
274
+ export type IAddHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void
275
+
276
+ /**取消事件冒泡
277
+ * @param {Event} e 浏览器事件对象
278
+ * @return {void}
279
+ */
280
+
281
+ export type IStopBubble = (e: Event) => void
282
+
283
+ /**取消默认事件
284
+ * @param {Event} e 浏览器事件对象
285
+ * @return {void}
286
+ */
287
+
288
+ export type IStopDefault = (e: Event) => void
289
+
290
+ /**取消浏览器事件
291
+ * @param {Document} ele 标签
292
+ * @param {string} type 事件类型
293
+ * @param {(e: Event) => void} handler 事件回调
294
+ * @return {void}
295
+ */
296
+
297
+ export type IRemoveHandler = <T extends Document>(ele: T, type: string, handler: (e: Event) => void) => void
298
+
299
+ /**取消默认事件
300
+ * @param {Event} e 浏览器事件对象
301
+ * @return {void}
302
+ */
303
+
304
+ export type IDispatchEvent = <T extends Document>(ele: T, data: any) => void
305
+
306
+ ##### request
307
+
308
+ export type IRequestParams<T> = T | IObject<any> | null
309
+
310
+ // 请求路径
311
+
312
+ export type IUrl = string
313
+
314
+ // 环境判断
315
+
316
+ export type IEnv = 'Window' | 'Node'
317
+
318
+ // fetch返回取值方式
319
+
320
+ export type IDataType = "text" | "json" | "blob" | "formData" | "arrayBuffer"
321
+
322
+ // 请求方式
323
+
324
+ export type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTION"
325
+
326
+ // body结构
327
+
328
+ export type IRequestBody = IRequestParams<BodyInit>
329
+
330
+ // heads结构
331
+
332
+ export type IRequestHeaders = IRequestParams<HeadersInit>
333
+
334
+ // 请求基础函数
335
+
336
+ export type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>
337
+
338
+ // 请求函数体
339
+
340
+ export type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>
341
+
342
+ // 请求参数
343
+
344
+ export type IRequestOptions = {
345
+ method?: IRequestMethods
346
+ query?: IRequestParams<IObject<any>>
347
+ body?: IRequestBody
348
+ headers?: IRequestHeaders
349
+ controller?: AbortController
350
+ timeout?: number
351
+ timer?: number | unknown | null
352
+ [key: string]: any
353
+ }
354
+
355
+ // 拦截器
356
+
357
+ export type IInterceptors = {
358
+ use(type: "request" | "response" | "error", fn: Function): void
359
+ get reqFn(): Function
360
+ get resFn(): Function
361
+ get errFn(): Function
362
+ }
363
+
364
+ // 公共函数
365
+
366
+ export type IRequestBase = {
367
+ readonly origin: string
368
+ chackUrl: (url: IUrl) => boolean
369
+ envDesc: () => IEnv
370
+ errorFn: <Err = any, R = Function>(reject: R) => (err: Err) => R
371
+ clearTimer: (opts: IRequestOptions) => void
372
+ initAbort: <T = IRequestOptions>(opts: T) => T
373
+ requestType: () => IRequestBaseFn
374
+ fixOrigin: (fixStr: string) => string
375
+ fetch: IRequestBaseFn
376
+ http: IRequestBaseFn
377
+ getDataByType: (type: IDataType, response: Response) => Promise<any>
378
+ }
379
+
380
+ // 初始化参数
381
+
382
+ export type IRequestInit = {
383
+ initDefaultParams: (url: IUrl, opts: IRequestOptions) => any
384
+ initFetchParams: (url: IUrl, opts: IRequestOptions) => any
385
+ initHttpParams: (url: IUrl, opts: IRequestOptions) => any
386
+ }
387
+
388
+ // 请求主体类
389
+
390
+ export type IRequest = {
391
+ GET: IRequestFn
392
+ POST: IRequestFn
393
+ DELETE: IRequestFn
394
+ PUT: IRequestFn
395
+ OPTIONS: IRequestFn
396
+ HEAD: IRequestFn
397
+ PATCH: IRequestFn
398
+ } & IRequestBase
@@ -1,4 +1,4 @@
1
- import { IRequest, IRequestBase, IRequestInit, IInterceptors } from "./index.js";
1
+ import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions } from "./index.js";
2
2
  declare class Interceptors implements IInterceptors {
3
3
  private requestSuccess;
4
4
  private responseSuccess;
@@ -54,12 +54,12 @@ export declare class Request extends RequestInit implements IRequest {
54
54
  constructor(origin: any);
55
55
  fetch: (_url: any, _opts: any) => Promise<void>;
56
56
  http: (_url: any, _opts: any) => Promise<void>;
57
- GET: (url: any, query: {}, _: any, opts: any) => any;
58
- POST: (url: any, query: {}, body: any, opts: any) => any;
59
- PUT: (url: any, query: {}, body: any, opts: any) => any;
60
- DELETE: (url: any, query: {}, body: any, opts: any) => any;
61
- OPTIONS: (url: any, query: {}, body: any, opts: any) => any;
62
- HEAD: (url: any, query: {}, body: any, opts: any) => any;
63
- PATCH: (url: any, query: {}, body: any, opts: any) => any;
57
+ GET: (url?: IUrl, query?: IObject<any>, _?: IRequestBody | void, opts?: IRequestOptions) => any;
58
+ POST: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
59
+ PUT: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
60
+ DELETE: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
61
+ OPTIONS: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
62
+ HEAD: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
63
+ PATCH: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
64
64
  }
65
65
  export {};
@@ -232,45 +232,24 @@ var Request = function (_super) {
232
232
  return promise;
233
233
  };
234
234
  _this.GET = function (url, query, _, opts) {
235
- if (query === void 0) {
236
- query = {};
237
- }
238
235
  return _this.request(url, __assign({ query: query, method: "GET" }, opts));
239
236
  };
240
237
  _this.POST = function (url, query, body, opts) {
241
- if (query === void 0) {
242
- query = {};
243
- }
244
238
  return _this.request(url, __assign({ query: query, method: "POST", body: body }, opts));
245
239
  };
246
240
  _this.PUT = function (url, query, body, opts) {
247
- if (query === void 0) {
248
- query = {};
249
- }
250
241
  return _this.request(url, __assign({ query: query, method: "PUT", body: body }, opts));
251
242
  };
252
243
  _this.DELETE = function (url, query, body, opts) {
253
- if (query === void 0) {
254
- query = {};
255
- }
256
244
  return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts));
257
245
  };
258
246
  _this.OPTIONS = function (url, query, body, opts) {
259
- if (query === void 0) {
260
- query = {};
261
- }
262
247
  return _this.request(url, __assign({ query: query, method: "OPTIONS", body: body }, opts));
263
248
  };
264
249
  _this.HEAD = function (url, query, body, opts) {
265
- if (query === void 0) {
266
- query = {};
267
- }
268
250
  return _this.request(url, __assign({ query: query, method: "HEAD", body: body }, opts));
269
251
  };
270
252
  _this.PATCH = function (url, query, body, opts) {
271
- if (query === void 0) {
272
- query = {};
273
- }
274
253
  return _this.request(url, __assign({ query: query, method: "PATCH", body: body }, opts));
275
254
  };
276
255
  _this.request = _this.requestType();
@@ -55,7 +55,7 @@ export declare type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTIO
55
55
  export declare type IRequestBody = IRequestParams<BodyInit>;
56
56
  export declare type IRequestHeaders = IRequestParams<HeadersInit>;
57
57
  export declare type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>;
58
- export declare type IRequestFn = (url?: IUrl, params?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>;
58
+ export declare type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>;
59
59
  export declare type IRequestOptions = {
60
60
  method?: IRequestMethods;
61
61
  query?: IRequestParams<IObject<any>>;
@@ -1,4 +1,4 @@
1
- import { IRequest, IRequestBase, IRequestInit, IInterceptors } from "./index.js";
1
+ import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions } from "./index.js";
2
2
  declare class Interceptors implements IInterceptors {
3
3
  private requestSuccess;
4
4
  private responseSuccess;
@@ -54,12 +54,12 @@ export declare class Request extends RequestInit implements IRequest {
54
54
  constructor(origin: any);
55
55
  fetch: (_url: any, _opts: any) => Promise<void>;
56
56
  http: (_url: any, _opts: any) => Promise<void>;
57
- GET: (url: any, query: {}, _: any, opts: any) => any;
58
- POST: (url: any, query: {}, body: any, opts: any) => any;
59
- PUT: (url: any, query: {}, body: any, opts: any) => any;
60
- DELETE: (url: any, query: {}, body: any, opts: any) => any;
61
- OPTIONS: (url: any, query: {}, body: any, opts: any) => any;
62
- HEAD: (url: any, query: {}, body: any, opts: any) => any;
63
- PATCH: (url: any, query: {}, body: any, opts: any) => any;
57
+ GET: (url?: IUrl, query?: IObject<any>, _?: IRequestBody | void, opts?: IRequestOptions) => any;
58
+ POST: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
59
+ PUT: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
60
+ DELETE: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
61
+ OPTIONS: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
62
+ HEAD: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
63
+ PATCH: (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => any;
64
64
  }
65
65
  export {};
@@ -228,45 +228,24 @@ var Request = function (_super) {
228
228
  return promise;
229
229
  };
230
230
  _this.GET = function (url, query, _, opts) {
231
- if (query === void 0) {
232
- query = {};
233
- }
234
231
  return _this.request(url, __assign({ query: query, method: "GET" }, opts));
235
232
  };
236
233
  _this.POST = function (url, query, body, opts) {
237
- if (query === void 0) {
238
- query = {};
239
- }
240
234
  return _this.request(url, __assign({ query: query, method: "POST", body: body }, opts));
241
235
  };
242
236
  _this.PUT = function (url, query, body, opts) {
243
- if (query === void 0) {
244
- query = {};
245
- }
246
237
  return _this.request(url, __assign({ query: query, method: "PUT", body: body }, opts));
247
238
  };
248
239
  _this.DELETE = function (url, query, body, opts) {
249
- if (query === void 0) {
250
- query = {};
251
- }
252
240
  return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts));
253
241
  };
254
242
  _this.OPTIONS = function (url, query, body, opts) {
255
- if (query === void 0) {
256
- query = {};
257
- }
258
243
  return _this.request(url, __assign({ query: query, method: "OPTIONS", body: body }, opts));
259
244
  };
260
245
  _this.HEAD = function (url, query, body, opts) {
261
- if (query === void 0) {
262
- query = {};
263
- }
264
246
  return _this.request(url, __assign({ query: query, method: "HEAD", body: body }, opts));
265
247
  };
266
248
  _this.PATCH = function (url, query, body, opts) {
267
- if (query === void 0) {
268
- query = {};
269
- }
270
249
  return _this.request(url, __assign({ query: query, method: "PATCH", body: body }, opts));
271
250
  };
272
251
  _this.request = _this.requestType();
@@ -55,7 +55,7 @@ export declare type IRequestMethods = "GET" | "POST" | "DELETE" | "PUT" | "OPTIO
55
55
  export declare type IRequestBody = IRequestParams<BodyInit>;
56
56
  export declare type IRequestHeaders = IRequestParams<HeadersInit>;
57
57
  export declare type IRequestBaseFn = (url: IUrl, opts: IRequestOptions) => Promise<any>;
58
- export declare type IRequestFn = (url?: IUrl, params?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>;
58
+ export declare type IRequestFn = (url?: IUrl, query?: IObject<any>, body?: IRequestBody, opts?: IRequestOptions) => Promise<any>;
59
59
  export declare type IRequestOptions = {
60
60
  method?: IRequestMethods;
61
61
  query?: IRequestParams<IObject<any>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-lib-js",
3
- "version": "1.0.8",
3
+ "version": "1.0.11",
4
4
  "description": "JavaScript工具函数,封装的一些常用的js函数",
5
5
  "main": "./dist/common/index.js",
6
6
  "types": "./dist/common/index.d.ts",