mazey 3.3.11 → 3.4.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 CHANGED
@@ -55,66 +55,56 @@ There ara some examples maintained by hand below. For more information, please c
55
55
 
56
56
  **Table of Contents**
57
57
 
58
- <ul>
59
- <li><a href="#load-resource">Load Resource</a>
60
- <ul>
61
- <li><a href="#load-script">Load Script</a></li>
62
- <li><a href="#load-css">Load CSS</a></li>
63
- <li><a href="#check-load">Check Load</a></li>
64
- </ul>
65
- </li>
66
- <li><a href="#function">Function</a>
67
- <ul>
68
- <li><a href="#debounce">Debounce</a></li>
69
- <li><a href="#throttle">Throttle</a></li>
70
- <li><a href="#check-number">Check Number</a></li>
71
- <li><a href="#camel-case">Camel Case</a></li>
72
- <li><a href="#trim">Trim</a></li>
73
- <li><a href="#deep-clone">Deep Clone</a></li>
74
- <li><a href="#json">JSON</a></li>
75
- <li><a href="#random">Random</a></li>
76
- </ul>
77
- </li>
78
- <li><a href="#dom">DOM</a>
79
- <ul>
80
- <li><a href="#class">Class</a></li>
81
- <li><a href="#style">Style</a></li>
82
- <li><a href="#newline">Newline</a></li>
83
- </ul>
84
- </li>
85
- <li><a href="#url">URL</a>
86
- <ul>
87
- <li><a href="#query-param">Query Param</a></li>
88
- <li><a href="#update-param">Update Param</a></li>
89
- <li><a href="#hash-param">Hash Param</a></li>
90
- <li><a href="#domain">Domain</a></li>
91
- </ul>
92
- </li>
93
- <li><a href="#cache-data">Cache Data</a>
94
- <ul>
95
- <li><a href="#storage">Storage</a></li>
96
- <li><a href="#cookie">Cookie</a></li>
97
- </ul>
98
- </li>
99
- <li><a href="#calculate-formula">Calculate&amp;Formula</a>
100
- <ul>
101
- <li><a href="#rate">Rate</a></li>
102
- <li><a href="#algorithm">Algorithm</a></li>
103
- </ul>
104
- </li>
105
- <li><a href="#browser-information">Browser Information</a></li>
106
- <li><a href="#web-performance">Web Performance</a></li>
107
- <li><a href="#margin-of-safety">Margin of Safety</a></li>
108
- <li><a href="#debug">Debug</a>
109
- <ul>
110
- <li><a href="#print">Print</a></li>
111
- </ul>
112
- </li>
113
- </ul>
58
+ <!-- toc - begin -->
59
+ - Generated with ❤️
60
+ - [Load Resource](#load-resource)
61
+ * [loadScript](#loadscript)
62
+ * [loadCSS](#loadcss)
63
+ * [windowLoaded](#windowloaded)
64
+ - [Function](#function)
65
+ * [debounce](#debounce)
66
+ * [throttle](#throttle)
67
+ * [isNumber](#isnumber)
68
+ * [camelCaseToKebabCase](#camelcasetokebabcase)
69
+ * [camelCase2Underscore](#camelcase2underscore)
70
+ * [mTrim](#mtrim)
71
+ * [deepCopyObject](#deepcopyobject)
72
+ * [isJsonString](#isjsonstring)
73
+ * [generateRndNum](#generaterndnum)
74
+ - [DOM](#dom)
75
+ * [Class](#class)
76
+ * [addStyle](#addstyle)
77
+ * [newLine](#newline)
78
+ - [URL](#url)
79
+ * [getQueryParam](#getqueryparam)
80
+ * [getUrlParam](#geturlparam)
81
+ * [updateQueryParam](#updatequeryparam)
82
+ * [getHashQueryParam](#gethashqueryparam)
83
+ * [getDomain](#getdomain)
84
+ - [Cache Data](#cache-data)
85
+ * [Storage](#storage)
86
+ * [Cookie](#cookie)
87
+ - [Calculate and Formula](#calculate-and-formula)
88
+ * [inRate](#inrate)
89
+ * [calLongestCommonSubstring](#callongestcommonsubstring)
90
+ * [calLongestCommonSubsequence](#callongestcommonsubsequence)
91
+ - [Browser Information](#browser-information)
92
+ * [getBrowserInfo](#getbrowserinfo)
93
+ - [Web Performance](#web-performance)
94
+ * [getPerformance](#getperformance)
95
+ - [Margin of Safety](#margin-of-safety)
96
+ * [isSafePWAEnv](#issafepwaenv)
97
+ - [Debug](#debug)
98
+ * [genCustomConsole](#gencustomconsole)
99
+ <!-- toc - end -->
114
100
 
115
101
  ### Load Resource
116
102
 
117
- #### Load Script
103
+ #### loadScript
104
+
105
+ Load a JavaScript file from the server and execute it.
106
+
107
+ <!-- ZH: 动态加载 JavaScript 文件 -->
118
108
 
119
109
  ```
120
110
  loadScript(
@@ -137,7 +127,18 @@ loadScript(
137
127
  );
138
128
  ```
139
129
 
140
- #### Load CSS
130
+ <!-- @param {string} url -- JavaScript 资源路径
131
+ @param {string} options.id -- DOM ID
132
+ @param {function} options.callback -- 加载后回调函数
133
+ @param {number} options.timeout -- 超时时长
134
+ @param {boolean} options.isDefer -- 是否添加 defer 标签
135
+ @returns {Promise<boolean>} -- true 成功 -->
136
+
137
+ #### loadCSS
138
+
139
+ Load a CSS file from the server.
140
+
141
+ <!-- ZH: 动态加载 CSS 文件 -->
141
142
 
142
143
  ```
143
144
  loadCSS(
@@ -158,10 +159,16 @@ loadCSS(
158
159
  );
159
160
  ```
160
161
 
161
- #### Check Load
162
+ <!-- @param {string} url -- css资源路径
163
+ @param {string} options.id -- link标签id
164
+ @returns {Promise<boolean>} true -- 加载成功 -->
165
+
166
+ #### windowLoaded
162
167
 
163
168
  Check whether the page is loaded successfully (Keepe the compatibility in case that browser's `load` event has been triggered).
164
169
 
170
+ <!-- ZH: 页面加载完成 -->
171
+
165
172
  ```
166
173
  windowLoaded(30) // second
167
174
  .then(res => {
@@ -172,9 +179,16 @@ windowLoaded(30) // second
172
179
  });
173
180
  ```
174
181
 
182
+ <!-- @param {number} timeout 超时时间 / 单位:秒
183
+ @returns {Promise<string>} document is loaded? 'complete' 'load' / 'timeout' -->
184
+
175
185
  ### Function
176
186
 
177
- #### Debounce
187
+ #### debounce
188
+
189
+ Debounce
190
+
191
+ <!-- ZH: 去抖 -->
178
192
 
179
193
  ```
180
194
  const foo = debounce(() => {
@@ -182,7 +196,11 @@ const foo = debounce(() => {
182
196
  }, 1000, true);
183
197
  ```
184
198
 
185
- #### Throttle
199
+ #### throttle
200
+
201
+ Throttle
202
+
203
+ <!-- ZH: 节流 -->
186
204
 
187
205
  ```
188
206
  const foo = throttle(() => {
@@ -190,10 +208,14 @@ const foo = throttle(() => {
190
208
  }, 1000, { leading: true });
191
209
  ```
192
210
 
193
- #### Check Number
211
+ Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
212
+
213
+ #### isNumber
194
214
 
195
215
  Check whether it is a right number.
196
216
 
217
+ <!-- ZH: 判断是否有效数字 -->
218
+
197
219
  ```
198
220
  isNumber(123); // true
199
221
  isNumber('123'); // false
@@ -204,7 +226,12 @@ isNumber(NaN); // false
204
226
  isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
205
227
  ```
206
228
 
207
- #### Camel Case
229
+ <!-- @param {*} num 被判断的值
230
+ @param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
231
+ @param {boolean} options.isUnFiniteAsNumber 是否 无限 算数字(默认不算)
232
+ @returns {boolean} true 是数字 -->
233
+
234
+ #### camelCaseToKebabCase
208
235
 
209
236
  Transfer CamelCase to KebabCase.
210
237
 
@@ -213,6 +240,11 @@ camelCaseToKebabCase('ABC'); // a-b-c
213
240
  camelCaseToKebabCase('aBC'); // a-b-c
214
241
  ```
215
242
 
243
+ <!-- @param {string} camelCase 'aBC' or 'ABC'
244
+ @returns {string} 'a-b-c' -->
245
+
246
+ #### camelCase2Underscore
247
+
216
248
  Transfer CamelCase to Underscore.
217
249
 
218
250
  ```
@@ -220,7 +252,10 @@ camelCase2Underscore('ABC'); // a_b_c
220
252
  camelCase2Underscore('aBC'); // a_b_c
221
253
  ```
222
254
 
223
- #### Trim
255
+ <!-- @param {string} camelCase 'aBC' or 'ABC'
256
+ @returns {string} 'a_b_c' -->
257
+
258
+ #### mTrim
224
259
 
225
260
  Remove leading and trailing whitespace or specified characters from string.
226
261
 
@@ -229,25 +264,52 @@ mTrim(' 1 2 3 '); // '1 2 3'
229
264
  mTrim('abc '); // 'abc'
230
265
  ```
231
266
 
232
- #### Deep Clone
267
+ <!-- @param {string} str The string to trim.
268
+ @returns {string} Trimmed string. -->
269
+
270
+ #### deepCopyObject
233
271
 
234
272
  Clone Object deeply.
235
273
 
274
+ Usage:
275
+
276
+ ```
277
+ deepCopyObject(['a', 'b', 'c']);
278
+ deepCopyObject('abc');
279
+ ```
280
+
281
+ Output:
282
+
236
283
  ```
237
- deepCopyObject(['a', 'b', 'c']); // ['a', 'b', 'c']
238
- deepCopyObject('abc'); // 'abc'
284
+ ['a', 'b', 'c']
285
+ 'abc'
239
286
  ```
240
287
 
241
- #### JSON
288
+ <!-- @param {object} obj The value to clone.
289
+ @returns {object} Returns the deep cloned value. -->
290
+
291
+ #### isJsonString
242
292
 
243
293
  Check whether it is a valid JSON string.
244
294
 
295
+ Usage:
296
+
297
+ ```
298
+ isJsonString(`['a', 'b', 'c']`);
299
+ isJsonString(`["a", "b", "c"]`);
300
+ ```
301
+
302
+ Output:
303
+
245
304
  ```
246
- isJsonString(`['a', 'b', 'c']`); // false
247
- isJsonString(`["a", "b", "c"]`); // true
305
+ false
306
+ true
248
307
  ```
249
308
 
250
- #### Random
309
+ <!-- @param {string} str The string to check.
310
+ @returns {boolean} Return the result of checking. -->
311
+
312
+ #### generateRndNum
251
313
 
252
314
  Produce a random string of number, `generateRndNum(7)` => '7658495'.
253
315
 
@@ -273,7 +335,7 @@ addClass(dom, 'test');
273
335
  removeClass(dom, 'test');
274
336
  ```
275
337
 
276
- #### Style
338
+ #### addStyle
277
339
 
278
340
  Add `<style>` in `<head>`.
279
341
 
@@ -314,7 +376,7 @@ addStyle(
314
376
  // </style>
315
377
  ```
316
378
 
317
- #### Newline
379
+ #### newLine
318
380
 
319
381
  Make a newline of HTML.
320
382
 
@@ -325,7 +387,7 @@ newLine('a\n\nbc'); // 'a<br /><br />bc'
325
387
 
326
388
  ### URL
327
389
 
328
- #### Query Param
390
+ #### getQueryParam
329
391
 
330
392
  Get the query param's value of the current Web URL(`location.search`).
331
393
 
@@ -336,6 +398,11 @@ getQueryParam('t3'); // 3
336
398
  getQueryParam('t4'); // 4
337
399
  ```
338
400
 
401
+ <!-- @param {string} param Query param.
402
+ @returns {string} value -->
403
+
404
+ #### getUrlParam
405
+
339
406
  Get the query param's value of the input URL.
340
407
 
341
408
  ```
@@ -343,35 +410,77 @@ getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3'); // 3
343
410
  getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // 4
344
411
  ```
345
412
 
346
- #### Update Param
413
+ <!-- @param {string} url URL string.
414
+ @param {string} param Query param.
415
+ @returns {string} value -->
416
+
417
+ #### updateQueryParam
347
418
 
348
419
  Update the query param's value of the input URL.
349
420
 
421
+ Usage:
422
+
350
423
  ```
351
- updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three'); // http://example.com/?t1=1&t2=2&t3=three&t4=4
352
- updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four'); // http://example.com/?t1=1&t2=2&t3=3&t4=four
424
+ updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three');
425
+ updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four');
353
426
  ```
354
427
 
355
- #### Hash Param
428
+ Output:
429
+
430
+ ```
431
+ http://example.com/?t1=1&t2=2&t3=three&t4=4
432
+ http://example.com/?t1=1&t2=2&t3=3&t4=four
433
+ ```
434
+
435
+ <!-- @param {string} url URL string.
436
+ @param {string} param Query param.
437
+ @param {string} value Param's value.
438
+ @returns {string} URL. -->
439
+
440
+ #### getHashQueryParam
356
441
 
357
442
  Get the hash query param's value of the current Web URL(`location.hash`).
358
443
 
444
+ Usage:
445
+
359
446
  ```
360
447
  // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
361
448
  // #2333?t1=1&t2=2&t3=3&t4=4
362
- getHashQueryParam('t3'); // 3
363
- getHashQueryParam('t4'); // 4
449
+ getHashQueryParam('t3');
450
+ getHashQueryParam('t4');
364
451
  ```
365
452
 
366
- #### Domain
453
+ Output:
454
+
455
+ ```
456
+ 3
457
+ 4
458
+ ```
459
+
460
+ <!-- @param {string} param Query param.
461
+ @returns {string} value -->
462
+
463
+ #### getDomain
367
464
 
368
465
  Get the domain of URL, and other params.
369
466
 
467
+ Usage:
468
+
469
+ ```
470
+ getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');
471
+ getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);
472
+ ```
473
+
474
+ Output:
475
+
370
476
  ```
371
- getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4'); // example.com
372
- getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']); // example.com/test/thanks
477
+ example.com
478
+ example.com/test/thanks
373
479
  ```
374
480
 
481
+ <!-- @param {string} url
482
+ @param {array} rules Object.keys(location), ['href', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile' -->
483
+
375
484
  ### Cache Data
376
485
 
377
486
  #### Storage
@@ -404,15 +513,29 @@ setCookie('test', '123', 30, 'example.com'); // key value day domain
404
513
  getCookie('test'); // 123
405
514
  ```
406
515
 
407
- ### Calculate&Formula
516
+ ### Calculate and Formula
408
517
 
409
- #### Rate
518
+ #### inRate
410
519
 
411
520
  Hit probability (1% ~ 100%).
412
521
 
522
+ <!-- ZH: 百分位概率 -->
523
+
524
+ Usage:
525
+
526
+ ```
527
+ inRate(0.5); // 0.01 ~ 1 true/false
413
528
  ```
414
- inRate(0.5); // 0.01 ~ 1 true / false
415
529
 
530
+ Output:
531
+
532
+ ```
533
+ true
534
+ ```
535
+
536
+ Example: Test the precision.
537
+
538
+ ```
416
539
  // Test
417
540
  let trueCount = 0;
418
541
  let falseCount = 0;
@@ -426,91 +549,197 @@ new Array(1000000).fill(0).forEach(() => {
426
549
  console.log(trueCount, falseCount); // 499994 500006
427
550
  ```
428
551
 
429
- #### Algorithm
552
+ <!-- @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
553
+ @returns {boolean} true 命中 -->
554
+
555
+ #### calLongestCommonSubstring
430
556
 
431
557
  Computes the longest common substring of two strings.
432
558
 
559
+ <!-- ZH: 计算两个字符串的最长公共子串 -->
560
+
561
+ Usage:
562
+
433
563
  ```
434
- calLongestCommonSubstring('fish', 'finish'); // 3
564
+ calLongestCommonSubstring('fish', 'finish');
435
565
  ```
436
566
 
567
+ Output:
568
+
569
+ ```
570
+ 3
571
+ ```
572
+
573
+ <!-- @param {string} aStr String
574
+ @param {string} bStr String
575
+ @returns {number} Length -->
576
+
577
+ #### calLongestCommonSubsequence
578
+
437
579
  Computes the longest common subsequence of two strings.
438
580
 
581
+ <!-- ZH: 计算两个字符串的最长公共子序列 -->
582
+
583
+ Usage:
584
+
439
585
  ```
440
- calLongestCommonSubsequence('fish', 'finish'); // 4
586
+ calLongestCommonSubsequence('fish', 'finish');
441
587
  ```
442
588
 
589
+ Output:
590
+
591
+ ```
592
+ 4
593
+ ```
594
+
595
+ <!-- @param {string} aStr 字符串
596
+ @param {string} bStr 字符串
597
+ @returns {number} 长度 -->
598
+
443
599
  ### Browser Information
444
600
 
601
+ #### getBrowserInfo
602
+
603
+ Browser Information
604
+
605
+ <!-- ZH: 返回浏览器信息 https://github.com/JowayYoung/juejin-code/blob/master/browser-type.js -->
606
+
607
+ Usage:
608
+
445
609
  ```
446
- getBrowserInfo(); // {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
447
- // Shell and shell version { shell: 'wechat', shellVs: '20' } shell: wechat qq uc 360 2345 sougou liebao maxthon
610
+ getBrowserInfo();
448
611
  ```
449
612
 
613
+ Output:
614
+
615
+ ```
616
+ {"engine":"webkit","engineVs":"537.36","platform":"desktop","supporter":"chrome","supporterVs":"85.0.4183.121","system":"windows","systemVs":"10"}
617
+ ```
618
+
619
+ Results:
620
+
450
621
  | Index | Field | Description |
451
622
  | --- | --- | --- |
452
- | * System | system | android, ios, windows, macos, linux |
453
- | * System version | systemVs | windows: 2000, xp, 2003, vista, 7, 8, 8.1, 10<br />macos: ... |
454
- | * Platform | platform | desktop, mobile |
455
- | * Engine | engine | webkit, gecko, presto, trident |
456
- | * Engine version | engineVs | - |
457
- | * Supporter | supporter | edge, opera, chrome, safari, firefox, iexplore |
458
- | * Supporter version | supporterVs | - |
459
- | Shell | shell | wechat, qq_browser, qq_app, uc, 360, 2345, sougou, liebao, maxthon, bilibili |
460
- | Shell version | shellVs | - |
461
- | Apple device type | appleType | iphone, ipad, ipod, iwatch |
623
+ | System | system | android, ios, windows, macos, linux |
624
+ | System version | systemVs | windows: 2000, xp, 2003, vista, 7, 8, 8.1, 10 <br />macos: ... |
625
+ | Platform | platform | desktop, mobile |
626
+ | Engine | engine | webkit, gecko, presto, trident |
627
+ | Engine version | engineVs | - |
628
+ | Supporter | supporter | edge, opera, chrome, safari, firefox, iexplore |
629
+ | Supporter version | supporterVs | - |
630
+ | Shell | shell | (Optional) wechat, qq_browser, qq_app, uc, 360, 2345, sougou, liebao, maxthon, bilibili |
631
+ | Shell version | shellVs | (Optional) 20/... |
632
+ | Apple device type | appleType | (Optional) iphone, ipad, ipod, iwatch |
633
+
634
+ Example: Determine the environment of the mobile QQ.
635
+
636
+ ```
637
+ const { system, shell } = getBrowserInfo();
638
+ const isMobileQQ = ['android', 'ios'].includes(system) && ['qq_browser', 'qq_app'].includes(shell);
639
+ ```
640
+
641
+ <!-- @returns 浏览器信息 -->
462
642
 
463
643
  ### Web Performance
464
644
 
645
+ #### getPerformance
646
+
465
647
  Get page load time(PerformanceTiming).
466
648
 
649
+ <!-- ZH: 获取页面加载相关的各项数据 -->
650
+
651
+ Usage:
652
+
467
653
  ```
468
654
  // `camelCase:true`(Default) Return hump data.
469
655
  // `camelCase:false` Return underline data.
470
656
  getPerformance(true)
471
657
  .then(res => {
472
658
  console.log(JSON.stringify(res));
473
- // {"deviceType":"pc","network":"3g","unloadTime":0,"redirectTime":0,"dnsTime":0,"tcpTime":0,"responseTime":65,"downloadTime":1,"domreadyTime":369,"onloadTime":441,"whiteTime":94,"renderTime":441,"decodedBodySize":210,"encodedBodySize":210}
474
659
  })
475
660
  .catch(console.error);
476
661
  ```
477
662
 
478
- | Index | Field | Calculation |
663
+ Output:
664
+
665
+ ```
666
+ {"deviceType":"pc","network":"3g","unloadTime":0,"redirectTime":0,"dnsTime":0,"tcpTime":0,"responseTime":65,"downloadTime":1,"domreadyTime":369,"onloadTime":441,"whiteTime":94,"renderTime":441,"decodedBodySize":210,"encodedBodySize":210}
667
+ ```
668
+
669
+ Results:
670
+
671
+ | Index | Field | Description |
479
672
  | --- | --- | --- |
480
- | * DNS lookup | dns_time | domainLookupEnd - domainLookupStart |
481
- | * Connection negotiation | tcp_time | connectEnd - connectStart |
482
- | * Requests and responses | response_time | responseStart - requestStart |
483
- | * White screen | white_time | responseStart - navigationStart |
484
- | * DomReady | domready_time | domContentLoadedEventStart - navigationStart |
485
- | * Onload | onload_time | loadEventStart - navigationStart |
486
- | * EventEnd | render_time | loadEventEnd -navigationStart |
487
- | Unload | unload_time | unloadEventEnd - unloadEventStart |
488
- | Redirect | redirect_time | redirectEnd - redirectStart |
489
- | SSL | ssl_time | connectEnd - secureConnectionStart |
490
- | Download | download_time | responseEnd - responseStart |
673
+ | DNS lookup | dns_time | domainLookupEnd - domainLookupStart |
674
+ | Connection negotiation | tcp_time | connectEnd - connectStart |
675
+ | Requests and responses | response_time | responseStart - requestStart |
676
+ | White screen | white_time | responseStart - navigationStart |
677
+ | DomReady | domready_time | domContentLoadedEventStart - navigationStart |
678
+ | Onload | onload_time | loadEventStart - navigationStart |
679
+ | EventEnd | render_time | loadEventEnd -navigationStart |
680
+ | Unload | unload_time | (Optional) unloadEventEnd - unloadEventStart |
681
+ | Redirect | redirect_time | (Optional) redirectEnd - redirectStart |
682
+ | SSL | ssl_time | (Optional) connectEnd - secureConnectionStart |
683
+ | Download | download_time | (Optional) responseEnd - responseStart |
684
+
685
+ <!-- @param {boolean} camelCase -- true(默认) 以驼峰形式返回数据 false 以下划线形式返回数据
686
+ @returns {Promise<object>} 加载数据 -->
491
687
 
492
688
  ### Margin of Safety
493
689
 
690
+ #### isSafePWAEnv
691
+
494
692
  Determine if it is a secure PWA environment that it can run.
495
693
 
694
+ <!-- ZH: 判断是否是安全的 PWA 环境 -->
695
+
696
+ Usage:
697
+
496
698
  ```
497
- isSafePWAEnv(); // true
699
+ isSafePWAEnv();
498
700
  ```
499
701
 
702
+ Output:
703
+
704
+ ```
705
+ true
706
+ ```
707
+
708
+ <!-- @returns {boolean} true 是 -->
709
+
500
710
  ### Debug
501
711
 
502
- #### Print
712
+ #### genCustomConsole
503
713
 
504
714
  Custom console printing (`console`).
505
715
 
716
+ <!-- ZH: 生成自定义控制台打印 -->
717
+
718
+ Usage:
719
+
506
720
  ```
507
721
  const myConsole = genCustomConsole('MazeyLog:');
508
- myConsole.log('I am string.'); // MazeyLog: I am string.
509
- myConsole.info('I am boolean.', true); // MazeyLog: I am boolean. true
510
- myConsole.info('I am number.', 123, 456); // MazeyLog: I am number. 123 456
511
- myConsole.info('I am object.', { a: 123, b: 456}); // MazeyLog: I am object. {a: 123, b: 456}
722
+ myConsole.log('I am string.');
723
+ myConsole.info('I am boolean.', true);
724
+ myConsole.info('I am number.', 123, 456);
725
+ myConsole.info('I am object.', { a: 123, b: 456});
512
726
  ```
513
727
 
728
+ Output:
729
+
730
+ ```
731
+ MazeyLog: I am string.
732
+ MazeyLog: I am boolean. true
733
+ MazeyLog: I am number. 123 456
734
+ MazeyLog: I am object. {a: 123, b: 456}
735
+ ```
736
+
737
+ <!-- @param {string} prefix 前缀
738
+ @param {string} locales A locale string.
739
+ @param {function} logFn The function with Log.
740
+ @param {function} errorFn The function with Error.
741
+ @returns {object} 新实例 -->
742
+
514
743
  ## Contributing
515
744
 
516
745
  ```
package/README_CN.md CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  ## 安装
32
32
 
33
- You can get mazey@1.4.39 via [npm](https://www.npmjs.com/package/mazey/v/1.4.39).
33
+ 使用 [NPM](https://www.npmjs.com/package/mazey/v/1.4.39) 安装 mazey@1.4.39
34
34
 
35
35
  ```
36
36
  npm install mazey@1.4.39 --save
@@ -350,4 +350,4 @@ npm run build
350
350
 
351
351
  # documentation
352
352
  npm run docs
353
- ```
353
+ ```