amos-apptool 1.0.0

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -0
  3. package/apis/objectPath.md +129 -0
  4. package/index.d.ts +861 -0
  5. package/lib/_clone.js +79 -0
  6. package/lib/_deepCopy.js +30 -0
  7. package/lib/_deepEqual.js +13 -0
  8. package/lib/_fastDeepEqual.js +38 -0
  9. package/lib/_forOwn.js +17 -0
  10. package/lib/_isnode.js +7 -0
  11. package/lib/_omit.js +19 -0
  12. package/lib/_parseJson.js +17 -0
  13. package/lib/_pick.js +20 -0
  14. package/lib/_pickBy.js +19 -0
  15. package/lib/_queue.js +72 -0
  16. package/lib/_shallowCopy.js +63 -0
  17. package/lib/_stringify.js +22 -0
  18. package/lib/_trim.js +15 -0
  19. package/lib/_typeOfList.js +29 -0
  20. package/lib/_uuids.js +56 -0
  21. package/lib/encrypt/_base64.js +39 -0
  22. package/lib/encrypt/_md5.js +130 -0
  23. package/lib/encrypt/des.js +539 -0
  24. package/lib/index.js +251 -0
  25. package/lib/math/_keyColor.js +158 -0
  26. package/lib/math/addition.js +25 -0
  27. package/lib/math/amountCase.js +18 -0
  28. package/lib/math/coinFormat.js +15 -0
  29. package/lib/math/colorUtil.js +261 -0
  30. package/lib/math/dateTime.js +154 -0
  31. package/lib/math/divide.js +21 -0
  32. package/lib/math/mul.js +29 -0
  33. package/lib/math/pwdStrength.js +11 -0
  34. package/lib/math/randomColor.js +31 -0
  35. package/lib/math/subtraction.js +25 -0
  36. package/lib/merged.js +16 -0
  37. package/lib/objectPath.js +126 -0
  38. package/lib/parseText.js +15 -0
  39. package/lib/pwdPolicy.js +38 -0
  40. package/lib/random.js +33 -0
  41. package/lib/shallowEqual.js +30 -0
  42. package/lib/strUtils.js +90 -0
  43. package/lib/url/encodeUrl.js +14 -0
  44. package/lib/url/restfulUrl.js +15 -0
  45. package/lib/utils.js +341 -0
  46. package/package.json +38 -0
package/index.d.ts ADDED
@@ -0,0 +1,861 @@
1
+ /// <reference types="node" />
2
+
3
+ export type RGBA = {
4
+ r: string | number;
5
+ g: string | number;
6
+ b: string | number;
7
+ a: string | number;
8
+ };
9
+
10
+ export class Base64 {
11
+ constructor();
12
+ /**
13
+ * 加密字符串
14
+ * @param input
15
+ */
16
+ encode(input: string): string;
17
+ /**
18
+ * 解密字符串
19
+ * @param input
20
+ */
21
+ decode(input: string): string;
22
+ }
23
+
24
+ /**
25
+ * DES加密 / 解密
26
+ * @author ilex.h
27
+ */
28
+ declare namespace DES {
29
+ /**
30
+ * 加密字符串
31
+ * @param data
32
+ * @param secretKey 秘钥,支持单秘钥以及二级和三级秘钥 `abcde` 和 `a,b` 和 `a,b,c` 等
33
+ * @example
34
+ * DES.encode('hello', 'test'); // DES.DesCore.encode(data, 'test');
35
+ * DES.encode('hello', ','); // DES.DesCore.encode(data, ',');
36
+ * DES.encode('hello', 'a,'); // DES.DesCore.encode(data, 'a', '');
37
+ * DES.encode('hello', 'a,b,c'); // DES.DesCore.encode(data, 'a', 'b', 'c');
38
+ */
39
+ export function encode(data: string, secretKey: string): string;
40
+ /**
41
+ * 解密字符串
42
+ * @param data
43
+ * @param secretKey
44
+ */
45
+ export function decode(data: string, secretKey: string): string;
46
+ }
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
+
53
+
54
+ declare namespace UUID {
55
+ /**
56
+ *
57
+ * @param len uuid 的字符长度
58
+ * @param radix 位数,默认为 62
59
+ * @example
60
+ * UUID.uuid(); // 7ED03492-919F-40D0-89D2-C53194F4A83D
61
+ */
62
+ export function uuid(len: number, radix: number): string;
63
+ /**
64
+ * @example
65
+ * UUID.uuidFast(); // E581CCDD-189C-482D-BE21-620863F423F9
66
+ */
67
+ export function uuidFast(): string;
68
+ /**
69
+ * @example
70
+ * UUID.uuidCompact(); // 090c3e83-ea67-45c4-b7dc-47c20eaea91e
71
+ */
72
+ export function uuidCompact(): string;
73
+ /**
74
+ * 获取 uid,以 Date.now() 为随机参照值
75
+ * @param flag 是否显示短杠,为 true 则去掉单杠
76
+ * @example
77
+ * UUID.uuidTime(); // 6fcac0c8-e7de-44e4-ada7-c1de03a45ad5
78
+ * UUID.uuidTime(true); // 5eb47f42a03c48e6ae6804a2517a1db4
79
+ */
80
+ export function uuidTime(flag: boolean): string;
81
+ /**
82
+ * @param prefix
83
+ * @example
84
+ * UUID.timeUUID(); // amos-timeuuid-1663831567208-1
85
+ */
86
+ export function timeUUID(prefix: string): string;
87
+ /**
88
+ * @param prefix
89
+ * @example
90
+ * UUID.longTimeUUID(); // longtime-202209221526-1
91
+ */
92
+ export function longTimeUUID(prefix: string): string;
93
+ /**
94
+ *
95
+ * @param tpl
96
+ * @example
97
+ * UUID.otherUUID(); // 6afe5aaf614eb8b00bf4bcd11a
98
+ */
99
+ export function otherUUID(tpl: string): string;
100
+ }
101
+
102
+ 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;
106
+ }
107
+
108
+ declare namespace random {
109
+ export function random(length: number): string;
110
+ export function randomInt(min: number, max: number): number;
111
+ }
112
+
113
+
114
+ declare namespace strUtils {
115
+ /**
116
+ * 首字母大写
117
+ * @param str
118
+ */
119
+ export function toCapitalStr(str: string): string;
120
+ /**
121
+ * 驼峰化, 仅支持首字母大写、或者采用中杠连接的两个字母首字母大写
122
+ * 如果要支持其它输入,将正则改为: /(-|(\s+)|_)(\w)/g
123
+ *
124
+ * @param {String} name
125
+ * @returns {String}
126
+ */
127
+ export function camelCase(name: string): string;
128
+ /**
129
+ * 将中缸连接的字符串 驼峰化
130
+ *
131
+ * hello-world => hellWorld
132
+ * Hello-world => hellWorld
133
+ * Hello-World => hellWorld
134
+ *
135
+ * @param {any} name
136
+ * @returns {String}
137
+ */
138
+ export function transCamel(name: string): string;
139
+ /**
140
+ * 字符串首字母大写
141
+ * @param {String} str
142
+ * @returns {String}
143
+ */
144
+ export function capFirst(name: string): string;
145
+ /**
146
+ * 获取字符串的hashCode码
147
+ * @param {String} str
148
+ * @returns {String} string | null
149
+ */
150
+ export function hashCode(name: string): string;
151
+ /**
152
+ * 进制与单位处理
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
168
+ */
169
+ export function toUTF8(str: string): string;
170
+ }
171
+
172
+
173
+ declare namespace colorUtil {
174
+ /**
175
+ * RGB颜色转换为16进制
176
+ * @param stringRgb
177
+ * @example
178
+ * toStringHexColor('rgba(241,112,19,1)'); // #f17013
179
+ * toStringHexColor('rgba(241,112,19, 0.1)'); // #f1701319
180
+ */
181
+ export function toStringHexColor(stringRgb: string): string;
182
+ /**
183
+ * - 转化为hex颜色 (仅支持 RGB),如果是 rgba 时,则舍去 a。
184
+ * - 如果传入的是 key color 则直接转化为与之对应的 hex 值
185
+ * @param {string} stringRgb
186
+ * @example
187
+ * toHexColor('rgba(241,112,19)'); // #f17013
188
+ * toHexColor('rgba(241,112,19, 1)'); // #f17013
189
+ * toHexColor('rgba(241,112,19, 0.1)'); // #f17013
190
+ * toHexColor('red'); // #ff0000
191
+ * toHexColor(); // ''
192
+ * toHexColor(null); // ''
193
+ * toHexColor(123456); // ''
194
+ * toHexColor(0x123456123456); // ''
195
+ */
196
+ export function toHexColor(stringRgb: string): string;
197
+ /**
198
+ * 16进制颜色转为RGB格式
199
+ * @param hexColor
200
+ * @example
201
+ * toRGBcolor('#AABBCC'); // rgb(170,187,204)
202
+ */
203
+ export function toRGBcolor(hexColor): string;
204
+ /**
205
+ * 将16进制的颜色转换为rgb
206
+ * @param hexColor
207
+ * @example
208
+ * transformColor('#AABBCC'); // rgb(170,187,204)
209
+ */
210
+ export function transformColor(hexColor: string): string;
211
+ export function isHexColor(color: string): boolean;
212
+ /**
213
+ * 判断是否是内置 英文 color
214
+ * @param color
215
+ * @example
216
+ * isKeyColor('red'); // true
217
+ * isKeyColor('yellow'); // true
218
+ * isKeyColor('asdfasdfa'); // false
219
+ */
220
+ export function isKeyColor(color: string): boolean;
221
+ export function isRgbColor(color: string): boolean;
222
+ /**
223
+ * 将rgb颜色转化成object
224
+ * @param color
225
+ * @example
226
+ * '12,12,12,12' => {r:12,g:12,b:12,a:12}
227
+ * 'rgba(12,12,12,12)' => {r:12,g:12,b:12,a:12}
228
+ */
229
+ export function rgb2object(color: string): RGBA;
230
+ /**
231
+ * 将object的rgb转化成string
232
+ * @param color
233
+ * @example
234
+ * objRGB2str({ r:1, g:1, b:1, a:1 }); // 'rgba(1,1,1,1)'
235
+ * objRGB2str({ r:1, g:1, b:1, a:0 }); // 'rgba(1,1,1,0)'
236
+ * objRGB2str({ r:1, g:1, b:1 }); // 'rgba(1,1,1)'
237
+ */
238
+ export function objRGB2str(color: object): string;
239
+ /**
240
+ * key color 转化为 hex color。
241
+ * 如果不是 key color 则直接返回 color 自身
242
+ * @param color
243
+ */
244
+ export function keyColorToHex(color: string): string;
245
+ /**
246
+ * 产生渐变色函数
247
+ * @param color
248
+ * @param minValue
249
+ * @param maxValue
250
+ */
251
+ export function gradientColor(color: Object, minValue: number, maxValue: number): any;
252
+ }
253
+
254
+ declare namespace randomColor {
255
+ export function randomHexColor(): string;
256
+ export function randomRgbColor(): string;
257
+ export function randomHexColorStr(): string;
258
+ }
259
+
260
+
261
+ /**
262
+ * 转码URL中的特殊字符
263
+ *
264
+ * 特殊字符说明
265
+ * 1. '+' URL 中+号表示空格 %2B
266
+ * 2. '空格' URL中的空格可以用+号或者编码 %20
267
+ * 3. '/' 分隔目录和子目录 %2F
268
+ * 4. '?' 分隔实际的 URL 和参数 %3F
269
+ * 5. '%' 指定特殊字符 %25
270
+ * 6. '#' 表示书签 %23
271
+ * 7. '&' URL 中指定的参数间的分隔符 %26
272
+ * 8. '=' URL 中指定参数的值 %3D
273
+ *
274
+ * @param url
275
+ * @return new url
276
+ * @example
277
+ * encodeUrl('http://localhost:3000/login?user=123&pwd=123'); // http://localhost:3000/login?user%3D123%26pwd%3D123
278
+ */
279
+ export function encodeUrl(url: string): string;
280
+
281
+ /**
282
+ * restful风格路径参数替换
283
+ *
284
+ * @param url
285
+ * @param options
286
+ * @param regexps
287
+ *
288
+ * @example
289
+ * const _url = 'a/b/{id}'
290
+ * const url = restfulUrl(_url, { id: '123' }, [regex]); => 'a/b/123'
291
+ */
292
+ export function restfulUrl(url: string, options: {}, regexps: RegExp): string;
293
+
294
+ /**
295
+ *
296
+ * @param str
297
+ * @param key
298
+ * @param raw
299
+ * @returns md5 value
300
+ * @example
301
+ * // calc the (hex-encoded) MD5 hash of a given string value:
302
+ * var hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"
303
+ * // calc the (hex-encoded) HMAC-MD5 hash of a given string value and key:
304
+ * var hash = md5("value", "key"); // "01433efd5f16327ea4b31144572c67f6"
305
+ * // calc the raw MD5 hash of a given string value:
306
+ * var hash = md5("value", null, true);
307
+ * // calc the raw HMAC-MD5 hash of a given string value and key:
308
+ * var hash = md5("value", "key", true);
309
+ */
310
+ export function MD5(str: string, key: string, raw: boolean): string;
311
+
312
+ /**
313
+ * deep copy
314
+ * 1. obj 中包含方法,则直接赋值
315
+ * @param source
316
+ */
317
+ export function deepCopy(source: any): any;
318
+ /**
319
+ * deep equal use stringfy
320
+ * @param valA
321
+ * @param valB
322
+ */
323
+ export function deepEqual(valA: any, valB: any): boolean;
324
+
325
+ /**
326
+ * deep equal
327
+ * support: Object/Array/String/Number/RegExp/
328
+ * @param valA
329
+ * @param valB
330
+ */
331
+ export function fastDeepEqual(a: any, b: any): boolean;
332
+ export function isNode(): boolean;
333
+
334
+ /**
335
+ * 删除多余属性
336
+ * @param obj 目标对象
337
+ * @param keys 需要删除的键
338
+ * @example
339
+ * omit({ name: 'ilex', age: 16 }, ['age']); // { name: 'ilex' }
340
+ */
341
+ export function omit(obj: object, keys: string | Array<String>): any;
342
+
343
+ /**
344
+ * 从指定的 obj 中获取 指定的key组成新的对象
345
+ * @param obj
346
+ * @param keys
347
+ * @example
348
+ * pick({ name: 'ilex', age: 16 }, ['age']); // { age: 16 }
349
+ * pick({ name: 'ilex', age: 16 }, ['']); // {}
350
+ * pick({ name: 'ilex', age: 16 }, ['you']); // {},如果指定对象中无指定的 key,则不拾取
351
+ */
352
+ export function pick(obj: Object | Function, keys: string | Array<String>): Object;
353
+ /**
354
+ * 从指定的 obj 中获取 满足 judge(key, value) 组成新的对象
355
+ *
356
+ * @param obj
357
+ * @param judge
358
+ * @example
359
+ * pickBy({ a: 1, b: 2, c: 'ray' }, (key, value) => typeof value === 'number')
360
+ */
361
+ export function pickBy(obj: Object | Function, judge: (key, value) => Boolean): Object;
362
+ /**
363
+ * 将数据转化为json
364
+ * @param data
365
+ */
366
+ export function parseJson(data: any): any;
367
+
368
+ /**
369
+ * 将object等 类型的数据转化为string
370
+ * @param json
371
+ */
372
+ export function stringify(json: any): any;
373
+
374
+ export function trim(str: string | null | undefined): string;
375
+
376
+
377
+ export class objectPath {
378
+ /**
379
+ * tests path existence
380
+ * @param obj
381
+ * @param path
382
+ * @example
383
+ * objectPath.has(obj, "a.b"); // true
384
+ * objectPath.has(obj, ["a","d"]); // false
385
+ */
386
+ has(obj: Object, path: number | string): boolean;
387
+ ensureExists(obj: Object, path: number | string, value: any): boolean;
388
+ set(obj: Object, path: number | string, value: any, doNotReplace: boolean): void;
389
+ empty(obj: Object, path: number | string): void;
390
+ push(obj: Object, path: number | string, values?: any): void;
391
+ coalesce(obj: Object, paths: Array<Number|String>, defaultValue: any): void;
392
+ /**
393
+ * 获取指定路径节点
394
+ * @param obj
395
+ * @param path
396
+ * @param defaultValue
397
+ * @example
398
+ * // bind object
399
+ var model = objectPath({
400
+ a: {
401
+ b: "d",
402
+ c: ["e", "f"]
403
+ }
404
+ });
405
+
406
+ //now any method from above is supported directly w/o passing an object
407
+ model.get("a.b"); //returns "d"
408
+ */
409
+ get(obj: Object, path: Number|String, defaultValue: any): any;
410
+ /**
411
+ * 删除指定路径节点
412
+ * @param obj
413
+ * @param path
414
+ * @example
415
+ * model.del("a.b"); // obj.a.b is now undefined
416
+ */
417
+ del(obj: Object, path: Number|String): string;
418
+ create(options: Object): Function;
419
+ withInheritedProps: Function;
420
+ }
421
+
422
+ /**
423
+ * 解析数据
424
+ * @param text
425
+ * @param dataObj
426
+ * @param regexps 可选
427
+ * @returns returns a new str
428
+ * @example
429
+ * demo: parseText('a/{b}/{c}/d',{a: 1, b:2}) 返回: 'a/1/2/d'
430
+ * demo: parseText('a/b?name={name}&pwd={pwd}',{name: 'ilex', pwd:122}) 返回: 'a/b?name=ilex&pwd=123'
431
+ */
432
+ export function parseText(text: string, dataObj: object, regexps?: string | RegExp): string;
433
+
434
+ export function shallowEqual(objA, objB): boolean;
435
+
436
+
437
+ export function addition(arg1, arg2): number;
438
+ export function subtraction(arg1, arg2): number;
439
+ /**
440
+ * 小数乘法
441
+ * @param arg1 被乘数(接受小数和整数)
442
+ * @param arg2 乘数(接受小数和整数)
443
+ * @param fix 乘积保留几位(接受正负整数以及0),默认值为 0
444
+ * @returns {Number}
445
+ * @example
446
+ * accMul(0.56, 100); // 56
447
+ * accMul(0.5679, 100); // 57
448
+ * accMul(0.5679, 100.2); // 57
449
+ */
450
+ export function accMul(arg1: Number, arg2: Number, fix?: Number): number;
451
+ /**
452
+ * 小数除法
453
+ * @param arg1 被乘数(接受小数和整数)
454
+ * @param arg2 乘数(接受小数和整数)
455
+ * @param fix 除法保留几位(接受正负整数以及0),默认值为 0
456
+ * @returns {Number}
457
+ * @example
458
+ * accDivide(56, 100); // 0.56
459
+ * accDivide(5679, 100, 2); // 56.79
460
+ * accDivide(5679, 100.2, 2); // 56.68
461
+ */
462
+ export function accDivide(arg1: Number, arg2: Number, fix?: Number): number;
463
+
464
+ /**
465
+ * 将数值格式化成金额形式
466
+ *
467
+ * @param num 数值(Number或者String)
468
+ * @param precision 精度,默认不变. 传 null or undefined
469
+ * @param separator 分隔符,默认为逗号
470
+ * @param sign 前缀,默认为$
471
+ * @param unit 单位,默认为空
472
+ * @return 金额格式的字符串,如'1,234,567',默认返回 ''
473
+ */
474
+ export function coinFormat(num: number, precision: number, separator: string, sign: string, unit: string): string | '';
475
+
476
+ /**
477
+ * dateTime
478
+ */
479
+ declare namespace dateTime {
480
+ /**
481
+ * 将日期时间戳格式化成指定格式
482
+ * @param date
483
+ * @param fmt 默认 yyyy-MM-dd HH:mm:ss
484
+ * @example
485
+ * formatDate(); // 2016-09-02 13:17:13
486
+ * formatDate(new Date(), 'yyyy-MM-dd'); // 2016-09-02
487
+ * formatDate(new Date(), 'yyyy-MM-dd 第q季度 www HH:mm:ss:SSS');// 2016-09-02 第3季度 星期五 13:19:15:792
488
+ * formatDate(1472793615764); // 2016-09-02 13:20:15
489
+ */
490
+ export function formatDate(date: Date | number, fmt: string): string;
491
+ /**
492
+ * 时间戳转时间,这是另一种方式 2018-07-09 11:04:51
493
+ *
494
+ * @param date
495
+ * @returns string
496
+ */
497
+ export function timetrans(date: Date | number): string;
498
+ /**
499
+ *将一个日期格式化成友好格式,比如,1分钟以内的返回“刚刚”,当天的返回时分,当年的返回月日,否则,返回年月日
500
+ *
501
+ * @param date
502
+ * @returns string
503
+ */
504
+ export function formatDateToFriendly(date: Date | number): string;
505
+ /**
506
+ * 将一段时长转换成友好格式
507
+ * @param time
508
+ * @returns string
509
+ * @example
510
+ * var str = friendlyDate('1311111119999'); // 6年前(括号里的字符串值为1970年距字符串值表示的时间的毫秒数)
511
+ * var str2 = friendlyDate('1503190042273'); // 1天前
512
+ */
513
+ export function friendlyDate(time: number): string;
514
+ /**
515
+ * 将一段时长转换成友好格式
516
+ * @param second
517
+ * @returns string
518
+ * @example
519
+ * 147->“2分27秒”
520
+ * 1581->“26分21秒”
521
+ * 15818->“4小时24分”
522
+ */
523
+ export function formatDurationToFriendly(second: number): string;
524
+ /**
525
+ * 将时间转换成MM:SS形式
526
+ * @param second
527
+ */
528
+ export function formatTimeToFriendly(second: number): string;
529
+ /**
530
+ * 判断某一年是否是闰年 可以是一个date类型,也可以是一个int类型的年份,不传默认当前时间
531
+ * @param year
532
+ */
533
+ export function isLeapYear(year: number): string;
534
+ /**
535
+ * 获取某一年某一月的总天数,没有任何参数时获取当前月份的
536
+ * @param date
537
+ * @param month
538
+ * @example
539
+ * 方式一:$.getMonthDays();
540
+ * 方式二:$.getMonthDays(new Date());
541
+ * 方式三:$.getMonthDays(2013, 12);
542
+ */
543
+ export function getMonthDays(date: Date | number, month: number): string;
544
+ /**
545
+ * 计算两个日期之间的天数,用的是比较毫秒数的方法
546
+ * 传进来的日期要么是Date类型,要么是yyyy-MM-dd格式的字符串日期
547
+ * @param date1 日期一
548
+ * @param date2 日期二
549
+ */
550
+ export function countDays(date1: Date | number, date2: Date | number): string;
551
+ /**
552
+ * 将字符串解析成日期
553
+ * @param str 输入的日期字符串,如'2014-09-13'
554
+ * @param fmt 字符串格式,默认'yyyy-MM-dd',支持如下:y、M、d、H、m、s、S,不支持w和q
555
+ * @returns 解析后的Date类型日期
556
+ * @example
557
+ * parseDate('2016-08-11'); // Thu Aug 11 2016 00:00:00 GMT+0800
558
+ * parseDate('2016-08-11 13:28:43', 'yyyy-MM-dd HH:mm:ss') // Thu Aug 11 2016 13:28:43 GMT+0800
559
+ */
560
+ export function parseDate(str: string, fmt: string): string;
561
+ /**
562
+ * 到某一个时间的倒计时
563
+ * @param endTime
564
+ * @example
565
+ * getEndTime('2017/7/22 16:0:0') // result:"剩余时间6天 2小时 28 分钟20 秒"
566
+ */
567
+ export function getEndTime(endTime: string | number): object;
568
+ /**
569
+ * 到某一个时间的倒计时
570
+ * @param endTime
571
+ * @example
572
+ * getEndTimeStr('2017/7/22 16:0:0') // "剩余时间6天 2小时 28 分钟20 秒"
573
+ */
574
+ export function getEndTimeStr(endTime: string | number): string;
575
+ /**
576
+ * 获取某月有多少天
577
+ * @param time
578
+ */
579
+ export function getMonthOfDay(time: string | number): string;
580
+ /**
581
+ * 获取某年有多少天
582
+ * @param time
583
+ */
584
+ export function getYearOfDay(time: string | number): string;
585
+ /**
586
+ * 获取某年的第一天
587
+ * @param time
588
+ */
589
+ export function getFirstDayOfYear(time: string | number): string;
590
+ /**
591
+ * 获取某年最后一天
592
+ * @param time
593
+ */
594
+ export function getLastDayOfYear(time: string | number): string;
595
+ /**
596
+ * 获取某个日期是当年中的第几天
597
+ * @param time
598
+ */
599
+ export function getDayOfYear(time: string | number): string;
600
+ /**
601
+ * 获取某个日期在这一年的第几周
602
+ * @param time
603
+ */
604
+ export function getDayOfYearWeek(time: string | number): string;
605
+ /**
606
+ * 获取两个时间段差多久
607
+ * @param time
608
+ * @param fmt
609
+ */
610
+ export function timeFn(str: string, fmt: string): string;
611
+ }
612
+
613
+ /**
614
+ * amostool
615
+ */
616
+ declare namespace amostool {}
617
+
618
+ /**
619
+ * amostool utils
620
+ */
621
+ declare namespace utils {
622
+ export function isString(value: any): boolean;
623
+ export function isArray(value: any): boolean;
624
+ export function isObject(value: any): boolean;
625
+ export function isBoolean(value: any): boolean;
626
+ export function isFunction(value: any): boolean;
627
+ /**
628
+ * 判断 number,采用正则表达式进行判断
629
+ * 正则表达式:/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/
630
+ * @param {*} value
631
+ */
632
+ export function isNumber(value: any): boolean;
633
+ /**
634
+ * 支持 string 类型的科学计数 number 校验
635
+ * @param value
636
+ */
637
+ export function isENumber(value: any): boolean;
638
+ export function isFloat(value: any): boolean;
639
+ export function isOpacity(value: any): boolean;
640
+ export function toFloat(value: any): number;
641
+ export function isNull(value: any): boolean;
642
+ export function isUndefined(value: any): boolean;
643
+ export function isNil(value: any): boolean;
644
+ /**
645
+ * 空(null、undefined、'')
646
+ * @param value
647
+ * @example
648
+ * isBlank(); // true
649
+ * isBlank(void 0); // true
650
+ * isBlank(null); // true
651
+ * isBlank(''); // true
652
+ * isBlank(NaN); // false
653
+ * isBlank(' '); // false
654
+ * isBlank(0); // false
655
+ * isBlank(false); // false
656
+ * isBlank(true); // false
657
+ */
658
+ export function isBlank(value: any): boolean;
659
+ export function has(obj: object | Array<any>, path: Array<any> | string): boolean;
660
+ /**
661
+ * Retrieve the values of an object's properties.
662
+ * @param obj
663
+ */
664
+ export function values(obj: object): Array<any>;
665
+ export function noop(): void;
666
+ export function isEmpty(value: any): boolean;
667
+ export function isEmptyObject(value: any): boolean;
668
+ export function isElement(value: any): boolean;
669
+ export function isHTMLElement(value: any): boolean;
670
+ export function isSVGElement(value: any): boolean;
671
+ export function isDom(value: any): boolean;
672
+ /**
673
+ * check value is url
674
+ * @param value
675
+ * @example
676
+ * isUrl('http://www.baidu.com') // true
677
+ * isUrl('https://www.baidu.com') // true
678
+ * isUrl('www.baidu.com') // false
679
+ * isUrl('http://172.16.1.2') // true
680
+ * isUrl('172.16.1.2') // false
681
+ * isUrl('/a/b/c') // false
682
+ * isUrl('main/dd/d') // false
683
+ * isUrl('http://localhost:8080/aaa') // true
684
+ */
685
+ export function isUrl(value: string): boolean;
686
+ export function isBuiltInObject(value: any): boolean;
687
+ export function null2default(str: any): any;
688
+ /**
689
+ * 判断对象是不是Json
690
+ * Object 对象,typeof === object && toString === '[object Object]'
691
+ * @param obj
692
+ * @returns boolean true 是 false不是
693
+ */
694
+ export function isJson(obj: any): boolean;
695
+
696
+ export function isSymbol(obj: any): boolean;
697
+ export function isNullOrUndefined(obj: any): boolean;
698
+ export function isDate(obj: any): boolean;
699
+
700
+ /**
701
+ * 判断string能否被转成json
702
+ * 参数 str 如果不是 string 则直接返回 false
703
+ * @param str
704
+ * @returns boolean
705
+ */
706
+ export function stringIsJson(value: any): boolean;
707
+ /**
708
+ * 判断key是否在object内
709
+ * (采用 in 判断,继承属性均会判断)
710
+ * @param keys
711
+ * @param obj 如果 obj 是 null or undefined, 或者 非 object,则直接 返回 false
712
+ */
713
+ export function isKeyInObject(keys: string | string[], obj: any): boolean;
714
+ /**
715
+ * 判断key是否在object内
716
+ * (采用 hasOwnProperty 判断,继承属性不会判断)
717
+ * @param keys
718
+ * @param obj 如果 obj 是 null or undefined, 或者 非 object,则直接 返回 false
719
+ */
720
+ export function isOwnKeyInObject(keys: string | string[], obj: any): boolean;
721
+ /**
722
+ * 判断是否是 promise
723
+ * @param value
724
+ */
725
+ export function isPromise(value: any): boolean;
726
+ /**
727
+ * 判断是否是正则对象
728
+ * @param value
729
+ * @example
730
+ * isRegExp(undefined); // false
731
+ * isRegExp(''); // false
732
+ * isRegExp(null); // false
733
+ * isRegExp(123); // false
734
+ * isRegExp('aa'); // false
735
+ * isRegExp(/aa/); // true
736
+ * isRegExp(new RegExp('aa')); // true
737
+ * isRegExp({ test(){} }); // false
738
+ */
739
+ export function isRegExp(value: any): boolean;
740
+ export function simpleEqual(objA: object, objB: object): boolean;
741
+ /**
742
+ * 判断是一个 image 的路径
743
+ * `/a/a/a.png|jpe?g|gif...`
744
+ * `http://a.b/a.png|jpe?g|gif...`
745
+ * `data:image/png|jpe?g|gif;base64,`
746
+ * @param url 支持的格式 `jpe?g|png|gif|bmp|ico|tga`
747
+ * @example
748
+ * isImageSrc('/a/a/a.png'); // true
749
+ * isImageSrc('http://a.b/a.png'); // true
750
+ * isImageSrc('data:image/png|jpe?g|gif;base64,'); // true
751
+ */
752
+ export function isImageSrc(url: String): boolean;
753
+ /**
754
+ * 判断图片是 gif
755
+ * @param url 支持的格式
756
+ * @example
757
+ * isGIF('a.gif'); // true
758
+ * isGIF('data:image/;base64,'); // true
759
+ */
760
+ export function isGIF(url: String): boolean;
761
+ /**
762
+ * 将数字部分内容转化为 *
763
+ * @param number 目标 Number
764
+ * @param start 起始位置 默认3
765
+ * @param len 转换位数 默认4
766
+ * @param sign 替换的字符 默认*
767
+ */
768
+ export function encodeNumber(number: Number, start?: number, len?: number, sign?: string): String;
769
+
770
+ /**
771
+ * 获取扩展名
772
+ *
773
+ * 可快速使用 `filePath.split('.').pop();` 获取扩展名
774
+ * @param filePath
775
+ * @return {String} ext
776
+ * @example
777
+ * getFileExtension('a.png'); // png
778
+ * getFileExtension('a/a/a.png'); // png
779
+ * getFileExtension('a.a.a.png.jpg'); // jpg
780
+ * getFileExtension('a'); // ''
781
+ */
782
+ export function getFileExtension(filePath: string): String;
783
+
784
+ /**
785
+ * 将指定 size 中的数据,转化为 byte
786
+ * - 默认不区分大小写, mb/MB/Mb 均表示 mb
787
+ * - 默认去除内部所有空格, 1024 MB -> 1024mb
788
+ * - 无单位或者 number 类型,将直接转化为 number值,默认当 byte 处理
789
+ * @param size 带有单位的 size,不带单位时,直接返回该值
790
+ * @returns byte
791
+ * @example
792
+ * fileSizeToByte('1kb'); // 1024
793
+ * fileSizeToByte('1mb'); // 1048576
794
+ * fileSizeToByte('1MB'); // 1048576
795
+ * fileSizeToByte('1gb'); // 1073741824
796
+ * fileSizeToByte('1tb'); // 1099511627776
797
+ * fileSizeToByte('123'); // 123
798
+ * fileSizeToByte(123); // 123
799
+ */
800
+ export function fileSizeToByte(size: string): String;
801
+
802
+ export function some(arr: Array<any>, fun: Function /*, thisArg */): boolean;
803
+ export function every(arr: Array<any>, callbackfn: Function, thisArg): boolean;
804
+ export function reduce(arr: Array<any>, callback: Function /*, initialValue*/);
805
+ export function parse2string(obj: object | Array<any>): string;
806
+ export function parse2object(str: string): object | Array<any>;
807
+ export function dataToArray(vars: any): Array<any>;
808
+ /**
809
+ * Those data types can be cloned:
810
+ * Plain object, Array, TypedArray, number, string, null, undefined.
811
+ * Those data types will be assgined using the orginal data:
812
+ * BUILTIN_OBJECT
813
+ * Instance of user defined class will be cloned to a plain object, without
814
+ * properties in prototype.
815
+ * Other data types is not supported (not sure what will happen).
816
+ *
817
+ * Caution: do not support clone Date, for performance consideration.
818
+ * (There might be a large number of date in `series.data`).
819
+ * So date should not be modified in and out of echarts.
820
+ *
821
+ * @param source
822
+ * @return new
823
+ */
824
+ export function clone(source: any): object | Array<any>;
825
+ /**
826
+ * @param target
827
+ * @param source
828
+ * @param [overwrite=false]
829
+ * @return target
830
+ */
831
+ export function merge(target: object | Array<any>, source: object | Array<any>, overwrite?: boolean): object | Array<any>;
832
+ /**
833
+ * @param targetAndSources The first item is target, and the rests are source.
834
+ * @param [overwrite=false]
835
+ * @return target
836
+ */
837
+ export function mergeAll(targetAndSources: Array<any>, overwrite?: boolean): object | Array<any>;
838
+ /**
839
+ * 比较 objTarget 中的所有属性值,是否在 objSource 中相等
840
+ * @param objSource
841
+ * @param objTarget
842
+ */
843
+ export function subObjectEqual(objSource: {}, objTarget: {}): Boolean;
844
+ /**
845
+ * 校验给定的 string 是否是 文件名
846
+ *
847
+ * 校验中使用的正则表达式: `/[\\/:\*\?"<>\|]/g`
848
+ * @param str
849
+ * @param maxLen
850
+ * @example
851
+ * checkFileName('example.txt'); // true
852
+ * checkFileName('con\\example.txt'); // false
853
+ * checkFileName('example:.txt'); // false
854
+ * checkFileName(' example.txt'); // false
855
+ * checkFileName('example.txt '); // false
856
+ * checkFileName('example.txt.'); // true
857
+ * checkFileName('example..............txt'); // true
858
+ */
859
+ export function checkFileName(str: String | Number, maxLen?: 259): Boolean;
860
+ }
861
+