amos-tool 1.4.8 → 1.4.9

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.md CHANGED
@@ -1,667 +1,670 @@
1
- # amos-tool
2
-
3
- by ilex.h
4
-
5
- docs: [docs](https://unpkg.com/amos-tool@latest/docs/index.html)
6
-
7
- ## useage
8
-
9
- npm install --save amos-tool
10
-
11
- ## keywords
12
-
13
- * amos ui
14
- * amos tool
15
-
16
- ## infos
17
-
18
- [![install size](https://packagephobia.now.sh/badge?p=amos-tool)](https://packagephobia.now.sh/result?p=amos-tool)
19
-
20
- ## api
21
-
22
- |name|link|description|
23
- |------|------|------|
24
- |Base64|[Base64](#base64)|`base64加密解密`|
25
- |MD5|[MD5](#md5)|`md5加密解密`|
26
- |DES|[DES](#des)|`des加密解密`|
27
- |Browser|[Browser](#browser)|`获取浏览器类型`|
28
- |deepCopy|[deepCopy](#deepCopy)|`深度复制`|
29
- |deepEqual|[deepEqual](#deepEqual)|`深度比较(stringify方式)`|
30
- |fastDeepEqual|[fastDeepEqual](#fastDeepEqual)|`深度比较(循环)`|
31
- |parseText|[parseText](#parseText)|`替换或者补全url`|
32
- |List|[List](#list)|`List集合`|
33
- |Queue|[Queue](#queue)|`队列`|
34
- |UUID|[UUID](#uuid)|`uuid`|
35
- |browserSupport|[browserSupport](#browserSupport)|`浏览器支持`|
36
- |Log|[Log](#log)|`定制化的log日志`|
37
- |Store|[Store](#store)|`数据处理,主要是localStorage、session、cookie`|
38
- |LocationParam|[LocationParam](#locationParam)|`location 工具`|
39
- |array2tree|[array2tree](#array2tree)|`将array转化为tree数据`|
40
- |tableFilter|[tableFilter](#tableFilter)|`表格数据过滤`|
41
- |pwdPolicy|[pwdPolicy](#pwdPolicy)|`密码生成器`|
42
- |omit|[omit](#omit)|`omit操作,删除object中的键`|
43
- |pick|[pick](#pick)|`pick操作,获取object指定key组成的新对象`|
44
- |utils|[utils](#utils)|`常用工具`|
45
- |xss|[utils](#xss)|`xss 工具及`|
46
- |strUtils|[strUtils](#strUtils)|`string常用工具`|
47
- |other|[other](#other)|`其它工具集`|
48
-
49
- ### base64
50
-
51
- ```js
52
- import { Base64 } from 'amos-tool';
53
- // or import Base64 from 'amos-tool/lib/encrypt/_base64';
54
-
55
- var b64 = new Base64();
56
-
57
- b64.encode(input);
58
- b64.decode(input);
59
- ```
60
-
61
- ### md5
62
-
63
- ```js
64
- import { MD5 } from 'amos-tool';
65
- // or import MD5 from 'amos-tool/lib/encrypt/_md5';
66
-
67
- var result = MD5('value'); // 2063c1608d6e0baf80249c42e2be5804
68
- var result = MD5('value', 'key'); // 01433efd5f16327ea4b31144572c67f6
69
- var result = MD5('value', null, true); // 'c\xc1`\x8dn\x0b\xaf\x80$\x9cB\xe2\xbeX\x04'
70
- var result = MD5('value', 'key', true); // '\x01C>\xfd_\x162~\xa4\xb3\x11DW,g\xf6'
71
- ```
72
-
73
- ### des
74
-
75
- > 注意,加密解密时,第一个 `秘钥` 不能为空
76
-
77
- ```js
78
- DES.DesCore.encode(data, firstKey, secondKey, thirdKey)
79
- DES.DesCore.decode(data, firstKey, secondKey, thirdKey)
80
-
81
- DES.encode(data, secretKey);
82
- DES.decode(data, secretKey);
83
- ```
84
-
85
- * example
86
-
87
- ```js
88
- import { DES } from 'amos-tool';
89
- // or import DES from 'amos-tool/lib/encrypt/des';
90
-
91
- const desCore = DES.DesCore;
92
-
93
- desCore.encode('123456', 'a'); // 484FD6D18A5501370873DB5F557A23F9
94
- desCore.encode('123456', 'a', 'b'); // 953AFFF48E49E4B94D8B74AABB6905E5
95
- desCore.encode('123456', 'a', 'b', 'c'); // 7C49B05CCBCBEECC5665732A177E624B
96
-
97
- desCore.decode('484FD6D18A5501370873DB5F557A23F9', 'a'); // 123456
98
- desCore.decode('953AFFF48E49E4B94D8B74AABB6905E5', 'a', 'b'); // 123456
99
- desCore.decode('7C49B05CCBCBEECC5665732A177E624B', 'a', 'b', 'c'); // 123456
100
-
101
-
102
- DES.encode('123456', 'a'); // 484FD6D18A5501370873DB5F557A23F9
103
- DES.encode('123456', 'a,b'); // 953AFFF48E49E4B94D8B74AABB6905E5
104
- DES.encode('123456', 'a,b,c'); // 7C49B05CCBCBEECC5665732A177E624B
105
-
106
- DES.decode('484FD6D18A5501370873DB5F557A23F9', 'a'); // 123456
107
- DES.decode('953AFFF48E49E4B94D8B74AABB6905E5', 'a,b'); // 123456
108
- DES.decode('7C49B05CCBCBEECC5665732A177E624B', 'a,b,c'); // 123456
109
- ```
110
-
111
- > 注意:
112
-
113
- secretKey 'a,b,c' 与 `a, b,c` 不同,识别空格。 支持3个秘钥,采用 `,` 分割
114
-
115
- 同时,`DES.DesCore` 第一个 key 值不可以为 空('', undefined, null)
116
-
117
- ### browser
118
-
119
- ```js
120
- Browser.isFirefox();
121
- Browser.isIE();
122
- Browser.isEdge();
123
- Browser.isChrome();
124
- Browser.isSafari();
125
- ```
126
-
127
- ### deepCopy
128
-
129
- ```js
130
- import { deepCopy } from 'amos-tool';
131
-
132
- deepCopy(source);
133
-
134
- import deepCopy, { eq } from 'amos-tool/lib/_deepCopy';
135
-
136
- eq(value, other)
137
- ```
138
-
139
- ### deepEqual
140
-
141
- ```js
142
- deepEqual(valA, valB);
143
- ```
144
-
145
- ### fastDeepEqual
146
-
147
- ```js
148
- fastDeepEqual(valA, valB);
149
- ```
150
-
151
- ### parseText
152
-
153
- ```js
154
-
155
- /**
156
- * 解析数据
157
- * @param {string} text
158
- * @param {object} dataObj
159
- * @param {string|RegExp} regexps 可选
160
- * @doc parseText('a/{b}/{c}/d',{a: 1, b:2}) 返回: 'a/1/2/d'
161
- * @doc parseText('a/b?name={name}&pwd={pwd}',{name: 'ilex', pwd:122}) 返回: 'a/b?name=ilex&pwd=123'
162
- */
163
- parseText(text, dataObj, regexps);
164
- ```
165
-
166
- ### list
167
- ```js
168
- List props:
169
-
170
- ArrayList: var arrlist = new List.ArrayList();
171
- parse2string: List.parse2string(obj)
172
- parse2object: List.parse2object(str)
173
- simpleEqual: List.simpleEqual(objA, objB)
174
- isObject: List.isObject(obj)
175
-
176
- // ArrayList
177
- var arrlist = new List.ArrayList();
178
-
179
- arrlist.size(); // get size of list
180
- arrlist.values();// all values
181
- arrlist.isEmpty();// check empty
182
- arrlist.iterator(callBack);// iterator
183
- arrlist.get(index);// 取得指定下标的值
184
- arrlist.add(value); // add item
185
- arrlist.addAll(value);// add all item, value is a arrayList
186
- arrlist.set(index, value);// 设置值
187
- arrlist.remove(value);// remove item
188
- arrlist.removeAt(index); // //remove item by index
189
- arrlist.indexOf(value); // get item index from list
190
- arrlist.clear(); // clear list
191
- arrlist.insert(index, value); // insert item in index place
192
- arrlist.updateValue(key, value); // use value[key] check equal
193
- ```
194
-
195
- ### queue
196
- ```js
197
- var q = new Queue;
198
- q.push(obj) // 入队
199
- q.pop();// 出队
200
- q.head();// 返回队列中头部(即最新添加的)的动态对象
201
- q.tail();// 返回队列中尾部(即最早添加的)的动态对象
202
- q.length();// 返回数据队列长度
203
- q.empty(); // 队列是否为空
204
- q.clear(); // 清空
205
- ```
206
-
207
- ### uuid
208
-
209
- ```js
210
- uuid(len, radix); // radix must be <= 62 , uuid(8, 2)
211
- uuidFast();
212
- uuidCompact();
213
- timeUUID(prefix = 'amos-timeuuid');
214
- longTimeUUID(prefix = 'longtime');
215
- otherUUID(tpl = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'); // 同 uuidCompact,无 '-'
216
- ```
217
-
218
- ### browserSupport
219
-
220
- * apis
221
-
222
- ```js
223
- simpleuse:
224
- defaultConfig: ['firefox/51.0', 'chrome/56']
225
- browserSupport();
226
- browserSupport('firefox/51.0');
227
- browserSupport(['firefox/51.0', 'chrome/56']);
228
- withMatchs:
229
- muitlConfig: ['firefox/', 'chrome/'];
230
- browserSupport(null, {
231
- 'firefox/': {limit: consts.GREATER_EQUAL, version: 51},
232
- 'chrome/': {limit: consts.GREATER_EQUAL, version: 56}
233
- });
234
-
235
- browserSupport('firefox/', {limit: consts.GREATER_EQUAL, version: 51});
236
-
237
- browserSupport(['firefox/', 'chrome/'], {
238
- 'firefox/': {limit: consts.GREATER_EQUAL, version: 51},
239
- 'chrome/': {limit: consts.GREATER_EQUAL, version: 56}
240
- });
241
-
242
- consts:
243
- GREATER: 1, // 大于
244
- EQUAL: 2, // 等于
245
- LESS: 3, // 小于
246
- GREATER_EQUAL: 4, // 大于等于
247
- LESS_EQUAL: 5 // 小于等于
248
- ```
249
-
250
- * demo
251
-
252
- ```js
253
- // 基本使用
254
- const result = browserSupport();
255
-
256
- const paramsList = ['firefox/', 'chrome/', 'ie'];
257
- const limit = {
258
- 'firefox/': { limit: consts.GREATER_EQUAL, version: 50 },
259
- 'chrome/': { limit: consts.GREATER_EQUAL, version: 55 },
260
- 'ie': { limit: consts.GREATER_EQUAL, version: 6 }
261
- };
262
-
263
- // 自定义使用 (注意适配ie时 写法)
264
- const result2 = browserSupport(paramsList, limit);
265
- ```
266
-
267
- ### log
268
-
269
- ```js
270
-
271
- window.LogConfig
272
- window.LogConfig.isDebug
273
-
274
- Log.trace()
275
- Log.debug()
276
- Log.info()
277
- Log.warn()
278
- Log.error()
279
- Log.fatal()
280
-
281
- ```
282
-
283
- ### store
284
-
285
- ```js
286
- `default function list`
287
- // 所有的cookie数据,均采用 escape/unescape 进行转码、解码
288
- encrypt(str) // 加密
289
- decrypt(str) // 解密
290
- setCookieByDays(name, value, days)
291
- getAllCookies() // 获取所有的cookie,同时每个key对应的value,均执行了 JSON.parse(value)
292
- setCookieByHour(name, value, hour)
293
- getCookieByName(name)
294
- removeCookieByName(name)
295
- clearAllCookie()
296
-
297
- `localStorage`
298
-
299
- const ls = Store.lsTool;
300
-
301
- ls.read(key)
302
- ls.write(key, data)
303
- ls.each(fn)
304
- ls.remove(key)
305
- ls.clearAll()
306
-
307
- `sessionStorage`
308
-
309
- const session = Store.session;
310
-
311
- session.read(key)
312
- session.write(key, data)
313
- session.each(fn)
314
- session.remove(key)
315
- session.clearAll()
316
-
317
- ```
318
-
319
- ### locationParam
320
-
321
- ```js
322
- parse(paramString):
323
- `if paramString is undefined, paramString=window.location.search`
324
- `return all params Key Pair object`
325
-
326
- paramSearch(name, target):
327
- `if target is undefined, default window.location.search`
328
- `and if name is undefined too `
329
- `return keyValueObjec; else if name not empty return value;`
330
-
331
- getLocationParams():
332
- `get all locationParams, and return a key-value object`
333
-
334
- getLocationParamByName(name):
335
- `get param value by name, and return value or null`
336
-
337
- getParameter(url, name):
338
- `get target url Parameter by name, and return value or '' `
339
-
340
- `LocationSearch` LocationParam.LocationSearch
341
- `other search tool`
342
- private: _keyValuePairs
343
- public:
344
- init():
345
- `init this tool,set private property _keyValuePairs and return a LocationSearch`
346
- getValue(key):
347
- `return target value`
348
- getParameters():
349
- `return all param value`
350
- ```
351
-
352
- ### array2tree
353
-
354
- ```js
355
-
356
- import { array2tree } from 'amos-tool';
357
-
358
- const data = [{
359
- value: 'a',
360
- children: [{
361
- value: 'b',
362
- children: [{
363
- value: 'c'
364
- }, {
365
- value: 'd',
366
- }]
367
- }],
368
- }];
369
- const values = ['a', 'b', 'c'];
370
- const result = array2tree(
371
- data, (item, level) => item.value === values[level]
372
- );
373
-
374
- console.log(result);
375
- // [
376
- // { value: 'a', children: [...] },
377
- // { value: 'b', children: [...] },
378
- // { value: 'c', children: [...] }
379
- // ]
380
-
381
- ```
382
-
383
- ### tableFilter
384
-
385
- ```js
386
- getChildrenlength(children)
387
-
388
- flatToHierarchy(arr)
389
-
390
- filterParentPosition(arr)
391
-
392
- isInclude(smallArray, bigArray)
393
- /**
394
- * 过滤数据
395
- *
396
- * @param {Array} vals 数据集合
397
- * @param {any} treeData tree数据
398
- * @returns
399
- */
400
- filterAllCheckedData(vals, treeData)
401
-
402
- /**
403
- * 递归
404
- *
405
- * @param {any} children
406
- * @param {any} cb
407
- */
408
- recursive(children, cb)
409
- ```
410
-
411
- ### pwdPolicy
412
-
413
- ```js
414
-
415
- /**
416
- * 普通密码生成策略
417
- * @param {string} password
418
- * @return {object} { password, secretKey }
419
- */
420
- normalPolicy(password)
421
-
422
- /**
423
- * 普通密码生成策略
424
- * @param {string} password 密码
425
- * @param {string} secretKey 秘钥
426
- * @return {object} { password, secretKey }
427
- */
428
- advancePolicy(password, secretKey)
429
-
430
- /**
431
- * 采用MD5生成密码 (不可逆)
432
- * @param {string} password
433
- * @param {string} secretKey
434
- */
435
- useMd5Policy(password, secretKey)
436
- ```
437
-
438
- ### omit
439
-
440
- ```js
441
- const ilex = {name: 'ilex', age: 18};
442
- const copy = omit(ilex, ['']); // {name: 'ilex', age: 18};
443
-
444
- const copy = omit(ilex, ['age']); // {name: 'ilex'}
445
- const copy = omit(ilex, ['name', 'age']); // {}
446
-
447
- ```
448
-
449
- ### pick
450
-
451
- ```js
452
- const ilex = {name: 'ilex', age: 18};
453
- const copy = pick(ilex, ['']); // {};
454
-
455
- const copy = pick(ilex, ['age']); // {age: 18}
456
- const copy = pick(ilex, ['name', 'age']); // {name: 'ilex', age: 18}
457
-
458
- ```
459
-
460
- ### utils
461
-
462
- ```js
463
- isString(obj);
464
- // Is a given value an array?
465
- // Delegates to ECMA5's native Array.isArray
466
- `If you want to judge object and judge array, you need to judge array first`
467
- isArray(obj);
468
- // Is a given variable an object?
469
- isObject(obj);
470
- // Is a given array, string, or object empty?
471
- // An "empty" object has no enumerable own-properties.
472
- isEmpty(objOrArray);
473
- // Is a given value equal to null?
474
- isNull(obj);
475
- // Is a given variable undefined?
476
- isUndefined(obj);
477
- // Is json
478
- isJson(obj);
479
- // is image src,支持的格式(jpe?g|png|gif|bmp|ico|tga) 及其 base64 格式
480
- isImageSrc(url);
481
- /**
482
- * 将数字部分内容转化为 *
483
- * @param {Number} number 目标 Number
484
- * @param {Number} start 起始位置
485
- * @param {Number} len 转换位数
486
- * @param {String} sign 替换的字符
487
- */
488
- encodeNumber(number, start = 3, len = 4, sign = '*');
489
- /**
490
- * some
491
- * some 为数组中的每一个元素执行一次 callback 函数,直到找到一个使得 callback 返回一个“真值”
492
- * @param {Array} arr
493
- * @param {function} fun
494
- */
495
- some(arr, fun /*, thisArg */ );
496
- //
497
- every(arr, callbackfn, thisArg);
498
- //
499
- reduce(arr, callback /*, initialValue*/);
500
-
501
- mergeAll(targetAndSources, overwrite);
502
-
503
- merge(target, source, overwrite);
504
-
505
- clone(source);
506
- ```
507
-
508
- ### xss
509
-
510
- ```js
511
- import htmlEncode from 'amos-tool/lib/xss/htmlEncode';
512
- import implementEncode from 'amos-tool/lib/xss/implementEncode';
513
-
514
- htmlEncode('<'); // &lt
515
- htmlEncode('>'); // &gt
516
- htmlEncode('\''); // &#39;
517
- htmlEncode('\"'); // &quot;
518
- ...
519
-
520
- implementEncode('<script language=text/javascript>alert(document.cookie);</script>');
521
- implementEncode('</script>');
522
- implementEncode(' eval(abc);');
523
- implementEncode('<img src="" onerror="alert(document.cookie);"></img>');
524
- ...
525
- ```
526
-
527
- ### strUtils
528
-
529
- ```js
530
- toCapitalStr(obj);
531
- // 驼峰化, 仅支持首字母大写、或者采用中杠连接的两个字母首字母大写
532
- // 如果要支持其它输入,将正则改为: /(-|(\s+)|_)(\w)/g
533
- camelCase(obj);
534
- // 将中缸连接的字符串 驼峰化
535
- transCamel(obj);
536
- // 字符串首字母大写
537
- capFirst(objOrArray);
538
- // 获取字符串的hashCode码
539
- hashCode(obj);
540
- // 进制与单位处理
541
- dealScaleAndUnit(obj);
542
- ```
543
-
544
- ### other
545
-
546
- * cookie:
547
-
548
- * isNode
549
- isNode();
550
-
551
- * objectAssign:
552
-
553
- objectAssign(target, source);
554
-
555
- * parseJson:
556
-
557
- parseJson(data)
558
-
559
- * stringify:
560
-
561
- stringify(json)
562
-
563
- * supportWs:
564
-
565
- supportWs()
566
-
567
- * trim:
568
-
569
- trim(str)
570
-
571
- * arrayFilter:
572
-
573
- * merged:
574
-
575
- merged(args): combine object property
576
-
577
- * objectPath
578
-
579
- @see [doc/objectPath.md](doc/objectPath.md)
580
-
581
- * random
582
-
583
- random(len)
584
- random.randomInt(min, max)
585
-
586
- #### extra
587
-
588
- * pathToTree
589
-
590
- ```js
591
- import pathToTree from 'amos-tool/lib/extra/pathToTree';
592
-
593
- const arr = [
594
- 'main/lib',
595
- 'console/tt/design1',
596
- 'console/mm/vizlib'
597
- ];
598
-
599
- const mapper = {
600
- main: 'RootView',
601
- console: 'ConsoleView'
602
- };
603
-
604
- var result1 = pathToTree(arr, {
605
- pathKey: 'path',
606
- childrenKey: 'childRoutes',
607
- processor(item, wantedNode){
608
- if (mapper[wantedNode]){
609
- item.component = mapper[wantedNode];
610
- }
611
- }
612
- });
613
- ```
614
-
615
- #### dom
616
-
617
- * canvas2img
618
-
619
- > saveAsImage(canvas/*canvasElement*/, width, height, type)
620
- > saveAsPNG(canvas, width, height)
621
- > saveAsGIF(canvas, width, height)
622
- > saveAsBMP(canvas, width, height)
623
- > convert2Image(canvas, width, height, type)
624
- > convert2data(canvas, type, width, height)
625
- > convert2Blob
626
-
627
- ```js
628
- /**
629
- * @param {Canvas} canvas
630
- * @param {function} fn (blob) => {}
631
- * @param {Object} options {
632
- * type: '', // 图片类型 默认 'image/png',其它类型详见MIME手册
633
- * width: number, //
634
- * height: number, //
635
- * encoderOptions: 0-1 // 图片质量
636
- * }
637
- */
638
- convert2Blob(canvas, fn, options)
639
- ```
640
-
641
- > convert2PNG(canvas, width, height)
642
- > convert2JPEG(canvas, width, height)
643
- > convert2GIF(canvas, width, height)
644
- > convert2BMP(canvas, width, height)
645
-
646
- ## changelog
647
-
648
- * v1.4.1
649
- `*` add `pathToRoutes`
650
-
651
- * v1.4.0
652
- `*` add `pathToTree` to calc react router path
653
-
654
- * v1.3.21
655
- `*` modify colorUtil
656
-
657
- * v1.3.19
658
- `*` modify colorUtil
659
- `*` modify `utils#getFileExtension`
660
- `*` modify `index.d.ts`
661
-
662
- * v1.3.14
663
- `*` modify cookie encode method
664
- `+` browser/indexDB
665
- * v1.3.13
666
- `+` htmlEncode
667
- `+` implementEncode
1
+ # amos-tool
2
+
3
+ by ilex.h
4
+
5
+ docs: [docs](https://unpkg.com/amos-tool@latest/docs/index.html)
6
+
7
+ ## useage
8
+
9
+ npm install --save amos-tool
10
+
11
+ ## keywords
12
+
13
+ * amos ui
14
+ * amos tool
15
+
16
+ ## infos
17
+
18
+ [![install size](https://packagephobia.now.sh/badge?p=amos-tool)](https://packagephobia.now.sh/result?p=amos-tool)
19
+
20
+ ## api
21
+
22
+ |name|link|description|
23
+ |------|------|------|
24
+ |Base64|[Base64](#base64)|`base64加密解密`|
25
+ |MD5|[MD5](#md5)|`md5加密解密`|
26
+ |DES|[DES](#des)|`des加密解密`|
27
+ |Browser|[Browser](#browser)|`获取浏览器类型`|
28
+ |deepCopy|[deepCopy](#deepCopy)|`深度复制`|
29
+ |deepEqual|[deepEqual](#deepEqual)|`深度比较(stringify方式)`|
30
+ |fastDeepEqual|[fastDeepEqual](#fastDeepEqual)|`深度比较(循环)`|
31
+ |parseText|[parseText](#parseText)|`替换或者补全url`|
32
+ |List|[List](#list)|`List集合`|
33
+ |Queue|[Queue](#queue)|`队列`|
34
+ |UUID|[UUID](#uuid)|`uuid`|
35
+ |browserSupport|[browserSupport](#browserSupport)|`浏览器支持`|
36
+ |Log|[Log](#log)|`定制化的log日志`|
37
+ |Store|[Store](#store)|`数据处理,主要是localStorage、session、cookie`|
38
+ |LocationParam|[LocationParam](#locationParam)|`location 工具`|
39
+ |array2tree|[array2tree](#array2tree)|`将array转化为tree数据`|
40
+ |tableFilter|[tableFilter](#tableFilter)|`表格数据过滤`|
41
+ |pwdPolicy|[pwdPolicy](#pwdPolicy)|`密码生成器`|
42
+ |omit|[omit](#omit)|`omit操作,删除object中的键`|
43
+ |pick|[pick](#pick)|`pick操作,获取object指定key组成的新对象`|
44
+ |utils|[utils](#utils)|`常用工具`|
45
+ |xss|[utils](#xss)|`xss 工具及`|
46
+ |strUtils|[strUtils](#strUtils)|`string常用工具`|
47
+ |other|[other](#other)|`其它工具集`|
48
+
49
+ ### base64
50
+
51
+ ```js
52
+ import { Base64 } from 'amos-tool';
53
+ // or import Base64 from 'amos-tool/lib/encrypt/_base64';
54
+
55
+ var b64 = new Base64();
56
+
57
+ b64.encode(input);
58
+ b64.decode(input);
59
+ ```
60
+
61
+ ### md5
62
+
63
+ ```js
64
+ import { MD5 } from 'amos-tool';
65
+ // or import MD5 from 'amos-tool/lib/encrypt/_md5';
66
+
67
+ var result = MD5('value'); // 2063c1608d6e0baf80249c42e2be5804
68
+ var result = MD5('value', 'key'); // 01433efd5f16327ea4b31144572c67f6
69
+ var result = MD5('value', null, true); // 'c\xc1`\x8dn\x0b\xaf\x80$\x9cB\xe2\xbeX\x04'
70
+ var result = MD5('value', 'key', true); // '\x01C>\xfd_\x162~\xa4\xb3\x11DW,g\xf6'
71
+ ```
72
+
73
+ ### des
74
+
75
+ > 注意,加密解密时,第一个 `秘钥` 不能为空
76
+
77
+ ```js
78
+ DES.DesCore.encode(data, firstKey, secondKey, thirdKey)
79
+ DES.DesCore.decode(data, firstKey, secondKey, thirdKey)
80
+
81
+ DES.encode(data, secretKey);
82
+ DES.decode(data, secretKey);
83
+ ```
84
+
85
+ * example
86
+
87
+ ```js
88
+ import { DES } from 'amos-tool';
89
+ // or import DES from 'amos-tool/lib/encrypt/des';
90
+
91
+ const desCore = DES.DesCore;
92
+
93
+ desCore.encode('123456', 'a'); // 484FD6D18A5501370873DB5F557A23F9
94
+ desCore.encode('123456', 'a', 'b'); // 953AFFF48E49E4B94D8B74AABB6905E5
95
+ desCore.encode('123456', 'a', 'b', 'c'); // 7C49B05CCBCBEECC5665732A177E624B
96
+
97
+ desCore.decode('484FD6D18A5501370873DB5F557A23F9', 'a'); // 123456
98
+ desCore.decode('953AFFF48E49E4B94D8B74AABB6905E5', 'a', 'b'); // 123456
99
+ desCore.decode('7C49B05CCBCBEECC5665732A177E624B', 'a', 'b', 'c'); // 123456
100
+
101
+
102
+ DES.encode('123456', 'a'); // 484FD6D18A5501370873DB5F557A23F9
103
+ DES.encode('123456', 'a,b'); // 953AFFF48E49E4B94D8B74AABB6905E5
104
+ DES.encode('123456', 'a,b,c'); // 7C49B05CCBCBEECC5665732A177E624B
105
+
106
+ DES.decode('484FD6D18A5501370873DB5F557A23F9', 'a'); // 123456
107
+ DES.decode('953AFFF48E49E4B94D8B74AABB6905E5', 'a,b'); // 123456
108
+ DES.decode('7C49B05CCBCBEECC5665732A177E624B', 'a,b,c'); // 123456
109
+ ```
110
+
111
+ > 注意:
112
+
113
+ secretKey 'a,b,c' 与 `a, b,c` 不同,识别空格。 支持3个秘钥,采用 `,` 分割
114
+
115
+ 同时,`DES.DesCore` 第一个 key 值不可以为 空('', undefined, null)
116
+
117
+ ### browser
118
+
119
+ ```js
120
+ Browser.isFirefox();
121
+ Browser.isIE();
122
+ Browser.isEdge();
123
+ Browser.isChrome();
124
+ Browser.isSafari();
125
+ ```
126
+
127
+ ### deepCopy
128
+
129
+ ```js
130
+ import { deepCopy } from 'amos-tool';
131
+
132
+ deepCopy(source);
133
+
134
+ import deepCopy, { eq } from 'amos-tool/lib/_deepCopy';
135
+
136
+ eq(value, other)
137
+ ```
138
+
139
+ ### deepEqual
140
+
141
+ ```js
142
+ deepEqual(valA, valB);
143
+ ```
144
+
145
+ ### fastDeepEqual
146
+
147
+ ```js
148
+ fastDeepEqual(valA, valB);
149
+ ```
150
+
151
+ ### parseText
152
+
153
+ ```js
154
+
155
+ /**
156
+ * 解析数据
157
+ * @param {string} text
158
+ * @param {object} dataObj
159
+ * @param {string|RegExp} regexps 可选
160
+ * @doc parseText('a/{b}/{c}/d',{a: 1, b:2}) 返回: 'a/1/2/d'
161
+ * @doc parseText('a/b?name={name}&pwd={pwd}',{name: 'ilex', pwd:122}) 返回: 'a/b?name=ilex&pwd=123'
162
+ */
163
+ parseText(text, dataObj, regexps);
164
+ ```
165
+
166
+ ### list
167
+ ```js
168
+ List props:
169
+
170
+ ArrayList: var arrlist = new List.ArrayList();
171
+ parse2string: List.parse2string(obj)
172
+ parse2object: List.parse2object(str)
173
+ simpleEqual: List.simpleEqual(objA, objB)
174
+ isObject: List.isObject(obj)
175
+
176
+ // ArrayList
177
+ var arrlist = new List.ArrayList();
178
+
179
+ arrlist.size(); // get size of list
180
+ arrlist.values();// all values
181
+ arrlist.isEmpty();// check empty
182
+ arrlist.iterator(callBack);// iterator
183
+ arrlist.get(index);// 取得指定下标的值
184
+ arrlist.add(value); // add item
185
+ arrlist.addAll(value);// add all item, value is a arrayList
186
+ arrlist.set(index, value);// 设置值
187
+ arrlist.remove(value);// remove item
188
+ arrlist.removeAt(index); // //remove item by index
189
+ arrlist.indexOf(value); // get item index from list
190
+ arrlist.clear(); // clear list
191
+ arrlist.insert(index, value); // insert item in index place
192
+ arrlist.updateValue(key, value); // use value[key] check equal
193
+ ```
194
+
195
+ ### queue
196
+ ```js
197
+ var q = new Queue;
198
+ q.push(obj) // 入队
199
+ q.pop();// 出队
200
+ q.head();// 返回队列中头部(即最新添加的)的动态对象
201
+ q.tail();// 返回队列中尾部(即最早添加的)的动态对象
202
+ q.length();// 返回数据队列长度
203
+ q.empty(); // 队列是否为空
204
+ q.clear(); // 清空
205
+ ```
206
+
207
+ ### uuid
208
+
209
+ ```js
210
+ uuid(len, radix); // radix must be <= 62 , uuid(8, 2)
211
+ uuidFast();
212
+ uuidCompact();
213
+ timeUUID(prefix = 'amos-timeuuid');
214
+ longTimeUUID(prefix = 'longtime');
215
+ otherUUID(tpl = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'); // 同 uuidCompact,无 '-'
216
+ ```
217
+
218
+ ### browserSupport
219
+
220
+ * apis
221
+
222
+ ```js
223
+ simpleuse:
224
+ defaultConfig: ['firefox/51.0', 'chrome/56']
225
+ browserSupport();
226
+ browserSupport('firefox/51.0');
227
+ browserSupport(['firefox/51.0', 'chrome/56']);
228
+ withMatchs:
229
+ muitlConfig: ['firefox/', 'chrome/'];
230
+ browserSupport(null, {
231
+ 'firefox/': {limit: consts.GREATER_EQUAL, version: 51},
232
+ 'chrome/': {limit: consts.GREATER_EQUAL, version: 56}
233
+ });
234
+
235
+ browserSupport('firefox/', {limit: consts.GREATER_EQUAL, version: 51});
236
+
237
+ browserSupport(['firefox/', 'chrome/'], {
238
+ 'firefox/': {limit: consts.GREATER_EQUAL, version: 51},
239
+ 'chrome/': {limit: consts.GREATER_EQUAL, version: 56}
240
+ });
241
+
242
+ consts:
243
+ GREATER: 1, // 大于
244
+ EQUAL: 2, // 等于
245
+ LESS: 3, // 小于
246
+ GREATER_EQUAL: 4, // 大于等于
247
+ LESS_EQUAL: 5 // 小于等于
248
+ ```
249
+
250
+ * demo
251
+
252
+ ```js
253
+ // 基本使用
254
+ const result = browserSupport();
255
+
256
+ const paramsList = ['firefox/', 'chrome/', 'ie'];
257
+ const limit = {
258
+ 'firefox/': { limit: consts.GREATER_EQUAL, version: 50 },
259
+ 'chrome/': { limit: consts.GREATER_EQUAL, version: 55 },
260
+ 'ie': { limit: consts.GREATER_EQUAL, version: 6 }
261
+ };
262
+
263
+ // 自定义使用 (注意适配ie时 写法)
264
+ const result2 = browserSupport(paramsList, limit);
265
+ ```
266
+
267
+ ### log
268
+
269
+ ```js
270
+
271
+ window.LogConfig
272
+ window.LogConfig.isDebug
273
+
274
+ Log.trace()
275
+ Log.debug()
276
+ Log.info()
277
+ Log.warn()
278
+ Log.error()
279
+ Log.fatal()
280
+
281
+ // 展示 pkg 信息,不受 LogConfig 配置影响
282
+ Log.pkgInfo(name, version)
283
+
284
+ ```
285
+
286
+ ### store
287
+
288
+ ```js
289
+ `default function list`
290
+ // 所有的cookie数据,均采用 escape/unescape 进行转码、解码
291
+ encrypt(str) // 加密
292
+ decrypt(str) // 解密
293
+ setCookieByDays(name, value, days)
294
+ getAllCookies() // 获取所有的cookie,同时每个key对应的value,均执行了 JSON.parse(value)
295
+ setCookieByHour(name, value, hour)
296
+ getCookieByName(name)
297
+ removeCookieByName(name)
298
+ clearAllCookie()
299
+
300
+ `localStorage`
301
+
302
+ const ls = Store.lsTool;
303
+
304
+ ls.read(key)
305
+ ls.write(key, data)
306
+ ls.each(fn)
307
+ ls.remove(key)
308
+ ls.clearAll()
309
+
310
+ `sessionStorage`
311
+
312
+ const session = Store.session;
313
+
314
+ session.read(key)
315
+ session.write(key, data)
316
+ session.each(fn)
317
+ session.remove(key)
318
+ session.clearAll()
319
+
320
+ ```
321
+
322
+ ### locationParam
323
+
324
+ ```js
325
+ parse(paramString):
326
+ `if paramString is undefined, paramString=window.location.search`
327
+ `return all params Key Pair object`
328
+
329
+ paramSearch(name, target):
330
+ `if target is undefined, default window.location.search`
331
+ `and if name is undefined too `
332
+ `return keyValueObjec; else if name not empty return value;`
333
+
334
+ getLocationParams():
335
+ `get all locationParams, and return a key-value object`
336
+
337
+ getLocationParamByName(name):
338
+ `get param value by name, and return value or null`
339
+
340
+ getParameter(url, name):
341
+ `get target url Parameter by name, and return value or '' `
342
+
343
+ `LocationSearch` LocationParam.LocationSearch
344
+ `other search tool`
345
+ private: _keyValuePairs
346
+ public:
347
+ init():
348
+ `init this tool,set private property _keyValuePairs and return a LocationSearch`
349
+ getValue(key):
350
+ `return target value`
351
+ getParameters():
352
+ `return all param value`
353
+ ```
354
+
355
+ ### array2tree
356
+
357
+ ```js
358
+
359
+ import { array2tree } from 'amos-tool';
360
+
361
+ const data = [{
362
+ value: 'a',
363
+ children: [{
364
+ value: 'b',
365
+ children: [{
366
+ value: 'c'
367
+ }, {
368
+ value: 'd',
369
+ }]
370
+ }],
371
+ }];
372
+ const values = ['a', 'b', 'c'];
373
+ const result = array2tree(
374
+ data, (item, level) => item.value === values[level]
375
+ );
376
+
377
+ console.log(result);
378
+ // [
379
+ // { value: 'a', children: [...] },
380
+ // { value: 'b', children: [...] },
381
+ // { value: 'c', children: [...] }
382
+ // ]
383
+
384
+ ```
385
+
386
+ ### tableFilter
387
+
388
+ ```js
389
+ getChildrenlength(children)
390
+
391
+ flatToHierarchy(arr)
392
+
393
+ filterParentPosition(arr)
394
+
395
+ isInclude(smallArray, bigArray)
396
+ /**
397
+ * 过滤数据
398
+ *
399
+ * @param {Array} vals 数据集合
400
+ * @param {any} treeData tree数据
401
+ * @returns
402
+ */
403
+ filterAllCheckedData(vals, treeData)
404
+
405
+ /**
406
+ * 递归
407
+ *
408
+ * @param {any} children
409
+ * @param {any} cb
410
+ */
411
+ recursive(children, cb)
412
+ ```
413
+
414
+ ### pwdPolicy
415
+
416
+ ```js
417
+
418
+ /**
419
+ * 普通密码生成策略
420
+ * @param {string} password
421
+ * @return {object} { password, secretKey }
422
+ */
423
+ normalPolicy(password)
424
+
425
+ /**
426
+ * 普通密码生成策略
427
+ * @param {string} password 密码
428
+ * @param {string} secretKey 秘钥
429
+ * @return {object} { password, secretKey }
430
+ */
431
+ advancePolicy(password, secretKey)
432
+
433
+ /**
434
+ * 采用MD5生成密码 (不可逆)
435
+ * @param {string} password
436
+ * @param {string} secretKey
437
+ */
438
+ useMd5Policy(password, secretKey)
439
+ ```
440
+
441
+ ### omit
442
+
443
+ ```js
444
+ const ilex = {name: 'ilex', age: 18};
445
+ const copy = omit(ilex, ['']); // {name: 'ilex', age: 18};
446
+
447
+ const copy = omit(ilex, ['age']); // {name: 'ilex'}
448
+ const copy = omit(ilex, ['name', 'age']); // {}
449
+
450
+ ```
451
+
452
+ ### pick
453
+
454
+ ```js
455
+ const ilex = {name: 'ilex', age: 18};
456
+ const copy = pick(ilex, ['']); // {};
457
+
458
+ const copy = pick(ilex, ['age']); // {age: 18}
459
+ const copy = pick(ilex, ['name', 'age']); // {name: 'ilex', age: 18}
460
+
461
+ ```
462
+
463
+ ### utils
464
+
465
+ ```js
466
+ isString(obj);
467
+ // Is a given value an array?
468
+ // Delegates to ECMA5's native Array.isArray
469
+ `If you want to judge object and judge array, you need to judge array first`
470
+ isArray(obj);
471
+ // Is a given variable an object?
472
+ isObject(obj);
473
+ // Is a given array, string, or object empty?
474
+ // An "empty" object has no enumerable own-properties.
475
+ isEmpty(objOrArray);
476
+ // Is a given value equal to null?
477
+ isNull(obj);
478
+ // Is a given variable undefined?
479
+ isUndefined(obj);
480
+ // Is json
481
+ isJson(obj);
482
+ // is image src,支持的格式(jpe?g|png|gif|bmp|ico|tga) 及其 base64 格式
483
+ isImageSrc(url);
484
+ /**
485
+ * 将数字部分内容转化为 *
486
+ * @param {Number} number 目标 Number
487
+ * @param {Number} start 起始位置
488
+ * @param {Number} len 转换位数
489
+ * @param {String} sign 替换的字符
490
+ */
491
+ encodeNumber(number, start = 3, len = 4, sign = '*');
492
+ /**
493
+ * some
494
+ * some 为数组中的每一个元素执行一次 callback 函数,直到找到一个使得 callback 返回一个“真值”
495
+ * @param {Array} arr
496
+ * @param {function} fun
497
+ */
498
+ some(arr, fun /*, thisArg */ );
499
+ //
500
+ every(arr, callbackfn, thisArg);
501
+ //
502
+ reduce(arr, callback /*, initialValue*/);
503
+
504
+ mergeAll(targetAndSources, overwrite);
505
+
506
+ merge(target, source, overwrite);
507
+
508
+ clone(source);
509
+ ```
510
+
511
+ ### xss
512
+
513
+ ```js
514
+ import htmlEncode from 'amos-tool/lib/xss/htmlEncode';
515
+ import implementEncode from 'amos-tool/lib/xss/implementEncode';
516
+
517
+ htmlEncode('<'); // &lt
518
+ htmlEncode('>'); // &gt
519
+ htmlEncode('\''); // &#39;
520
+ htmlEncode('\"'); // &quot;
521
+ ...
522
+
523
+ implementEncode('<script language=text/javascript>alert(document.cookie);</script>');
524
+ implementEncode('</script>');
525
+ implementEncode(' eval(abc);');
526
+ implementEncode('<img src="" onerror="alert(document.cookie);"></img>');
527
+ ...
528
+ ```
529
+
530
+ ### strUtils
531
+
532
+ ```js
533
+ toCapitalStr(obj);
534
+ // 驼峰化, 仅支持首字母大写、或者采用中杠连接的两个字母首字母大写
535
+ // 如果要支持其它输入,将正则改为: /(-|(\s+)|_)(\w)/g
536
+ camelCase(obj);
537
+ // 将中缸连接的字符串 驼峰化
538
+ transCamel(obj);
539
+ // 字符串首字母大写
540
+ capFirst(objOrArray);
541
+ // 获取字符串的hashCode码
542
+ hashCode(obj);
543
+ // 进制与单位处理
544
+ dealScaleAndUnit(obj);
545
+ ```
546
+
547
+ ### other
548
+
549
+ * cookie:
550
+
551
+ * isNode
552
+ isNode();
553
+
554
+ * objectAssign:
555
+
556
+ objectAssign(target, source);
557
+
558
+ * parseJson:
559
+
560
+ parseJson(data)
561
+
562
+ * stringify:
563
+
564
+ stringify(json)
565
+
566
+ * supportWs:
567
+
568
+ supportWs()
569
+
570
+ * trim:
571
+
572
+ trim(str)
573
+
574
+ * arrayFilter:
575
+
576
+ * merged:
577
+
578
+ merged(args): combine object property
579
+
580
+ * objectPath
581
+
582
+ @see [doc/objectPath.md](doc/objectPath.md)
583
+
584
+ * random
585
+
586
+ random(len)
587
+ random.randomInt(min, max)
588
+
589
+ #### extra
590
+
591
+ * pathToTree
592
+
593
+ ```js
594
+ import pathToTree from 'amos-tool/lib/extra/pathToTree';
595
+
596
+ const arr = [
597
+ 'main/lib',
598
+ 'console/tt/design1',
599
+ 'console/mm/vizlib'
600
+ ];
601
+
602
+ const mapper = {
603
+ main: 'RootView',
604
+ console: 'ConsoleView'
605
+ };
606
+
607
+ var result1 = pathToTree(arr, {
608
+ pathKey: 'path',
609
+ childrenKey: 'childRoutes',
610
+ processor(item, wantedNode){
611
+ if (mapper[wantedNode]){
612
+ item.component = mapper[wantedNode];
613
+ }
614
+ }
615
+ });
616
+ ```
617
+
618
+ #### dom
619
+
620
+ * canvas2img
621
+
622
+ > saveAsImage(canvas/*canvasElement*/, width, height, type)
623
+ > saveAsPNG(canvas, width, height)
624
+ > saveAsGIF(canvas, width, height)
625
+ > saveAsBMP(canvas, width, height)
626
+ > convert2Image(canvas, width, height, type)
627
+ > convert2data(canvas, type, width, height)
628
+ > convert2Blob
629
+
630
+ ```js
631
+ /**
632
+ * @param {Canvas} canvas
633
+ * @param {function} fn (blob) => {}
634
+ * @param {Object} options {
635
+ * type: '', // 图片类型 默认 'image/png',其它类型详见MIME手册
636
+ * width: number, // 宽
637
+ * height: number, // 高
638
+ * encoderOptions: 0-1 // 图片质量
639
+ * }
640
+ */
641
+ convert2Blob(canvas, fn, options)
642
+ ```
643
+
644
+ > convert2PNG(canvas, width, height)
645
+ > convert2JPEG(canvas, width, height)
646
+ > convert2GIF(canvas, width, height)
647
+ > convert2BMP(canvas, width, height)
648
+
649
+ ## changelog
650
+
651
+ * v1.4.1
652
+ `*` add `pathToRoutes`
653
+
654
+ * v1.4.0
655
+ `*` add `pathToTree` to calc react router path
656
+
657
+ * v1.3.21
658
+ `*` modify colorUtil
659
+
660
+ * v1.3.19
661
+ `*` modify colorUtil
662
+ `*` modify `utils#getFileExtension`
663
+ `*` modify `index.d.ts`
664
+
665
+ * v1.3.14
666
+ `*` modify cookie encode method
667
+ `+` browser/indexDB
668
+ * v1.3.13
669
+ `+` htmlEncode
670
+ `+` implementEncode