amos-apptool 1.2.0 → 1.2.1

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/index.d.ts CHANGED
@@ -11,12 +11,12 @@ export class Base64 {
11
11
  constructor();
12
12
  /**
13
13
  * 加密字符串
14
- * @param input
14
+ * @param input 待加密的字符串
15
15
  */
16
16
  encode(input: string): string;
17
17
  /**
18
18
  * 解密字符串
19
- * @param input
19
+ * @param input 待解密的字符串
20
20
  */
21
21
  decode(input: string): string;
22
22
  }
@@ -28,7 +28,7 @@ export class Base64 {
28
28
  declare namespace DES {
29
29
  /**
30
30
  * 加密字符串
31
- * @param data
31
+ * @param data 待加密字符串
32
32
  * @param secretKey 秘钥,支持单秘钥以及二级和三级秘钥 `abcde` 和 `a,b` 和 `a,b,c` 等
33
33
  * @example
34
34
  * DES.encode('hello', 'test'); // DES.DesCore.encode(data, 'test');
@@ -39,70 +39,97 @@ declare namespace DES {
39
39
  export function encode(data: string, secretKey: string): string;
40
40
  /**
41
41
  * 解密字符串
42
- * @param data
43
- * @param secretKey
42
+ * @param data 待解密字符串
43
+ * @param secretKey 解密秘钥
44
44
  */
45
45
  export function decode(data: string, secretKey: string): string;
46
46
  }
47
47
 
48
-
49
- export function simpleClone(o: object | Array<any>): object | Array<any>;
50
- export function clone(o: any): object | Array<any>;
51
- export function cloneAll(o: any): any;
52
-
48
+ export function simpleClone<T extends object | any[]>(o: T): T;
49
+ export function clone<T>(o: T): T extends object | any[] ? T : T;
50
+ export function cloneAll<T>(o: T): T;
53
51
 
54
52
  declare namespace UUID {
55
53
  /**
56
- *
54
+ * 生成UUID
57
55
  * @param len uuid 的字符长度
58
56
  * @param radix 位数,默认为 62
59
57
  * @example
60
58
  * UUID.uuid(); // 7ED03492-919F-40D0-89D2-C53194F4A83D
61
59
  */
62
- export function uuid(len: number, radix: number): string;
60
+ export function uuid(len?: number, radix?: number): string;
63
61
  /**
62
+ * 快速生成UUID
64
63
  * @example
65
64
  * UUID.uuidFast(); // E581CCDD-189C-482D-BE21-620863F423F9
66
65
  */
67
66
  export function uuidFast(): string;
68
67
  /**
68
+ * 生成紧凑格式UUID
69
69
  * @example
70
70
  * UUID.uuidCompact(); // 090c3e83-ea67-45c4-b7dc-47c20eaea91e
71
71
  */
72
72
  export function uuidCompact(): string;
73
73
  /**
74
74
  * 获取 uid,以 Date.now() 为随机参照值
75
- * @param flag 是否显示短杠,为 true 则去掉单杠
75
+ * @param flag 是否显示短杠,为 true 则去掉短杠
76
76
  * @example
77
77
  * UUID.uuidTime(); // 6fcac0c8-e7de-44e4-ada7-c1de03a45ad5
78
78
  * UUID.uuidTime(true); // 5eb47f42a03c48e6ae6804a2517a1db4
79
79
  */
80
- export function uuidTime(flag: boolean): string;
80
+ export function uuidTime(flag?: boolean): string;
81
81
  /**
82
- * @param prefix
82
+ * 生成带时间戳的UUID
83
+ * @param prefix 前缀
83
84
  * @example
84
85
  * UUID.timeUUID(); // amos-timeuuid-1663831567208-1
85
86
  */
86
- export function timeUUID(prefix: string): string;
87
+ export function timeUUID(prefix?: string): string;
87
88
  /**
88
- * @param prefix
89
+ * 生成长格式带时间戳的UUID
90
+ * @param prefix 前缀
89
91
  * @example
90
92
  * UUID.longTimeUUID(); // longtime-202209221526-1
91
93
  */
92
- export function longTimeUUID(prefix: string): string;
94
+ export function longTimeUUID(prefix?: string): string;
93
95
  /**
94
- *
95
- * @param tpl
96
+ * 生成自定义格式UUID
97
+ * @param tpl 模板字符串
96
98
  * @example
97
99
  * UUID.otherUUID(); // 6afe5aaf614eb8b00bf4bcd11a
98
100
  */
99
- export function otherUUID(tpl: string): string;
101
+ export function otherUUID(tpl?: string): string;
100
102
  }
101
103
 
102
104
  declare namespace pwdPolicy {
103
- export function normalPolicy(password: string): object;
104
- export function advancePolicy(password: string, secretKey: string): object;
105
- export function useMd5Policy(password: string, secretKey: string): object;
105
+ export interface PasswordPolicyResult {
106
+ password: string;
107
+ secretKey: string;
108
+ }
109
+
110
+ /**
111
+ * 普通密码生成策略
112
+ * @param password
113
+ */
114
+ export function normalPolicy(password: string): PasswordPolicyResult;
115
+ /**
116
+ * 密码生成策略
117
+ * @param password 密码
118
+ * @param secretKey 秘钥
119
+ */
120
+ export function advancePolicy(password: string, secretKey: string): PasswordPolicyResult;
121
+ /**
122
+ * 采用MD5生成密码
123
+ * @param password
124
+ * @param secretKey
125
+ */
126
+ export function useMd5Policy(password: string, secretKey: string): PasswordPolicyResult;
127
+ /**
128
+ * 采用MD5生成密码
129
+ * @param password
130
+ * @param secretKey
131
+ */
132
+ export function useMd5Policy2(password: string, secretKey: string): PasswordPolicyResult;
106
133
  }
107
134
 
108
135
  declare namespace random {
@@ -110,145 +137,177 @@ declare namespace random {
110
137
  export function randomInt(min: number, max: number): number;
111
138
  }
112
139
 
113
-
114
140
  declare namespace strUtils {
115
141
  /**
116
142
  * 首字母大写
117
- * @param str
143
+ * @param str 目标字符串
118
144
  */
119
145
  export function toCapitalStr(str: string): string;
146
+
120
147
  /**
121
148
  * 驼峰化, 仅支持首字母大写、或者采用中杠连接的两个字母首字母大写
122
149
  * 如果要支持其它输入,将正则改为: /(-|(\s+)|_)(\w)/g
123
- *
124
- * @param {String} name
125
- * @returns {String}
150
+ * @param name 目标字符串
151
+ * @returns 驼峰化后的字符串
126
152
  */
127
153
  export function camelCase(name: string): string;
154
+
128
155
  /**
129
- * 将中缸连接的字符串 驼峰化
130
- *
156
+ * 将中杠连接的字符串 驼峰化
157
+ * @example
131
158
  * hello-world => hellWorld
132
159
  * Hello-world => hellWorld
133
160
  * Hello-World => hellWorld
134
- *
135
- * @param {any} name
136
- * @returns {String}
161
+ * @param name 目标字符串
162
+ * @returns 驼峰化后的字符串
137
163
  */
138
164
  export function transCamel(name: string): string;
165
+
139
166
  /**
140
167
  * 字符串首字母大写
141
- * @param {String} str
142
- * @returns {String}
168
+ * @param str 目标字符串
169
+ * @returns 首字母大写后的字符串
143
170
  */
144
- export function capFirst(name: string): string;
171
+ export function capFirst(str: string): string;
172
+
145
173
  /**
146
174
  * 获取字符串的hashCode码
147
- * @param {String} str
148
- * @returns {String} string | null
175
+ * @param str 目标字符串
176
+ * @returns hashCode值或null
149
177
  */
150
- export function hashCode(name: string): string;
178
+ export function hashCode(str: string): string | null;
179
+
151
180
  /**
152
181
  * 进制与单位处理
153
- * @param {String | Number} value 要处理的值
154
- * @param {Object} fmtOpt
155
- * @param {String} fmtOpt.prefix 前缀
156
- * @param {String} fmtOpt.suffix 后缀
157
- * @param {Boolean} fmtOpt.selfenable 自定义进制是否启用
158
- * @param {String} fmtOpt.selfscale 进制
159
- * @param {String} fmtOpt.selfunit 单位
160
- * @param {Number} fmtOpt.fixnumber 小数位数
161
- * @param {Boolean} fmtOpt.fillzero 空位补0
162
- * @param {Boolean} fmtOpt.thousandsplitchar 千分位分隔符
163
- */
164
- export function dealScaleAndUnit(value: string, fmtOpt: Object): string;
165
- /**
166
- * 转化为 utf8
167
- * @param str
182
+ *
183
+ * fmtOpt 参数 字段说明
184
+ * - fmtOpt.prefix 前缀
185
+ * - fmtOpt.suffix 后缀
186
+ * - fmtOpt.selfenable 自定义进制是否启用
187
+ * - fmtOpt.selfscale 进制
188
+ * - fmtOpt.selfunit 单位
189
+ * - fmtOpt.fixnumber 小数位数
190
+ * - fmtOpt.fillzero 空位补0
191
+ * - fmtOpt.thousandsplitchar 千分位分隔符
192
+ * @param value 要处理的值
193
+ * @param fmtOpt 格式化选项
194
+ */
195
+ export function dealScaleAndUnit(
196
+ value: string | number,
197
+ fmtOpt: {
198
+ prefix?: string;
199
+ suffix?: string;
200
+ selfenable?: boolean;
201
+ selfscale?: string;
202
+ selfunit?: string;
203
+ fixnumber?: number;
204
+ fillzero?: boolean;
205
+ thousandsplitchar?: string;
206
+ }
207
+ ): string;
208
+
209
+ /**
210
+ * 转化为 utf8 编码
211
+ * @param str 目标字符串
168
212
  */
169
213
  export function toUTF8(str: string): string;
170
214
  }
171
215
 
172
-
173
216
  declare namespace colorUtil {
174
217
  /**
175
218
  * RGB颜色转换为16进制
176
- * @param stringRgb
219
+ * @param stringRgb RGB/RGBA颜色字符串
177
220
  * @example
178
221
  * toStringHexColor('rgba(241,112,19,1)'); // #f17013
179
222
  * toStringHexColor('rgba(241,112,19, 0.1)'); // #f1701319
180
223
  */
181
224
  export function toStringHexColor(stringRgb: string): string;
225
+
182
226
  /**
183
- * - 转化为hex颜色 (仅支持 RGB),如果是 rgba 时,则舍去 a。
184
- * - 如果传入的是 key color 则直接转化为与之对应的 hex 值
185
- * @param {string} stringRgb
227
+ * 转化为hex颜色 (仅支持 RGB),如果是 rgba 时,则舍去 a。
228
+ * 如果传入的是 key color 则直接转化为与之对应的 hex 值
229
+ * @param stringRgb RGB/RGBA颜色字符串或颜色关键字
186
230
  * @example
187
231
  * toHexColor('rgba(241,112,19)'); // #f17013
188
232
  * toHexColor('rgba(241,112,19, 1)'); // #f17013
189
233
  * toHexColor('rgba(241,112,19, 0.1)'); // #f17013
190
234
  * toHexColor('red'); // #ff0000
191
- * toHexColor(); // ''
192
235
  * toHexColor(null); // ''
193
236
  * toHexColor(123456); // ''
194
237
  * toHexColor(0x123456123456); // ''
195
238
  */
196
- export function toHexColor(stringRgb: string): string;
239
+ export function toHexColor(stringRgb?: string): string;
240
+
197
241
  /**
198
242
  * 16进制颜色转为RGB格式
199
- * @param hexColor
243
+ * @param hexColor 16进制颜色字符串
200
244
  * @example
201
245
  * toRGBcolor('#AABBCC'); // rgb(170,187,204)
202
246
  */
203
- export function toRGBcolor(hexColor): string;
247
+ export function toRGBcolor(hexColor: string): string;
248
+
204
249
  /**
205
250
  * 将16进制的颜色转换为rgb
206
- * @param hexColor
251
+ * @param hexColor 16进制颜色字符串
207
252
  * @example
208
253
  * transformColor('#AABBCC'); // rgb(170,187,204)
209
254
  */
210
255
  export function transformColor(hexColor: string): string;
256
+
257
+ /**
258
+ * 判断是否是16进制颜色
259
+ * @param color 颜色字符串
260
+ */
211
261
  export function isHexColor(color: string): boolean;
262
+
212
263
  /**
213
264
  * 判断是否是内置 英文 color
214
- * @param color
265
+ * @param color 颜色字符串
215
266
  * @example
216
267
  * isKeyColor('red'); // true
217
- * isKeyColor('yellow'); // true
218
268
  * isKeyColor('asdfasdfa'); // false
219
269
  */
220
270
  export function isKeyColor(color: string): boolean;
271
+
272
+ /**
273
+ * 判断是否是RGB/RGBA颜色
274
+ * @param color 颜色字符串
275
+ */
221
276
  export function isRgbColor(color: string): boolean;
277
+
222
278
  /**
223
279
  * 将rgb颜色转化成object
224
- * @param color
280
+ * @param color RGB/RGBA颜色字符串
225
281
  * @example
226
282
  * '12,12,12,12' => {r:12,g:12,b:12,a:12}
227
283
  * 'rgba(12,12,12,12)' => {r:12,g:12,b:12,a:12}
228
284
  */
229
285
  export function rgb2object(color: string): RGBA;
286
+
230
287
  /**
231
288
  * 将object的rgb转化成string
232
- * @param color
289
+ * @param color RGBA对象
233
290
  * @example
234
291
  * objRGB2str({ r:1, g:1, b:1, a:1 }); // 'rgba(1,1,1,1)'
235
292
  * objRGB2str({ r:1, g:1, b:1, a:0 }); // 'rgba(1,1,1,0)'
236
293
  * objRGB2str({ r:1, g:1, b:1 }); // 'rgba(1,1,1)'
237
294
  */
238
- export function objRGB2str(color: object): string;
295
+ export function objRGB2str(color: Partial<RGBA>): string;
296
+
239
297
  /**
240
298
  * key color 转化为 hex color。
241
299
  * 如果不是 key color 则直接返回 color 自身
242
- * @param color
300
+ * @param color 颜色关键字
243
301
  */
244
302
  export function keyColorToHex(color: string): string;
303
+
245
304
  /**
246
305
  * 产生渐变色函数
247
- * @param color
248
- * @param minValue
249
- * @param maxValue
306
+ * @param color 基础颜色
307
+ * @param minValue 最小值
308
+ * @param maxValue 最大值
250
309
  */
251
- export function gradientColor(color: Object, minValue: number, maxValue: number): any;
310
+ export function gradientColor(color: Record<string, any>, minValue: number, maxValue: number): string | RGBA;
252
311
  }
253
312
 
254
313
  declare namespace randomColor {
@@ -257,7 +316,6 @@ declare namespace randomColor {
257
316
  export function randomHexColorStr(): string;
258
317
  }
259
318
 
260
-
261
319
  /**
262
320
  * 转码URL中的特殊字符
263
321
  *
@@ -271,8 +329,8 @@ declare namespace randomColor {
271
329
  * 7. '&' URL 中指定的参数间的分隔符 %26
272
330
  * 8. '=' URL 中指定参数的值 %3D
273
331
  *
274
- * @param url
275
- * @return new url
332
+ * @param url 原始URL
333
+ * @return 转码后的URL
276
334
  * @example
277
335
  * encodeUrl('http://localhost:3000/login?user=123&pwd=123'); // http://localhost:3000/login?user%3D123%26pwd%3D123
278
336
  */
@@ -280,16 +338,14 @@ export function encodeUrl(url: string): string;
280
338
 
281
339
  /**
282
340
  * restful风格路径参数替换
283
- *
284
- * @param url
285
- * @param options
286
- * @param regexps
287
- *
341
+ * @param url 模板URL
342
+ * @param options 参数对象
343
+ * @param regexps 匹配正则
288
344
  * @example
289
345
  * const _url = 'a/b/{id}'
290
346
  * const url = restfulUrl(_url, { id: '123' }, [regex]); => 'a/b/123'
291
347
  */
292
- export function restfulUrl(url: string, options: {}, regexps: RegExp): string;
348
+ export function restfulUrl(url: string, options: Record<string, any>, regexps: RegExp): string;
293
349
 
294
350
  /**
295
351
  * 替换 url 参数。如果url中无指定的参数,则自动追加。
@@ -315,24 +371,28 @@ export function restfulUrl(url: string, options: {}, regexps: RegExp): string;
315
371
  * // 更换 token={token} 值,注意 原理并不是替换 {token} 值,而是更新 `token=xxx` 值,也就是目标是 `=` 左边的 `key` 与 params 中的 key 匹配
316
372
  * changeParam('a/b/d/g?token={token}', { a: 'file', b: [1,2], token: 'mytoken' }); // a/b/d/g?token=mytoken&a=file&b=1,2
317
373
  */
318
- export function changeParam(href: String, params: Object): String;
319
-
320
- /**
321
- * 格式化url
322
- * @param {string} targetStr
323
- * @param {object} dataObj
324
- * @param {string|RegExp} regexps 可选, default: /\{(.*)\}/g);
325
- * @example
374
+ export function changeParam(href: string, params: Record<string, any>): string;
375
+
376
+ /**
377
+ * 格式化url
378
+ * @param targetStr 模板字符串
379
+ * @param dataObj 数据对象
380
+ * @param regexps 匹配正则,默认: /\{(.*)\}/g
381
+ * @example
326
382
  * formatUrl('a/{b}/{c}/d',{a: 1, b:2}) // 返回: 'a/1/2/d'
327
383
  * formatUrl('a/{{b}}/{{c}}/d',{a: 1, b:2}, /\{\{(.*)\}\}/g) // 返回: 'a/1/2/d'
328
384
  */
329
- export function formatUrl(targetStr: string, dataObj: {}, regexps: string|RegExp): string;
385
+ export function formatUrl(
386
+ targetStr: string,
387
+ dataObj: Record<string, any>,
388
+ regexps?: string | RegExp
389
+ ): string;
330
390
 
331
391
  /**
332
- * 补全 url
392
+ * 补全 url 前缀
333
393
  * @param left 左边通用前缀
334
394
  * @param right 右边具体的 url
335
- * @return
395
+ * @return 补全后的URL
336
396
  * @example
337
397
  * completePrefix('/aa/', 'b/c/d'); // '/aa/b/c/d'
338
398
  * completePrefix('/aa /', ' b/c/d'); // '/aa/b/c/d'
@@ -344,11 +404,11 @@ export function formatUrl(targetStr: string, dataObj: {}, regexps: string|RegExp
344
404
  export function completePrefix(left = '', right = ''): string;
345
405
 
346
406
  /**
347
- *
348
- * @param str
349
- * @param key
350
- * @param raw
351
- * @returns md5 value
407
+ * 计算MD5哈希值
408
+ * @param str 目标字符串
409
+ * @param key HMAC密钥(可选)
410
+ * @param raw 是否返回原始二进制数据
411
+ * @returns md5
352
412
  * @example
353
413
  * // calc the (hex-encoded) MD5 hash of a given string value:
354
414
  * var hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"
@@ -359,28 +419,33 @@ export function completePrefix(left = '', right = ''): string;
359
419
  * // calc the raw HMAC-MD5 hash of a given string value and key:
360
420
  * var hash = md5("value", "key", true);
361
421
  */
362
- export function MD5(str: string, key: string, raw: boolean): string;
422
+ export function MD5(str: string, key?: string, raw?: boolean): string;
363
423
 
364
424
  /**
365
- * deep copy
425
+ * 深拷贝
426
+ * @param source 源对象
366
427
  * 1. obj 中包含方法,则直接赋值
367
- * @param source
368
428
  */
369
- export function deepCopy(source: any): any;
429
+ export function deepCopy<T>(source: T): T;
430
+
370
431
  /**
371
- * deep equal use stringfy
372
- * @param valA
373
- * @param valB
432
+ * 通过序列化实现深比较
433
+ * @param valA 比较值A
434
+ * @param valB 比较值B
374
435
  */
375
436
  export function deepEqual(valA: any, valB: any): boolean;
376
437
 
377
438
  /**
378
- * deep equal
439
+ * 快速深比较
440
+ * @param a 比较值A
441
+ * @param b 比较值B
379
442
  * support: Object/Array/String/Number/RegExp/
380
- * @param valA
381
- * @param valB
382
443
  */
383
444
  export function fastDeepEqual(a: any, b: any): boolean;
445
+
446
+ /**
447
+ * 判断是否在Node.js环境中
448
+ */
384
449
  export function isNode(): boolean;
385
450
 
386
451
  /**
@@ -390,62 +455,94 @@ export function isNode(): boolean;
390
455
  * @example
391
456
  * omit({ name: 'ilex', age: 16 }, ['age']); // { name: 'ilex' }
392
457
  */
393
- export function omit(obj: object, keys: string | Array<String>): any;
458
+ export function omit<T extends object, K extends keyof T>(
459
+ obj: T,
460
+ keys: K | K[]
461
+ ): Omit<T, K>;
394
462
 
395
463
  /**
396
464
  * 从指定的 obj 中获取 指定的key组成新的对象
397
- * @param obj
398
- * @param keys
465
+ * @param obj 目标对象
466
+ * @param keys 需要提取的键
399
467
  * @example
400
468
  * pick({ name: 'ilex', age: 16 }, ['age']); // { age: 16 }
401
469
  * pick({ name: 'ilex', age: 16 }, ['']); // {}
402
470
  * pick({ name: 'ilex', age: 16 }, ['you']); // {},如果指定对象中无指定的 key,则不拾取
403
471
  */
404
- export function pick(obj: Object | Function, keys: string | Array<String>): Object;
472
+ export function pick<T extends object, K extends keyof T>(
473
+ obj: T | Function,
474
+ keys: K | K[]
475
+ ): Partial<Pick<T, K>>;
476
+
405
477
  /**
406
478
  * 从指定的 obj 中获取 满足 judge(key, value) 组成新的对象
407
- *
408
- * @param obj
409
- * @param judge
479
+ * @param obj 目标对象
480
+ * @param judge 判断函数
410
481
  * @example
411
482
  * pickBy({ a: 1, b: 2, c: 'ray' }, (key, value) => typeof value === 'number')
412
483
  */
413
- export function pickBy(obj: Object | Function, judge: (key, value) => Boolean): Object;
484
+ export function pickBy<T extends object>(
485
+ obj: T | Function,
486
+ judge: (key: keyof T, value: T[keyof T]) => boolean
487
+ ): Partial<T>;
488
+
414
489
  /**
415
490
  * 将数据转化为json
416
- * @param data
491
+ * @param data 原始数据
417
492
  */
418
- export function parseJson(data: any): any;
493
+ export function parseJson(data: string): any;
419
494
 
420
495
  /**
421
- * 将object等 类型的数据转化为string
422
- * @param json
496
+ * 将object等类型的数据转化为string
497
+ * @param json 原始数据
423
498
  */
424
- export function stringify(json: any): any;
499
+ export function stringify(json: any): string;
425
500
 
501
+ /**
502
+ * 去除字符串两端空白
503
+ * @param str 目标字符串
504
+ */
426
505
  export function trim(str: string | null | undefined): string;
427
506
 
428
-
429
- export class objectPath {
507
+ export const objectPath: {
430
508
  /**
431
509
  * tests path existence
432
- * @param obj
433
- * @param path
510
+ * @param obj 目标对象
511
+ * @param path 属性路径
434
512
  * @example
435
513
  * objectPath.has(obj, "a.b"); // true
436
514
  * objectPath.has(obj, ["a","d"]); // false
437
515
  */
438
- has(obj: Object, path: number | string): boolean;
439
- ensureExists(obj: Object, path: number | string, value: any): boolean;
440
- set(obj: Object, path: number | string, value: any, doNotReplace: boolean): void;
441
- empty(obj: Object, path: number | string): void;
442
- push(obj: Object, path: number | string, values?: any): void;
443
- coalesce(obj: Object, paths: Array<Number|String>, defaultValue: any): void;
516
+ has(obj: object, path: number | string | (number | string)[]): boolean;
517
+
518
+ ensureExists(obj: object, path: number | string | (number | string)[], value: any): boolean;
519
+
520
+ set(
521
+ obj: object,
522
+ path: number | string | (number | string)[],
523
+ value: any,
524
+ doNotReplace?: boolean
525
+ ): void;
526
+
527
+ empty(obj: object, path: number | string | (number | string)[]): void;
528
+
529
+ push(
530
+ obj: object,
531
+ path: number | string | (number | string)[],
532
+ ...values: any[]
533
+ ): void;
534
+
535
+ coalesce(
536
+ obj: object,
537
+ paths: Array<number | string | (number | string)[]>,
538
+ defaultValue: any
539
+ ): any;
540
+
444
541
  /**
445
542
  * 获取指定路径节点
446
- * @param obj
447
- * @param path
448
- * @param defaultValue
543
+ * @param obj 目标对象
544
+ * @param path 属性路径
545
+ * @param defaultValue 默认值
449
546
  * @example
450
547
  * // bind object
451
548
  var model = objectPath({
@@ -458,72 +555,112 @@ export class objectPath {
458
555
  //now any method from above is supported directly w/o passing an object
459
556
  model.get("a.b"); //returns "d"
460
557
  */
461
- get(obj: Object, path: Number|String, defaultValue: any): any;
558
+ get(
559
+ obj: object,
560
+ path: number | string | (number | string)[],
561
+ defaultValue?: any
562
+ ): any;
563
+
462
564
  /**
463
565
  * 删除指定路径节点
464
- * @param obj
465
- * @param path
566
+ * @param obj 目标对象
567
+ * @param path 属性路径
466
568
  * @example
467
569
  * model.del("a.b"); // obj.a.b is now undefined
468
570
  */
469
- del(obj: Object, path: Number|String): string;
470
- create(options: Object): Function;
471
- withInheritedProps: Function;
571
+ del(obj: object, path: number | string | (number | string)[]): void;
572
+
573
+ /**
574
+ * 创建一个新的 objectPath
575
+ * @param options
576
+ */
577
+ create(options?: Record<string, any>): typeof objectPath;
578
+
579
+ /**
580
+ *includeInheritedProps 为 true 的 objectPath
581
+ */
582
+ withInheritedProps: typeof objectPath;
472
583
  }
473
584
 
474
585
  /**
475
- * 解析数据
476
- * @param text
477
- * @param dataObj
478
- * @param regexps 可选
479
- * @returns returns a new str
586
+ * 解析数据并替换模板中的占位符
587
+ * @param text 模板文本
588
+ * @param dataObj 数据对象
589
+ * @param regexps 匹配正则(可选)
590
+ * @returns 替换后的字符串
480
591
  * @example
481
592
  * demo: parseText('a/{b}/{c}/d',{a: 1, b:2}) 返回: 'a/1/2/d'
482
593
  * demo: parseText('a/b?name={name}&pwd={pwd}',{name: 'ilex', pwd:122}) 返回: 'a/b?name=ilex&pwd=123'
483
594
  */
484
- export function parseText(text: string, dataObj: object, regexps?: string | RegExp): string;
595
+ export function parseText(
596
+ text: string,
597
+ dataObj: Record<string, any>,
598
+ regexps?: string | RegExp
599
+ ): string;
600
+
601
+ /**
602
+ * 浅比较
603
+ * @param objA 比较对象A
604
+ * @param objB 比较对象B
605
+ */
606
+ export function shallowEqual(objA: any, objB: any): boolean;
485
607
 
486
- export function shallowEqual(objA, objB): boolean;
608
+ /**
609
+ * 加法运算(解决精度问题)
610
+ * @param arg1 加数
611
+ * @param arg2 被加数
612
+ */
613
+ export function addition(arg1: number, arg2: number): number;
487
614
 
615
+ /**
616
+ * 减法运算(解决精度问题)
617
+ * @param arg1 减数
618
+ * @param arg2 被减数
619
+ */
620
+ export function subtraction(arg1: number, arg2: number): number;
488
621
 
489
- export function addition(arg1, arg2): number;
490
- export function subtraction(arg1, arg2): number;
491
622
  /**
492
623
  * 小数乘法
493
624
  * @param arg1 被乘数(接受小数和整数)
494
625
  * @param arg2 乘数(接受小数和整数)
495
626
  * @param fix 乘积保留几位(接受正负整数以及0),默认值为 0
496
- * @returns {Number}
627
+ * @returns 乘积结果
497
628
  * @example
498
629
  * accMul(0.56, 100); // 56
499
630
  * accMul(0.5679, 100); // 57
500
631
  * accMul(0.5679, 100.2); // 57
501
- */
502
- export function accMul(arg1: Number, arg2: Number, fix?: Number): number;
632
+ */
633
+ export function accMul(arg1: number, arg2: number, fix?: number): number;
634
+
503
635
  /**
504
636
  * 小数除法
505
- * @param arg1 被乘数(接受小数和整数)
506
- * @param arg2 乘数(接受小数和整数)
637
+ * @param arg1 被除数
638
+ * @param arg2 除数
507
639
  * @param fix 除法保留几位(接受正负整数以及0),默认值为 0
508
- * @returns {Number}
640
+ * @returns 除法结果
509
641
  * @example
510
642
  * accDivide(56, 100); // 0.56
511
643
  * accDivide(5679, 100, 2); // 56.79
512
644
  * accDivide(5679, 100.2, 2); // 56.68
513
645
  */
514
- export function accDivide(arg1: Number, arg2: Number, fix?: Number): number;
646
+ export function accDivide(arg1: number, arg2: number, fix?: number): number;
515
647
 
516
648
  /**
517
649
  * 将数值格式化成金额形式
518
- *
519
650
  * @param num 数值(Number或者String)
520
- * @param precision 精度,默认不变. 传 null or undefined
651
+ * @param precision 精度,默认不变
521
652
  * @param separator 分隔符,默认为逗号
522
653
  * @param sign 前缀,默认为$
523
654
  * @param unit 单位,默认为空
524
655
  * @return 金额格式的字符串,如'1,234,567',默认返回 ''
525
656
  */
526
- export function coinFormat(num: number, precision: number, separator: string, sign: string, unit: string): string | '';
657
+ export function coinFormat(
658
+ num: number | string,
659
+ precision?: number,
660
+ separator?: string,
661
+ sign?: string,
662
+ unit?: string
663
+ ): string;
527
664
 
528
665
  // --- 日历工具类
529
666
  /**
@@ -608,7 +745,12 @@ interface DateHelper {
608
745
  * @param firstDayOfWeek 一周的第一天(0表示周日,默认0)
609
746
  * @return {number} 周数
610
747
  */
611
- getMonthWeek(year: number | string, month: number | string, date: number | string, firstDayOfWeek?: number): number;
748
+ getMonthWeek(
749
+ year: number | string,
750
+ month: number | string,
751
+ date: number | string,
752
+ firstDayOfWeek?: number
753
+ ): number;
612
754
 
613
755
  /**
614
756
  * 获取指定日期在当年的周数
@@ -618,7 +760,12 @@ interface DateHelper {
618
760
  * @param firstDayOfWeek 一周的第一天(0表示周日,默认0)
619
761
  * @return {number} 周数
620
762
  */
621
- getYearWeek(year: number | string, month: number | string, date: number | string, firstDayOfWeek?: number): number;
763
+ getYearWeek(
764
+ year: number | string,
765
+ month: number | string,
766
+ date: number | string,
767
+ firstDayOfWeek?: number
768
+ ): number;
622
769
 
623
770
  /**
624
771
  * 获取指定日期所在周的起止日期
@@ -628,7 +775,12 @@ interface DateHelper {
628
775
  * @param firstDayOfWeek 一周的第一天(0表示周日,默认0)
629
776
  * @return {[string, string]} 周起始日期和结束日期组成的数组
630
777
  */
631
- getWeekDate(year: number | string, month: number | string, date: number | string, firstDayOfWeek?: number): [string, string];
778
+ getWeekDate(
779
+ year: number | string,
780
+ month: number | string,
781
+ date: number | string,
782
+ firstDayOfWeek?: number
783
+ ): [string, string];
632
784
 
633
785
  /**
634
786
  * 格式化日期结果
@@ -674,7 +826,11 @@ interface PanelDate {
674
826
  * @param month 月
675
827
  * @returns [年, 两位数字的月, 该月天数]
676
828
  */
677
- declare function getCurrMonthData(type: string, year: number, month: number): [number, string, number];
829
+ declare function getCurrMonthData(
830
+ type: string,
831
+ year: number,
832
+ month: number
833
+ ): [number, string, number];
678
834
 
679
835
  /**
680
836
  * 获取日期状态
@@ -683,7 +839,11 @@ declare function getCurrMonthData(type: string, year: number, month: number): [n
683
839
  * @param month 月
684
840
  * @returns 日期状态数组
685
841
  */
686
- declare function getDaysStatus(type: string, year: number, month: number): DayStatus[];
842
+ declare function getDaysStatus(
843
+ type: string,
844
+ year: number,
845
+ month: number
846
+ ): DayStatus[];
687
847
 
688
848
  /**
689
849
  * 获取上一个月的最后一周天数,填充当月空白
@@ -693,7 +853,12 @@ declare function getDaysStatus(type: string, year: number, month: number): DaySt
693
853
  * @param firstDayOfWeek 一周的第一天(0表示周日)
694
854
  * @returns 上月填充日期数组
695
855
  */
696
- declare function getPreMonthDates(type: string, year: number, month: number, firstDayOfWeek: number): DayStatus[];
856
+ declare function getPreMonthDates(
857
+ type: string,
858
+ year: number,
859
+ month: number,
860
+ firstDayOfWeek: number
861
+ ): DayStatus[];
697
862
 
698
863
  /**
699
864
  * 将日期对象转换为年、月、日结构
@@ -716,7 +881,11 @@ declare function convertDayToDate(day: DayObject | null): Date | null;
716
881
  * @param firstDayOfWeek 一周的第一天(0表示周日)
717
882
  * @returns 上月面板日期数组
718
883
  */
719
- declare function getPrevMonthDays(year: number, month: number, firstDayOfWeek: number): PanelDate[];
884
+ declare function getPrevMonthDays(
885
+ year: number,
886
+ month: number,
887
+ firstDayOfWeek: number
888
+ ): PanelDate[];
720
889
 
721
890
  /**
722
891
  * 获取当前月的日期数据
@@ -724,7 +893,10 @@ declare function getPrevMonthDays(year: number, month: number, firstDayOfWeek: n
724
893
  * @param month 月
725
894
  * @returns 当月面板日期数组
726
895
  */
727
- declare function getCurrentMonthDays(year: number, month: number): PanelDate[];
896
+ declare function getCurrentMonthDays(
897
+ year: number,
898
+ month: number
899
+ ): PanelDate[];
728
900
 
729
901
  /**
730
902
  * 根据日期获取当前周的起始日期
@@ -732,7 +904,17 @@ declare function getCurrentMonthDays(year: number, month: number): PanelDate[];
732
904
  * @param firstDayOfWeek 一周的第一天(0表示周日)
733
905
  * @returns [周起始日期, 周结束日期]
734
906
  */
735
- declare function getCurrentWeekDays(day: DayObject, firstDayOfWeek: number): [DayObject, DayObject];
907
+ declare function getCurrentWeekDays(
908
+ day: DayObject,
909
+ firstDayOfWeek: number
910
+ ): [DayObject, DayObject];
911
+
912
+ /**
913
+ * 检测传入的日期是 今天
914
+ * @param dayObj PanelDate 对象
915
+ * @returns boolean
916
+ */
917
+ declare function checkIsToday(dayObj: PanelDate | null): boolean;
736
918
 
737
919
  /**
738
920
  * 日历工具类
@@ -747,86 +929,98 @@ declare const CalendarUtils: {
747
929
  getPrevMonthDays: typeof getPrevMonthDays;
748
930
  getCurrentMonthDays: typeof getCurrentMonthDays;
749
931
  getCurrentWeekDays: typeof getCurrentWeekDays;
932
+ checkIsToday: typeof checkIsToday;
750
933
  };
751
934
 
752
935
  export { CalendarUtils };
753
936
  export type { DayObject, DayStatus, PanelDate, DateHelper };
754
937
 
755
938
  /**
756
- * dateTime
939
+ * 日期时间工具
757
940
  */
758
941
  declare namespace dateTime {
759
942
  /**
760
943
  * 将日期时间戳格式化成指定格式
761
- * @param date
762
- * @param fmt 默认 yyyy-MM-dd HH:mm:ss
944
+ * @param date 日期对象或时间戳
945
+ * @param fmt 格式化模板,默认 yyyy-MM-dd HH:mm:ss
763
946
  * @example
764
947
  * formatDate(); // 2016-09-02 13:17:13
765
948
  * formatDate(new Date(), 'yyyy-MM-dd'); // 2016-09-02
766
949
  * formatDate(new Date(), 'yyyy-MM-dd 第q季度 www HH:mm:ss:SSS');// 2016-09-02 第3季度 星期五 13:19:15:792
767
950
  * formatDate(1472793615764); // 2016-09-02 13:20:15
768
951
  */
769
- export function formatDate(date: Date | number, fmt: string): string;
952
+ export function formatDate(date?: Date | number, fmt?: string): string;
953
+
770
954
  /**
771
- * 时间戳转时间,这是另一种方式 2018-07-09 11:04:51
772
- *
773
- * @param date
774
- * @returns string
955
+ * 时间戳转时间字符串
956
+ * @param date 日期对象或时间戳
957
+ * @returns 格式化后的时间字符串
958
+ * @example
959
+ * timetrans(1472793615764); // 2016-09-02 13:20:15
775
960
  */
776
961
  export function timetrans(date: Date | number): string;
962
+
777
963
  /**
778
- *将一个日期格式化成友好格式,比如,1分钟以内的返回“刚刚”,当天的返回时分,当年的返回月日,否则,返回年月日
779
- *
780
- * @param date
781
- * @returns string
964
+ * 将一个日期格式化成友好格式
965
+ * @param date 日期对象或时间戳
966
+ * @returns 友好格式的时间字符串
967
+ * @example
968
+ * formatDateToFriendly(new Date()); // "刚刚" 或 "1分钟前" 等
782
969
  */
783
970
  export function formatDateToFriendly(date: Date | number): string;
971
+
784
972
  /**
785
973
  * 将一段时长转换成友好格式
786
- * @param time
787
- * @returns string
974
+ * @param time 时间戳(毫秒)
975
+ * @returns 友好格式的时长字符串
788
976
  * @example
789
- * var str = friendlyDate('1311111119999'); // 6年前(括号里的字符串值为1970年距字符串值表示的时间的毫秒数)
790
- * var str2 = friendlyDate('1503190042273'); // 1天前
977
+ * friendlyDate('1503190042273'); // 1天前
791
978
  */
792
979
  export function friendlyDate(time: number): string;
980
+
793
981
  /**
794
- * 将一段时长转换成友好格式
795
- * @param second
796
- * @returns string
982
+ * 将秒数转换成友好格式的时长
983
+ * @param second 秒数
984
+ * @returns 友好格式的时长字符串
797
985
  * @example
986
+ * formatDurationToFriendly(147); // "2分27秒"
798
987
  * 147->“2分27秒”
799
988
  * 1581->“26分21秒”
800
989
  * 15818->“4小时24分”
801
990
  */
802
991
  export function formatDurationToFriendly(second: number): string;
992
+
803
993
  /**
804
- * 将时间转换成MM:SS形式
805
- * @param second
994
+ * 将秒数转换成MM:SS形式
995
+ * @param second 秒数
806
996
  */
807
997
  export function formatTimeToFriendly(second: number): string;
998
+
808
999
  /**
809
- * 判断某一年是否是闰年 可以是一个date类型,也可以是一个int类型的年份,不传默认当前时间
810
- * @param year
1000
+ * 判断某一年是否是闰年
1001
+ * @param year 年份或日期对象
811
1002
  */
812
- export function isLeapYear(year: number): string;
1003
+ export function isLeapYear(year: number | Date): boolean;
1004
+
813
1005
  /**
814
- * 获取某一年某一月的总天数,没有任何参数时获取当前月份的
815
- * @param date
816
- * @param month
1006
+ * 获取某一年某一月的总天数
1007
+ * @param date 年份或日期对象
1008
+ * @param month 月份(可选)
817
1009
  * @example
818
- * 方式一:$.getMonthDays();
819
- * 方式二:$.getMonthDays(new Date());
820
- * 方式三:$.getMonthDays(2013, 12);
1010
+ * getMonthDays(); // 当前月天数
1011
+ * getMonthDays(new Date());
1012
+ * getMonthDays(2013, 12); // 2013年12月天数
821
1013
  */
822
- export function getMonthDays(date: Date | number, month: number): string;
1014
+ export function getMonthDays(date?: Date | number, month?: number): number;
1015
+
823
1016
  /**
824
1017
  * 计算两个日期之间的天数,用的是比较毫秒数的方法
825
1018
  * 传进来的日期要么是Date类型,要么是yyyy-MM-dd格式的字符串日期
826
1019
  * @param date1 日期一
827
1020
  * @param date2 日期二
828
1021
  */
829
- export function countDays(date1: Date | number, date2: Date | number): string;
1022
+ export function countDays(date1: Date | string, date2: Date | string): number;
1023
+
830
1024
  /**
831
1025
  * 将字符串解析成日期
832
1026
  * @param str 输入的日期字符串,如'2014-09-13'
@@ -836,93 +1030,167 @@ declare namespace dateTime {
836
1030
  * parseDate('2016-08-11'); // Thu Aug 11 2016 00:00:00 GMT+0800
837
1031
  * parseDate('2016-08-11 13:28:43', 'yyyy-MM-dd HH:mm:ss') // Thu Aug 11 2016 13:28:43 GMT+0800
838
1032
  */
839
- export function parseDate(str: string, fmt: string): string;
1033
+ export function parseDate(str: string, fmt?: string): Date;
1034
+
840
1035
  /**
841
1036
  * 到某一个时间的倒计时
842
- * @param endTime
1037
+ * @param endTime 结束时间
1038
+ * @returns 倒计时对象
843
1039
  * @example
844
- * getEndTime('2017/7/22 16:0:0') // result:"剩余时间6 2小时 28 分钟20 秒"
1040
+ * getEndTime('2017/7/22 16:0:0') // {d:6, h:2, m:28, s:20}
845
1041
  */
846
- export function getEndTime(endTime: string | number): object;
1042
+ export function getEndTime(endTime: string | number): {
1043
+ days: number;
1044
+ hours: number;
1045
+ minutes: number;
1046
+ seconds: number;
1047
+ [key: string]: number;
1048
+ };
1049
+
847
1050
  /**
848
- * 到某一个时间的倒计时
849
- * @param endTime
1051
+ * 到某一个时间的倒计时字符串
1052
+ * @param endTime 结束时间
1053
+ * @returns 倒计时字符串
850
1054
  * @example
851
1055
  * getEndTimeStr('2017/7/22 16:0:0') // "剩余时间6天 2小时 28 分钟20 秒"
852
1056
  */
853
1057
  export function getEndTimeStr(endTime: string | number): string;
1058
+
854
1059
  /**
855
1060
  * 获取某月有多少天
856
- * @param time
1061
+ * @param time 日期字符串或时间戳
857
1062
  */
858
- export function getMonthOfDay(time: string | number): string;
1063
+ export function getMonthOfDay(time: string | number): number;
1064
+
859
1065
  /**
860
1066
  * 获取某年有多少天
861
- * @param time
1067
+ * @param time 日期字符串或时间戳
862
1068
  */
863
- export function getYearOfDay(time: string | number): string;
1069
+ export function getYearOfDay(time: string | number): number;
1070
+
864
1071
  /**
865
1072
  * 获取某年的第一天
866
- * @param time
1073
+ * @param time 日期字符串或时间戳
867
1074
  */
868
1075
  export function getFirstDayOfYear(time: string | number): string;
1076
+
869
1077
  /**
870
1078
  * 获取某年最后一天
871
- * @param time
1079
+ * @param time 日期字符串或时间戳
872
1080
  */
873
1081
  export function getLastDayOfYear(time: string | number): string;
1082
+
874
1083
  /**
875
1084
  * 获取某个日期是当年中的第几天
876
- * @param time
1085
+ * @param time 日期字符串或时间戳
877
1086
  */
878
- export function getDayOfYear(time: string | number): string;
1087
+ export function getDayOfYear(time: string | number): number;
1088
+
879
1089
  /**
880
1090
  * 获取某个日期在这一年的第几周
881
- * @param time
1091
+ * @param time 日期字符串或时间戳
882
1092
  */
883
- export function getDayOfYearWeek(time: string | number): string;
1093
+ export function getDayOfYearWeek(time: string | number): number;
1094
+
884
1095
  /**
885
1096
  * 获取两个时间段差多久
886
- * @param time
887
- * @param fmt
1097
+ * @param str 时间字符串
1098
+ * @param fmt 格式模板
888
1099
  */
889
1100
  export function timeFn(str: string, fmt: string): string;
890
1101
  }
891
1102
 
892
1103
  /**
893
- * amostool
1104
+ * amostool 命名空间
894
1105
  */
895
1106
  declare namespace amostool {}
896
1107
 
897
1108
  /**
898
- * amostool utils
1109
+ * 通用工具函数命名空间
899
1110
  */
900
1111
  declare namespace utils {
901
- export function isString(value: any): boolean;
902
- export function isArray(value: any): boolean;
903
- export function isObject(value: any): boolean;
904
- export function isBoolean(value: any): boolean;
905
- export function isFunction(value: any): boolean;
906
1112
  /**
907
- * 判断 number,采用正则表达式进行判断
1113
+ * 判断是否为字符串
1114
+ * @param value 待检测值
1115
+ */
1116
+ export function isString(value: any): value is string;
1117
+
1118
+ /**
1119
+ * 判断是否为数组
1120
+ * @param value 待检测值
1121
+ */
1122
+ export function isArray(value: any): value is any[];
1123
+
1124
+ /**
1125
+ * 判断是否为对象(排除数组、null)
1126
+ * @param value 待检测值
1127
+ */
1128
+ export function isObject(value: any): value is object;
1129
+
1130
+ /**
1131
+ * 判断是否为布尔值
1132
+ * @param value 待检测值
1133
+ */
1134
+ export function isBoolean(value: any): value is boolean;
1135
+
1136
+ /**
1137
+ * 判断是否为函数
1138
+ * @param value 待检测值
1139
+ */
1140
+ export function isFunction(value: any): value is Function;
1141
+
1142
+ /**
1143
+ * 判断是否为数字,采用正则表达式进行判断
1144
+ * @param value 待检测值
908
1145
  * 正则表达式:/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/
909
- * @param {*} value
910
1146
  */
911
- export function isNumber(value: any): boolean;
1147
+ export function isNumber(value: any): value is number;
1148
+
912
1149
  /**
913
- * 支持 string 类型的科学计数 number 校验
914
- * @param value
1150
+ * 支持科学计数法的数字校验
1151
+ * @param value 待检测值
915
1152
  */
916
1153
  export function isENumber(value: any): boolean;
1154
+
1155
+ /**
1156
+ * 判断是否为浮点数
1157
+ * @param value 待检测值
1158
+ */
917
1159
  export function isFloat(value: any): boolean;
1160
+
1161
+ /**
1162
+ * 判断是否为透明度值(0-1之间)
1163
+ * @param value 待检测值
1164
+ */
918
1165
  export function isOpacity(value: any): boolean;
1166
+
1167
+ /**
1168
+ * 转换为浮点数
1169
+ * @param value 待转换值
1170
+ */
919
1171
  export function toFloat(value: any): number;
920
- export function isNull(value: any): boolean;
921
- export function isUndefined(value: any): boolean;
922
- export function isNil(value: any): boolean;
1172
+
923
1173
  /**
924
- * 空(null、undefined、'')
925
- * @param value
1174
+ * 判断是否为null
1175
+ * @param value 待检测值
1176
+ */
1177
+ export function isNull(value: any): value is null;
1178
+
1179
+ /**
1180
+ * 判断是否为undefined
1181
+ * @param value 待检测值
1182
+ */
1183
+ export function isUndefined(value: any): value is undefined;
1184
+
1185
+ /**
1186
+ * 判断是否为null或undefined
1187
+ * @param value 待检测值
1188
+ */
1189
+ export function isNil(value: any): value is null | undefined;
1190
+
1191
+ /**
1192
+ * 判断是否为空值(null、undefined、'')
1193
+ * @param value 待检测值
926
1194
  * @example
927
1195
  * isBlank(); // true
928
1196
  * isBlank(void 0); // true
@@ -935,22 +1203,67 @@ declare namespace utils {
935
1203
  * isBlank(true); // false
936
1204
  */
937
1205
  export function isBlank(value: any): boolean;
938
- export function has(obj: object | Array<any>, path: Array<any> | string): boolean;
1206
+
1207
+ /**
1208
+ * 检查对象是否存在指定路径
1209
+ * @param obj 目标对象
1210
+ * @param path 属性路径
1211
+ */
1212
+ export function has(
1213
+ obj: object | any[],
1214
+ path: string | number | (string | number)[]
1215
+ ): boolean;
1216
+
1217
+ /**
1218
+ * 获取对象的所有值
1219
+ * @param obj 目标对象
1220
+ */
1221
+ export function values<T extends object>(obj: T): Array<T[keyof T]>;
1222
+
939
1223
  /**
940
- * Retrieve the values of an object's properties.
941
- * @param obj
1224
+ * 空函数
942
1225
  */
943
- export function values(obj: object): Array<any>;
944
1226
  export function noop(): void;
1227
+
1228
+ /**
1229
+ * 判断是否为空(空数组、空对象、空字符串等)
1230
+ * @param value 待检测值
1231
+ */
945
1232
  export function isEmpty(value: any): boolean;
1233
+
1234
+ /**
1235
+ * 判断是否为空对象
1236
+ * @param value 待检测值
1237
+ */
946
1238
  export function isEmptyObject(value: any): boolean;
1239
+
1240
+ /**
1241
+ * 判断是否为DOM元素
1242
+ * @param value 待检测值
1243
+ */
947
1244
  export function isElement(value: any): boolean;
948
- export function isHTMLElement(value: any): boolean;
1245
+
1246
+ /**
1247
+ * 判断是否为HTML元素
1248
+ * @param value 待检测值
1249
+ */
1250
+ export function isHTMLElement(value: any): value is HTMLElement;
1251
+
1252
+ /**
1253
+ * 判断是否为SVG元素
1254
+ * @param value 待检测值
1255
+ */
949
1256
  export function isSVGElement(value: any): boolean;
1257
+
1258
+ /**
1259
+ * 判断是否为DOM节点
1260
+ * @param value 待检测值
1261
+ */
950
1262
  export function isDom(value: any): boolean;
1263
+
951
1264
  /**
952
- * check value is url
953
- * @param value
1265
+ * 检查是否为合法URL
1266
+ * @param value 待检测值
954
1267
  * @example
955
1268
  * isUrl('http://www.baidu.com') // true
956
1269
  * isUrl('https://www.baidu.com') // true
@@ -962,49 +1275,76 @@ declare namespace utils {
962
1275
  * isUrl('http://localhost:8080/aaa') // true
963
1276
  */
964
1277
  export function isUrl(value: string): boolean;
1278
+
1279
+ /**
1280
+ * 判断是否为内置对象
1281
+ * @param value 待检测值
1282
+ */
965
1283
  export function isBuiltInObject(value: any): boolean;
1284
+
1285
+ /**
1286
+ * null值转换为默认值
1287
+ * @param str 待转换值
1288
+ */
966
1289
  export function null2default(str: any): any;
1290
+
967
1291
  /**
968
1292
  * 判断对象是不是Json
969
1293
  * Object 对象,typeof === object && toString === '[object Object]'
970
- * @param obj
971
- * @returns boolean true 是 false不是
1294
+ * @param obj 待检测值
972
1295
  */
973
1296
  export function isJson(obj: any): boolean;
974
1297
 
975
- export function isSymbol(obj: any): boolean;
976
- export function isNullOrUndefined(obj: any): boolean;
977
- export function isDate(obj: any): boolean;
1298
+ /**
1299
+ * 判断是否为Symbol类型
1300
+ * @param obj 待检测值
1301
+ */
1302
+ export function isSymbol(obj: any): obj is symbol;
1303
+
1304
+ /**
1305
+ * 判断是否为null或undefined
1306
+ * @param obj 待检测值
1307
+ */
1308
+ export function isNullOrUndefined(obj: any): obj is null | undefined;
1309
+
1310
+ /**
1311
+ * 判断是否为Date对象
1312
+ * @param obj 待检测值
1313
+ */
1314
+ export function isDate(obj: any): obj is Date;
978
1315
 
979
1316
  /**
980
1317
  * 判断string能否被转成json
981
1318
  * 参数 str 如果不是 string 则直接返回 false
982
- * @param str
983
- * @returns boolean
1319
+ * @param value 待检测值
984
1320
  */
985
1321
  export function stringIsJson(value: any): boolean;
1322
+
986
1323
  /**
987
1324
  * 判断key是否在object内
988
1325
  * (采用 in 判断,继承属性均会判断)
989
- * @param keys
990
- * @param obj 如果 obj 是 null or undefined, 或者 非 object,则直接 返回 false
1326
+ * @param keys 键名或键名数组
1327
+ * @param obj 目标对象 如果 obj 是 null or undefined, 或者 非 object,则直接 返回 false
991
1328
  */
992
1329
  export function isKeyInObject(keys: string | string[], obj: any): boolean;
1330
+
993
1331
  /**
994
1332
  * 判断key是否在object内
995
1333
  * (采用 hasOwnProperty 判断,继承属性不会判断)
996
- * @param keys
997
- * @param obj 如果 obj 是 null or undefined, 或者 非 object,则直接 返回 false
1334
+ * @param keys 键名或键名数组
1335
+ * @param obj 目标对象 如果 obj 是 null or undefined, 或者 非 object,则直接 返回 false
998
1336
  */
999
1337
  export function isOwnKeyInObject(keys: string | string[], obj: any): boolean;
1338
+
1000
1339
  /**
1001
- * 判断是否是 promise
1002
- * @param value
1340
+ * 判断是否为Promise对象
1341
+ * @param value 待检测值
1003
1342
  */
1004
- export function isPromise(value: any): boolean;
1343
+ export function isPromise(value: any): value is Promise<any>;
1344
+
1005
1345
  /**
1006
- * 判断是否是正则对象
1007
- * @param value
1346
+ * 判断是否为正则表达式
1347
+ * @param value 待检测值
1008
1348
  * @example
1009
1349
  * isRegExp(undefined); // false
1010
1350
  * isRegExp(''); // false
@@ -1015,10 +1355,17 @@ declare namespace utils {
1015
1355
  * isRegExp(new RegExp('aa')); // true
1016
1356
  * isRegExp({ test(){} }); // false
1017
1357
  */
1018
- export function isRegExp(value: any): boolean;
1358
+ export function isRegExp(value: any): value is RegExp;
1359
+
1360
+ /**
1361
+ * 简单对象比较
1362
+ * @param objA 比较对象A
1363
+ * @param objB 比较对象B
1364
+ */
1019
1365
  export function simpleEqual(objA: object, objB: object): boolean;
1366
+
1020
1367
  /**
1021
- * 判断是一个 image 的路径
1368
+ * 判断是否为图片路径
1022
1369
  * `/a/a/a.png|jpe?g|gif...`
1023
1370
  * `http://a.b/a.png|jpe?g|gif...`
1024
1371
  * `data:image/png|jpe?g|gif;base64,`
@@ -1028,37 +1375,43 @@ declare namespace utils {
1028
1375
  * isImageSrc('http://a.b/a.png'); // true
1029
1376
  * isImageSrc('data:image/png|jpe?g|gif;base64,'); // true
1030
1377
  */
1031
- export function isImageSrc(url: String): boolean;
1378
+ export function isImageSrc(url: string): boolean;
1379
+
1032
1380
  /**
1033
- * 判断图片是 gif
1034
- * @param url 支持的格式
1381
+ * 判断是否为GIF图片
1382
+ * @param url 待检测URL
1035
1383
  * @example
1036
1384
  * isGIF('a.gif'); // true
1037
1385
  * isGIF('data:image/;base64,'); // true
1038
1386
  */
1039
- export function isGIF(url: String): boolean;
1387
+ export function isGIF(url: string): boolean;
1388
+
1040
1389
  /**
1041
1390
  * 将数字部分内容转化为 *
1042
- * @param number 目标 Number
1391
+ * @param number 目标数字
1043
1392
  * @param start 起始位置 默认3
1044
1393
  * @param len 转换位数 默认4
1045
1394
  * @param sign 替换的字符 默认*
1046
1395
  */
1047
- export function encodeNumber(number: Number, start?: number, len?: number, sign?: string): String;
1396
+ export function encodeNumber(
1397
+ number: number,
1398
+ start?: number,
1399
+ len?: number,
1400
+ sign?: string
1401
+ ): string;
1048
1402
 
1049
1403
  /**
1050
- * 获取扩展名
1404
+ * 获取文件扩展名
1051
1405
  *
1052
1406
  * 可快速使用 `filePath.split('.').pop();` 获取扩展名
1053
- * @param filePath
1054
- * @return {String} ext
1407
+ * @param filePath 文件路径
1055
1408
  * @example
1056
1409
  * getFileExtension('a.png'); // png
1057
1410
  * getFileExtension('a/a/a.png'); // png
1058
1411
  * getFileExtension('a.a.a.png.jpg'); // jpg
1059
1412
  * getFileExtension('a'); // ''
1060
1413
  */
1061
- export function getFileExtension(filePath: string): String;
1414
+ export function getFileExtension(filePath: string): string;
1062
1415
 
1063
1416
  /**
1064
1417
  * 将指定 size 中的数据,转化为 byte
@@ -1066,7 +1419,6 @@ declare namespace utils {
1066
1419
  * - 默认去除内部所有空格, 1024 MB -> 1024mb
1067
1420
  * - 无单位或者 number 类型,将直接转化为 number值,默认当 byte 处理
1068
1421
  * @param size 带有单位的 size,不带单位时,直接返回该值
1069
- * @returns byte
1070
1422
  * @example
1071
1423
  * fileSizeToByte('1kb'); // 1024
1072
1424
  * fileSizeToByte('1mb'); // 1048576
@@ -1076,15 +1428,33 @@ declare namespace utils {
1076
1428
  * fileSizeToByte('123'); // 123
1077
1429
  * fileSizeToByte(123); // 123
1078
1430
  */
1079
- export function fileSizeToByte(size: string): String;
1431
+ export function fileSizeToByte(size: string | number): number;
1432
+
1433
+ /**
1434
+ * 数组some方法兼容实现
1435
+ * @param arr 目标数组
1436
+ * @param fun 回调函数
1437
+ */
1438
+ export function some(
1439
+ arr: any[],
1440
+ fun: (value: any, index: number, array: any[]) => boolean,
1441
+ thisArg?: any
1442
+ ): boolean;
1080
1443
 
1081
- export function some(arr: Array<any>, fun: Function /*, thisArg */): boolean;
1082
- export function every(arr: Array<any>, callbackfn: Function, thisArg): boolean;
1083
- export function reduce(arr: Array<any>, callback: Function /*, initialValue*/);
1084
- export function parse2string(obj: object | Array<any>): string;
1085
- export function parse2object(str: string): object | Array<any>;
1086
- export function dataToArray(vars: any): Array<any>;
1087
1444
  /**
1445
+ * 数组every方法兼容实现
1446
+ * @param arr 目标数组
1447
+ * @param callbackfn 回调函数
1448
+ * @param thisArg this指向
1449
+ */
1450
+ export function every(
1451
+ arr: any[],
1452
+ callbackfn: (value: any, index: number, array: any[]) => boolean,
1453
+ thisArg?: any
1454
+ ): boolean;
1455
+
1456
+ /**
1457
+ * 数组reduce方法兼容实现
1088
1458
  * Those data types can be cloned:
1089
1459
  * Plain object, Array, TypedArray, number, string, null, undefined.
1090
1460
  * Those data types will be assgined using the orginal data:
@@ -1097,35 +1467,85 @@ declare namespace utils {
1097
1467
  * (There might be a large number of date in `series.data`).
1098
1468
  * So date should not be modified in and out of echarts.
1099
1469
  *
1100
- * @param source
1101
- * @return new
1470
+ * @param arr 目标数组
1471
+ * @param callback 回调函数
1472
+ * @param initialValue 初始值
1102
1473
  */
1103
- export function clone(source: any): object | Array<any>;
1474
+ export function reduce<T, U = T>(
1475
+ arr: T[],
1476
+ callback: (
1477
+ accumulator: U,
1478
+ currentValue: T,
1479
+ currentIndex: number,
1480
+ array: T[]
1481
+ ) => U,
1482
+ initialValue?: U
1483
+ ): U;
1484
+
1104
1485
  /**
1105
- * @param target
1106
- * @param source
1107
- * @param [overwrite=false]
1108
- * @return target
1486
+ * 转换为字符串
1487
+ * @param obj 目标对象/数组
1109
1488
  */
1110
- export function merge(target: object | Array<any>, source: object | Array<any>, overwrite?: boolean): object | Array<any>;
1489
+ export function parse2string(obj: object | any[]): string;
1490
+
1111
1491
  /**
1112
- * @param targetAndSources The first item is target, and the rests are source.
1113
- * @param [overwrite=false]
1114
- * @return target
1492
+ * 解析为对象/数组
1493
+ * @param str JSON字符串
1115
1494
  */
1116
- export function mergeAll(targetAndSources: Array<any>, overwrite?: boolean): object | Array<any>;
1495
+ export function parse2object(str: string): object | any[];
1496
+
1117
1497
  /**
1498
+ * 转换为数组
1499
+ * @param vars 目标值
1500
+ */
1501
+ export function dataToArray(vars: any): any[];
1502
+
1503
+ /**
1504
+ * 克隆对象/数组
1505
+ * @param source 源对象
1506
+ */
1507
+ export function clone<T>(source: T): T;
1508
+
1509
+ /**
1510
+ * 合并对象
1511
+ * @param target 目标对象
1512
+ * @param source 源对象
1513
+ * @param overwrite 是否覆盖已有属性
1514
+ */
1515
+ export function merge<T extends object>(
1516
+ target: T,
1517
+ source: Partial<T>,
1518
+ overwrite?: boolean
1519
+ ): T;
1520
+
1521
+ /**
1522
+ * 合并多个对象
1523
+ * @param targetAndSources 目标对象和源对象数组 he first item is target, and the rests are source.
1524
+ * @param overwrite 是否覆盖已有属性
1525
+ */
1526
+ export function mergeAll<T extends object>(
1527
+ targetAndSources: [T, ...Partial<T>[]],
1528
+ overwrite?: boolean
1529
+ ): T;
1530
+
1531
+ /**
1532
+ * 比较子对象属性是否相等
1533
+ *
1118
1534
  * 比较 objTarget 中的所有属性值,是否在 objSource 中相等
1119
- * @param objSource
1120
- * @param objTarget
1535
+ * @param objSource 源对象
1536
+ * @param objTarget 目标对象
1121
1537
  */
1122
- export function subObjectEqual(objSource: {}, objTarget: {}): Boolean;
1538
+ export function subObjectEqual(
1539
+ objSource: Record<string, any>,
1540
+ objTarget: Record<string, any>
1541
+ ): boolean;
1542
+
1123
1543
  /**
1124
- * 校验给定的 string 是否是 文件名
1125
- *
1544
+ * 校验文件名合法性
1545
+ *
1126
1546
  * 校验中使用的正则表达式: `/[\\/:\*\?"<>\|]/g`
1127
- * @param str
1128
- * @param maxLen
1547
+ * @param str 文件名
1548
+ * @param maxLen 最大长度,默认259
1129
1549
  * @example
1130
1550
  * checkFileName('example.txt'); // true
1131
1551
  * checkFileName('con\\example.txt'); // false
@@ -1135,6 +1555,6 @@ declare namespace utils {
1135
1555
  * checkFileName('example.txt.'); // true
1136
1556
  * checkFileName('example..............txt'); // true
1137
1557
  */
1138
- export function checkFileName(str: String | Number, maxLen?: 259): Boolean;
1558
+ export function checkFileName(str: string | number, maxLen?: number): boolean;
1139
1559
  }
1140
1560