mazey 3.5.4 → 3.6.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.
- package/README.md +90 -51
- package/README_CN.md +4 -2
- package/lib/index.cjs.js +3607 -2753
- package/lib/index.d.ts +274 -42
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +3602 -2754
- package/lib/mazey.min.js +2 -2
- package/package.json +1 -1
- package/scripts/env.sh +2 -0
- package/src/index.ts +328 -45
- package/src/preview.js +0 -44
package/README.md
CHANGED
|
@@ -92,10 +92,9 @@ There ara some examples maintained by hand below. For more information, please c
|
|
|
92
92
|
* [calLongestCommonSubsequence](#callongestcommonsubsequence)
|
|
93
93
|
- [Browser Information](#browser-information)
|
|
94
94
|
* [getBrowserInfo](#getbrowserinfo)
|
|
95
|
+
* [isSafePWAEnv](#issafepwaenv)
|
|
95
96
|
- [Web Performance](#web-performance)
|
|
96
97
|
* [getPerformance](#getperformance)
|
|
97
|
-
- [Margin of Safety](#margin-of-safety)
|
|
98
|
-
* [isSafePWAEnv](#issafepwaenv)
|
|
99
98
|
- [Debug](#debug)
|
|
100
99
|
* [genCustomConsole](#gencustomconsole)
|
|
101
100
|
<!-- toc - end -->
|
|
@@ -208,7 +207,8 @@ isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
|
|
|
208
207
|
<!-- @param {*} num 被判断的值
|
|
209
208
|
@param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
|
|
210
209
|
@param {boolean} options.isUnFiniteAsNumber 是否 无限 算数字(默认不算)
|
|
211
|
-
@returns {boolean} true 是数字
|
|
210
|
+
@returns {boolean} true 是数字
|
|
211
|
+
@category Util -->
|
|
212
212
|
|
|
213
213
|
#### generateRndNum
|
|
214
214
|
|
|
@@ -219,6 +219,10 @@ generateRndNum(4); // '9730'
|
|
|
219
219
|
generateRndNum(7); // '2262490'
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
+
<!-- @param {number} n Length
|
|
223
|
+
@returns {string} Return the random string.
|
|
224
|
+
@category Util -->
|
|
225
|
+
|
|
222
226
|
#### isJsonString
|
|
223
227
|
|
|
224
228
|
Check whether it is a valid JSON string.
|
|
@@ -238,7 +242,8 @@ true
|
|
|
238
242
|
```
|
|
239
243
|
|
|
240
244
|
<!-- @param {string} str The string to check.
|
|
241
|
-
@returns {boolean} Return the result of checking.
|
|
245
|
+
@returns {boolean} Return the result of checking.
|
|
246
|
+
@category Util -->
|
|
242
247
|
|
|
243
248
|
#### formatDate
|
|
244
249
|
|
|
@@ -264,7 +269,8 @@ Date formatDate value: 02/11/2014
|
|
|
264
269
|
|
|
265
270
|
<!-- @param {Date|number|string} dateIns Original Date
|
|
266
271
|
@param {string} format Format String
|
|
267
|
-
@returns {string} Return the formatted date string.
|
|
272
|
+
@returns {string} Return the formatted date string.
|
|
273
|
+
@category Util -->
|
|
268
274
|
|
|
269
275
|
#### debounce
|
|
270
276
|
|
|
@@ -278,6 +284,8 @@ const foo = debounce(() => {
|
|
|
278
284
|
}, 1000, true);
|
|
279
285
|
```
|
|
280
286
|
|
|
287
|
+
<!-- @category Util -->
|
|
288
|
+
|
|
281
289
|
#### throttle
|
|
282
290
|
|
|
283
291
|
Throttle
|
|
@@ -292,6 +300,8 @@ const foo = throttle(() => {
|
|
|
292
300
|
|
|
293
301
|
Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
|
|
294
302
|
|
|
303
|
+
<!-- @category Util -->
|
|
304
|
+
|
|
295
305
|
#### camelCaseToKebabCase
|
|
296
306
|
|
|
297
307
|
Transfer CamelCase to KebabCase.
|
|
@@ -302,7 +312,8 @@ camelCaseToKebabCase('aBC'); // a-b-c
|
|
|
302
312
|
```
|
|
303
313
|
|
|
304
314
|
<!-- @param {string} camelCase 'aBC' or 'ABC'
|
|
305
|
-
@returns {string} 'a-b-c'
|
|
315
|
+
@returns {string} 'a-b-c'
|
|
316
|
+
@category Util -->
|
|
306
317
|
|
|
307
318
|
#### camelCase2Underscore
|
|
308
319
|
|
|
@@ -314,7 +325,8 @@ camelCase2Underscore('aBC'); // a_b_c
|
|
|
314
325
|
```
|
|
315
326
|
|
|
316
327
|
<!-- @param {string} camelCase 'aBC' or 'ABC'
|
|
317
|
-
@returns {string} 'a_b_c'
|
|
328
|
+
@returns {string} 'a_b_c'
|
|
329
|
+
@category Util -->
|
|
318
330
|
|
|
319
331
|
#### mTrim
|
|
320
332
|
|
|
@@ -326,7 +338,8 @@ mTrim('abc '); // 'abc'
|
|
|
326
338
|
```
|
|
327
339
|
|
|
328
340
|
<!-- @param {string} str The string to trim.
|
|
329
|
-
@returns {string} Trimmed string.
|
|
341
|
+
@returns {string} Trimmed string.
|
|
342
|
+
@category Util -->
|
|
330
343
|
|
|
331
344
|
#### deepCopyObject
|
|
332
345
|
|
|
@@ -347,7 +360,8 @@ Output:
|
|
|
347
360
|
```
|
|
348
361
|
|
|
349
362
|
<!-- @param {object} obj The value to clone.
|
|
350
|
-
@returns {object} Returns the deep cloned value.
|
|
363
|
+
@returns {object} Returns the deep cloned value.
|
|
364
|
+
@category Util -->
|
|
351
365
|
|
|
352
366
|
#### isValidData
|
|
353
367
|
|
|
@@ -384,7 +398,8 @@ isValidDataResC: false
|
|
|
384
398
|
<!-- @param {any} data Original Data
|
|
385
399
|
@param {string[]} attributes Data Attributes
|
|
386
400
|
@param {any} validValue Given Value for verifying.
|
|
387
|
-
@returns {boolean} Return TRUE if the data is valid.
|
|
401
|
+
@returns {boolean} Return TRUE if the data is valid.
|
|
402
|
+
@category Util -->
|
|
388
403
|
|
|
389
404
|
### DOM
|
|
390
405
|
|
|
@@ -392,7 +407,9 @@ isValidDataResC: false
|
|
|
392
407
|
|
|
393
408
|
Add `<style>` in `<head>`.
|
|
394
409
|
|
|
395
|
-
|
|
410
|
+
<!-- ZH: 添加样式标签; style: 样式标签内的字符串; id: `<style>` 标签的 `id`; 返回: 添加成功/失败 -->
|
|
411
|
+
|
|
412
|
+
Example 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
|
|
396
413
|
|
|
397
414
|
```
|
|
398
415
|
addStyle(
|
|
@@ -412,7 +429,7 @@ addStyle(
|
|
|
412
429
|
// </style>
|
|
413
430
|
```
|
|
414
431
|
|
|
415
|
-
|
|
432
|
+
Example 2: Add the `<style>` without `id`, and repeated invoking will adding a new one.
|
|
416
433
|
|
|
417
434
|
```
|
|
418
435
|
addStyle(
|
|
@@ -429,6 +446,8 @@ addStyle(
|
|
|
429
446
|
// </style>
|
|
430
447
|
```
|
|
431
448
|
|
|
449
|
+
<!-- @category DOM -->
|
|
450
|
+
|
|
432
451
|
#### newLine
|
|
433
452
|
|
|
434
453
|
Make a newline of HTML.
|
|
@@ -438,6 +457,10 @@ newLine('a\nb\nc'); // 'a<br />b<br />c'
|
|
|
438
457
|
newLine('a\n\nbc'); // 'a<br /><br />bc'
|
|
439
458
|
```
|
|
440
459
|
|
|
460
|
+
<!-- @param {string} str The string to make a newline.
|
|
461
|
+
@returns {string} A newline with `br`.
|
|
462
|
+
@category DOM -->
|
|
463
|
+
|
|
441
464
|
#### Class
|
|
442
465
|
|
|
443
466
|
Modify `class`.
|
|
@@ -453,6 +476,8 @@ addClass(dom, 'test');
|
|
|
453
476
|
removeClass(dom, 'test');
|
|
454
477
|
```
|
|
455
478
|
|
|
479
|
+
<!-- @category DOM -->
|
|
480
|
+
|
|
456
481
|
### URL
|
|
457
482
|
|
|
458
483
|
#### getQueryParam
|
|
@@ -560,6 +585,8 @@ http://example.com/?t1=1&t2=2&t3=3&t4=four
|
|
|
560
585
|
|
|
561
586
|
Handle Storage (Keep fit for JSON, it can tansfer format automatically).
|
|
562
587
|
|
|
588
|
+
<!-- ZH: 存储/获取数据到 sessionStorage/localStorage -->
|
|
589
|
+
|
|
563
590
|
```
|
|
564
591
|
setSessionStorage('test', '123');
|
|
565
592
|
getSessionStorage('test'); // 123
|
|
@@ -577,15 +604,23 @@ function mGetLocalStorage (key) {
|
|
|
577
604
|
}
|
|
578
605
|
```
|
|
579
606
|
|
|
607
|
+
<!-- @param {string} key 键
|
|
608
|
+
@returns {any} 返回值
|
|
609
|
+
@category Cache Data -->
|
|
610
|
+
|
|
580
611
|
#### Cookie
|
|
581
612
|
|
|
582
613
|
Handle Cookie.
|
|
583
614
|
|
|
615
|
+
<!-- ZH: 设置/获取 Cookie -->
|
|
616
|
+
|
|
584
617
|
```
|
|
585
618
|
setCookie('test', '123', 30, 'example.com'); // key value day domain
|
|
586
619
|
getCookie('test'); // 123
|
|
587
620
|
```
|
|
588
621
|
|
|
622
|
+
<!-- @category Cache Data -->
|
|
623
|
+
|
|
589
624
|
### Calculate and Formula
|
|
590
625
|
|
|
591
626
|
#### inRate
|
|
@@ -623,7 +658,8 @@ console.log(trueCount, falseCount); // 499994 500006
|
|
|
623
658
|
```
|
|
624
659
|
|
|
625
660
|
<!-- @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
|
|
626
|
-
@returns {boolean} true 命中
|
|
661
|
+
@returns {boolean} true 命中
|
|
662
|
+
@category Calculate and Formula -->
|
|
627
663
|
|
|
628
664
|
#### calLongestCommonSubstring
|
|
629
665
|
|
|
@@ -645,7 +681,8 @@ Output:
|
|
|
645
681
|
|
|
646
682
|
<!-- @param {string} aStr String
|
|
647
683
|
@param {string} bStr String
|
|
648
|
-
@returns {number} Length
|
|
684
|
+
@returns {number} Length
|
|
685
|
+
@category Calculate and Formula -->
|
|
649
686
|
|
|
650
687
|
#### calLongestCommonSubsequence
|
|
651
688
|
|
|
@@ -667,7 +704,8 @@ Output:
|
|
|
667
704
|
|
|
668
705
|
<!-- @param {string} aStr 字符串
|
|
669
706
|
@param {string} bStr 字符串
|
|
670
|
-
@returns {number} 长度
|
|
707
|
+
@returns {number} 长度
|
|
708
|
+
@category Calculate and Formula -->
|
|
671
709
|
|
|
672
710
|
### Browser Information
|
|
673
711
|
|
|
@@ -691,18 +729,18 @@ Output:
|
|
|
691
729
|
|
|
692
730
|
Results:
|
|
693
731
|
|
|
694
|
-
|
|
|
695
|
-
| --- | --- | --- |
|
|
696
|
-
| System |
|
|
697
|
-
| System version |
|
|
698
|
-
| Platform |
|
|
699
|
-
| Engine |
|
|
700
|
-
| Engine version |
|
|
701
|
-
| Supporter |
|
|
702
|
-
| Supporter version |
|
|
703
|
-
| Shell |
|
|
704
|
-
| Shell version |
|
|
705
|
-
| Apple device type |
|
|
732
|
+
| Attribute | Description | Type | Values |
|
|
733
|
+
| --- | --- | --- | --- |
|
|
734
|
+
| **system** | System | string | android, ios, windows, macos, linux |
|
|
735
|
+
| systemVs | System version | string | windows: 2000, xp, 2003, vista, 7, 8, 8.1, 10 <br />macos: ... |
|
|
736
|
+
| platform | Platform | string | desktop, mobile |
|
|
737
|
+
| engine | Engine | string | webkit, gecko, presto, trident |
|
|
738
|
+
| engineVs | Engine version | string | - |
|
|
739
|
+
| supporter | Supporter | string | edge, opera, chrome, safari, firefox, iexplore |
|
|
740
|
+
| supporterVs | Supporter version | string | - |
|
|
741
|
+
| shell | Shell | string | (Optional) wechat, qq_browser, qq_app, uc, 360, 2345, sougou, liebao, maxthon, bilibili |
|
|
742
|
+
| shellVs | Shell version | string | (Optional) 20/... |
|
|
743
|
+
| appleType | Apple device type | string | (Optional) ipad, iphone, ipod, iwatch |
|
|
706
744
|
|
|
707
745
|
Example: Determine the environment of the mobile QQ.
|
|
708
746
|
|
|
@@ -714,6 +752,27 @@ const isMobileQQ = ['android', 'ios'].includes(system) && ['qq_browser', 'qq_app
|
|
|
714
752
|
<!-- @returns 浏览器信息
|
|
715
753
|
@category Browser Information -->
|
|
716
754
|
|
|
755
|
+
#### isSafePWAEnv
|
|
756
|
+
|
|
757
|
+
Detect the margin of Safety. Determine if it is a secure PWA environment that it can run.
|
|
758
|
+
|
|
759
|
+
<!-- ZH: 判断是否是安全的 PWA 环境 -->
|
|
760
|
+
|
|
761
|
+
Usage:
|
|
762
|
+
|
|
763
|
+
```
|
|
764
|
+
isSafePWAEnv();
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
Output:
|
|
768
|
+
|
|
769
|
+
```
|
|
770
|
+
true
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
<!-- @returns {boolean} true 是
|
|
774
|
+
@category Browser Information -->
|
|
775
|
+
|
|
717
776
|
### Web Performance
|
|
718
777
|
|
|
719
778
|
#### getPerformance
|
|
@@ -757,29 +816,8 @@ Results:
|
|
|
757
816
|
| Download | download_time | (Optional) responseEnd - responseStart |
|
|
758
817
|
|
|
759
818
|
<!-- @param {boolean} camelCase -- false(默认) 以下划线形式返回数据 true 以驼峰形式返回数据
|
|
760
|
-
@returns {Promise<object>} 加载数据
|
|
761
|
-
|
|
762
|
-
### Margin of Safety
|
|
763
|
-
|
|
764
|
-
#### isSafePWAEnv
|
|
765
|
-
|
|
766
|
-
Determine if it is a secure PWA environment that it can run.
|
|
767
|
-
|
|
768
|
-
<!-- ZH: 判断是否是安全的 PWA 环境 -->
|
|
769
|
-
|
|
770
|
-
Usage:
|
|
771
|
-
|
|
772
|
-
```
|
|
773
|
-
isSafePWAEnv();
|
|
774
|
-
```
|
|
775
|
-
|
|
776
|
-
Output:
|
|
777
|
-
|
|
778
|
-
```
|
|
779
|
-
true
|
|
780
|
-
```
|
|
781
|
-
|
|
782
|
-
<!-- @returns {boolean} true 是 -->
|
|
819
|
+
@returns {Promise<object>} 加载数据
|
|
820
|
+
@category Web Performance -->
|
|
783
821
|
|
|
784
822
|
### Debug
|
|
785
823
|
|
|
@@ -812,7 +850,8 @@ MazeyLog: I am object. {a: 123, b: 456}
|
|
|
812
850
|
@param {string} locales A locale string.
|
|
813
851
|
@param {function} logFn The function with Log.
|
|
814
852
|
@param {function} errorFn The function with Error.
|
|
815
|
-
@returns {object} 新实例
|
|
853
|
+
@returns {object} 新实例
|
|
854
|
+
@category Debug -->
|
|
816
855
|
|
|
817
856
|
## Contributing
|
|
818
857
|
|
package/README_CN.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
⚠️ Note: The document has expired, please check the latest [README.md](./README.md).
|
|
2
2
|
|
|
3
|
+
⚠️ 注意: 此文档只适用于 v1.4.39 版本,[查看 v3.x 版本的文档](./README.md)
|
|
4
|
+
|
|
3
5
|
# mazey
|
|
4
6
|
|
|
5
7
|
[![NPM version][npm-image]][npm-url]
|
|
@@ -10,7 +12,7 @@
|
|
|
10
12
|
[l-image]: https://img.shields.io/npm/l/mazey
|
|
11
13
|
[l-url]: https://github.com/mazeyqian/mazey
|
|
12
14
|
|
|
13
|
-
后除的 JavaScript
|
|
15
|
+
后除的 JavaScript 函数库,所有的方法都在线上项目中使用过
|
|
14
16
|
|
|
15
17
|
**目录**
|
|
16
18
|
|
|
@@ -338,7 +340,7 @@ myConsole.info('I am number.', 123, 456); // MazeyLog: I am number. 123 456
|
|
|
338
340
|
myConsole.info('I am object.', { a: 123, b: 456}); // MazeyLog: I am object. {a: 123, b: 456}
|
|
339
341
|
```
|
|
340
342
|
|
|
341
|
-
[更多接口>>](https://mazey.cn/
|
|
343
|
+
[更多接口>>](https://mazey.cn/t/m)
|
|
342
344
|
|
|
343
345
|
## 开发
|
|
344
346
|
|