mazey 3.5.3 → 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 +226 -178
- package/README_CN.md +4 -2
- package/lib/index.cjs.js +3619 -2756
- package/lib/index.d.ts +286 -42
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +3614 -2757
- package/lib/mazey.min.js +2 -2
- package/package.json +4 -3
- package/scripts/env.sh +2 -0
- package/src/index.ts +343 -48
- package/src/preview.js +0 -44
package/README.md
CHANGED
|
@@ -61,28 +61,28 @@ There ara some examples maintained by hand below. For more information, please c
|
|
|
61
61
|
* [loadScript](#loadscript)
|
|
62
62
|
* [loadCSS](#loadcss)
|
|
63
63
|
* [windowLoaded](#windowloaded)
|
|
64
|
-
- [
|
|
64
|
+
- [Util](#util)
|
|
65
|
+
* [isNumber](#isnumber)
|
|
66
|
+
* [generateRndNum](#generaterndnum)
|
|
67
|
+
* [isJsonString](#isjsonstring)
|
|
68
|
+
* [formatDate](#formatdate)
|
|
65
69
|
* [debounce](#debounce)
|
|
66
70
|
* [throttle](#throttle)
|
|
67
|
-
* [isNumber](#isnumber)
|
|
68
71
|
* [camelCaseToKebabCase](#camelcasetokebabcase)
|
|
69
72
|
* [camelCase2Underscore](#camelcase2underscore)
|
|
70
73
|
* [mTrim](#mtrim)
|
|
71
74
|
* [deepCopyObject](#deepcopyobject)
|
|
72
|
-
* [isJsonString](#isjsonstring)
|
|
73
|
-
* [generateRndNum](#generaterndnum)
|
|
74
|
-
* [formatDate](#formatdate)
|
|
75
75
|
* [isValidData](#isvaliddata)
|
|
76
76
|
- [DOM](#dom)
|
|
77
|
-
* [Class](#class)
|
|
78
77
|
* [addStyle](#addstyle)
|
|
79
78
|
* [newLine](#newline)
|
|
79
|
+
* [Class](#class)
|
|
80
80
|
- [URL](#url)
|
|
81
81
|
* [getQueryParam](#getqueryparam)
|
|
82
82
|
* [getUrlParam](#geturlparam)
|
|
83
|
-
* [updateQueryParam](#updatequeryparam)
|
|
84
83
|
* [getHashQueryParam](#gethashqueryparam)
|
|
85
84
|
* [getDomain](#getdomain)
|
|
85
|
+
* [updateQueryParam](#updatequeryparam)
|
|
86
86
|
- [Cache Data](#cache-data)
|
|
87
87
|
* [Storage](#storage)
|
|
88
88
|
* [Cookie](#cookie)
|
|
@@ -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 -->
|
|
@@ -134,7 +133,8 @@ loadScript(
|
|
|
134
133
|
@param {function} options.callback -- 加载后回调函数
|
|
135
134
|
@param {number} options.timeout -- 超时时长
|
|
136
135
|
@param {boolean} options.isDefer -- 是否添加 defer 标签
|
|
137
|
-
@returns {Promise<boolean>} -- true 成功
|
|
136
|
+
@returns {Promise<boolean>} -- true 成功
|
|
137
|
+
@category Load Resource -->
|
|
138
138
|
|
|
139
139
|
#### loadCSS
|
|
140
140
|
|
|
@@ -163,7 +163,8 @@ loadCSS(
|
|
|
163
163
|
|
|
164
164
|
<!-- @param {string} url -- css资源路径
|
|
165
165
|
@param {string} options.id -- link标签id
|
|
166
|
-
@returns {Promise<boolean>} true -- 加载成功
|
|
166
|
+
@returns {Promise<boolean>} true -- 加载成功
|
|
167
|
+
@category Load Resource -->
|
|
167
168
|
|
|
168
169
|
#### windowLoaded
|
|
169
170
|
|
|
@@ -182,9 +183,94 @@ windowLoaded(30) // second
|
|
|
182
183
|
```
|
|
183
184
|
|
|
184
185
|
<!-- @param {number} timeout 超时时间 / 单位:秒
|
|
185
|
-
@returns {Promise<string>} document is loaded? 'complete' 'load' / 'timeout'
|
|
186
|
+
@returns {Promise<string>} document is loaded? 'complete' 'load' / 'timeout'
|
|
187
|
+
@category Load Resource -->
|
|
188
|
+
|
|
189
|
+
### Util
|
|
190
|
+
|
|
191
|
+
#### isNumber
|
|
192
|
+
|
|
193
|
+
Check whether it is a right number.
|
|
194
|
+
|
|
195
|
+
<!-- ZH: 判断是否有效数字 -->
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
isNumber(123); // true
|
|
199
|
+
isNumber('123'); // false
|
|
200
|
+
// Default: NaN, Infinity is not Number
|
|
201
|
+
isNumber(Infinity); // false
|
|
202
|
+
isNumber(Infinity, { isUnFiniteAsNumber: true }); // true
|
|
203
|
+
isNumber(NaN); // false
|
|
204
|
+
isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
<!-- @param {*} num 被判断的值
|
|
208
|
+
@param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
|
|
209
|
+
@param {boolean} options.isUnFiniteAsNumber 是否 无限 算数字(默认不算)
|
|
210
|
+
@returns {boolean} true 是数字
|
|
211
|
+
@category Util -->
|
|
212
|
+
|
|
213
|
+
#### generateRndNum
|
|
214
|
+
|
|
215
|
+
Produce a random string of number, `generateRndNum(7)` => '7658495'.
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
generateRndNum(4); // '9730'
|
|
219
|
+
generateRndNum(7); // '2262490'
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
<!-- @param {number} n Length
|
|
223
|
+
@returns {string} Return the random string.
|
|
224
|
+
@category Util -->
|
|
225
|
+
|
|
226
|
+
#### isJsonString
|
|
227
|
+
|
|
228
|
+
Check whether it is a valid JSON string.
|
|
229
|
+
|
|
230
|
+
Usage:
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
isJsonString(`['a', 'b', 'c']`);
|
|
234
|
+
isJsonString(`["a", "b", "c"]`);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Output:
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
false
|
|
241
|
+
true
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
<!-- @param {string} str The string to check.
|
|
245
|
+
@returns {boolean} Return the result of checking.
|
|
246
|
+
@category Util -->
|
|
247
|
+
|
|
248
|
+
#### formatDate
|
|
249
|
+
|
|
250
|
+
Return the formatted date string in the given format.
|
|
251
|
+
|
|
252
|
+
Usage:
|
|
186
253
|
|
|
187
|
-
|
|
254
|
+
```
|
|
255
|
+
console.log('Default formatDate value:', formatDate());
|
|
256
|
+
console.log('String formatDate value:', formatDate('Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)', 'yyyy-MM-dd hh:mm:ss'));
|
|
257
|
+
console.log('Number formatDate value:', formatDate(1641881235000, 'yyyy-MM-dd hh:mm:ss'));
|
|
258
|
+
console.log('Date formatDate value:', formatDate(new Date(2014, 1, 11), 'MM/dd/yyyy'));
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Output:
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
Default formatDate value: 2023-01-11
|
|
265
|
+
String formatDate value: 2022-01-11 14:12:26
|
|
266
|
+
Number formatDate value: 2022-01-11 14:07:15
|
|
267
|
+
Date formatDate value: 02/11/2014
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
<!-- @param {Date|number|string} dateIns Original Date
|
|
271
|
+
@param {string} format Format String
|
|
272
|
+
@returns {string} Return the formatted date string.
|
|
273
|
+
@category Util -->
|
|
188
274
|
|
|
189
275
|
#### debounce
|
|
190
276
|
|
|
@@ -198,6 +284,8 @@ const foo = debounce(() => {
|
|
|
198
284
|
}, 1000, true);
|
|
199
285
|
```
|
|
200
286
|
|
|
287
|
+
<!-- @category Util -->
|
|
288
|
+
|
|
201
289
|
#### throttle
|
|
202
290
|
|
|
203
291
|
Throttle
|
|
@@ -212,26 +300,7 @@ const foo = throttle(() => {
|
|
|
212
300
|
|
|
213
301
|
Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
|
|
214
302
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
Check whether it is a right number.
|
|
218
|
-
|
|
219
|
-
<!-- ZH: 判断是否有效数字 -->
|
|
220
|
-
|
|
221
|
-
```
|
|
222
|
-
isNumber(123); // true
|
|
223
|
-
isNumber('123'); // false
|
|
224
|
-
// Default: NaN, Infinity is not Number
|
|
225
|
-
isNumber(Infinity); // false
|
|
226
|
-
isNumber(Infinity, { isUnFiniteAsNumber: true }); // true
|
|
227
|
-
isNumber(NaN); // false
|
|
228
|
-
isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
<!-- @param {*} num 被判断的值
|
|
232
|
-
@param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
|
|
233
|
-
@param {boolean} options.isUnFiniteAsNumber 是否 无限 算数字(默认不算)
|
|
234
|
-
@returns {boolean} true 是数字 -->
|
|
303
|
+
<!-- @category Util -->
|
|
235
304
|
|
|
236
305
|
#### camelCaseToKebabCase
|
|
237
306
|
|
|
@@ -243,7 +312,8 @@ camelCaseToKebabCase('aBC'); // a-b-c
|
|
|
243
312
|
```
|
|
244
313
|
|
|
245
314
|
<!-- @param {string} camelCase 'aBC' or 'ABC'
|
|
246
|
-
@returns {string} 'a-b-c'
|
|
315
|
+
@returns {string} 'a-b-c'
|
|
316
|
+
@category Util -->
|
|
247
317
|
|
|
248
318
|
#### camelCase2Underscore
|
|
249
319
|
|
|
@@ -255,7 +325,8 @@ camelCase2Underscore('aBC'); // a_b_c
|
|
|
255
325
|
```
|
|
256
326
|
|
|
257
327
|
<!-- @param {string} camelCase 'aBC' or 'ABC'
|
|
258
|
-
@returns {string} 'a_b_c'
|
|
328
|
+
@returns {string} 'a_b_c'
|
|
329
|
+
@category Util -->
|
|
259
330
|
|
|
260
331
|
#### mTrim
|
|
261
332
|
|
|
@@ -267,7 +338,8 @@ mTrim('abc '); // 'abc'
|
|
|
267
338
|
```
|
|
268
339
|
|
|
269
340
|
<!-- @param {string} str The string to trim.
|
|
270
|
-
@returns {string} Trimmed string.
|
|
341
|
+
@returns {string} Trimmed string.
|
|
342
|
+
@category Util -->
|
|
271
343
|
|
|
272
344
|
#### deepCopyObject
|
|
273
345
|
|
|
@@ -288,63 +360,8 @@ Output:
|
|
|
288
360
|
```
|
|
289
361
|
|
|
290
362
|
<!-- @param {object} obj The value to clone.
|
|
291
|
-
@returns {object} Returns the deep cloned value.
|
|
292
|
-
|
|
293
|
-
#### isJsonString
|
|
294
|
-
|
|
295
|
-
Check whether it is a valid JSON string.
|
|
296
|
-
|
|
297
|
-
Usage:
|
|
298
|
-
|
|
299
|
-
```
|
|
300
|
-
isJsonString(`['a', 'b', 'c']`);
|
|
301
|
-
isJsonString(`["a", "b", "c"]`);
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
Output:
|
|
305
|
-
|
|
306
|
-
```
|
|
307
|
-
false
|
|
308
|
-
true
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
<!-- @param {string} str The string to check.
|
|
312
|
-
@returns {boolean} Return the result of checking. -->
|
|
313
|
-
|
|
314
|
-
#### generateRndNum
|
|
315
|
-
|
|
316
|
-
Produce a random string of number, `generateRndNum(7)` => '7658495'.
|
|
317
|
-
|
|
318
|
-
```
|
|
319
|
-
generateRndNum(4); // '9730'
|
|
320
|
-
generateRndNum(7); // '2262490'
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
#### formatDate
|
|
324
|
-
|
|
325
|
-
Return the formatted date string in the given format.
|
|
326
|
-
|
|
327
|
-
Usage:
|
|
328
|
-
|
|
329
|
-
```
|
|
330
|
-
console.log('Default formatDate value:', formatDate());
|
|
331
|
-
console.log('String formatDate value:', formatDate('Tue Jan 11 2022 14:12:26 GMT+0800 (China Standard Time)', 'yyyy-MM-dd hh:mm:ss'));
|
|
332
|
-
console.log('Number formatDate value:', formatDate(1641881235000, 'yyyy-MM-dd hh:mm:ss'));
|
|
333
|
-
console.log('Date formatDate value:', formatDate(new Date(2014, 1, 11), 'MM/dd/yyyy'));
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
Output:
|
|
337
|
-
|
|
338
|
-
```
|
|
339
|
-
Default formatDate value: 2023-01-11
|
|
340
|
-
String formatDate value: 2022-01-11 14:12:26
|
|
341
|
-
Number formatDate value: 2022-01-11 14:07:15
|
|
342
|
-
Date formatDate value: 02/11/2014
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
<!-- @param {Date|number|string} dateIns Original Date
|
|
346
|
-
@param {string} format Format String
|
|
347
|
-
@returns {string} Return the formatted date string. -->
|
|
363
|
+
@returns {object} Returns the deep cloned value.
|
|
364
|
+
@category Util -->
|
|
348
365
|
|
|
349
366
|
#### isValidData
|
|
350
367
|
|
|
@@ -381,30 +398,18 @@ isValidDataResC: false
|
|
|
381
398
|
<!-- @param {any} data Original Data
|
|
382
399
|
@param {string[]} attributes Data Attributes
|
|
383
400
|
@param {any} validValue Given Value for verifying.
|
|
384
|
-
@returns {boolean} Return TRUE if the data is valid.
|
|
401
|
+
@returns {boolean} Return TRUE if the data is valid.
|
|
402
|
+
@category Util -->
|
|
385
403
|
|
|
386
404
|
### DOM
|
|
387
405
|
|
|
388
|
-
#### Class
|
|
389
|
-
|
|
390
|
-
Modify `class`.
|
|
391
|
-
|
|
392
|
-
```
|
|
393
|
-
const dom = document.querySelector('#box');
|
|
394
|
-
|
|
395
|
-
// Determine `class`
|
|
396
|
-
hasClass(dom, 'test');
|
|
397
|
-
// Add `class`
|
|
398
|
-
addClass(dom, 'test');
|
|
399
|
-
// Remove `class`
|
|
400
|
-
removeClass(dom, 'test');
|
|
401
|
-
```
|
|
402
|
-
|
|
403
406
|
#### addStyle
|
|
404
407
|
|
|
405
408
|
Add `<style>` in `<head>`.
|
|
406
409
|
|
|
407
|
-
|
|
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.
|
|
408
413
|
|
|
409
414
|
```
|
|
410
415
|
addStyle(
|
|
@@ -424,7 +429,7 @@ addStyle(
|
|
|
424
429
|
// </style>
|
|
425
430
|
```
|
|
426
431
|
|
|
427
|
-
|
|
432
|
+
Example 2: Add the `<style>` without `id`, and repeated invoking will adding a new one.
|
|
428
433
|
|
|
429
434
|
```
|
|
430
435
|
addStyle(
|
|
@@ -441,6 +446,8 @@ addStyle(
|
|
|
441
446
|
// </style>
|
|
442
447
|
```
|
|
443
448
|
|
|
449
|
+
<!-- @category DOM -->
|
|
450
|
+
|
|
444
451
|
#### newLine
|
|
445
452
|
|
|
446
453
|
Make a newline of HTML.
|
|
@@ -450,6 +457,27 @@ newLine('a\nb\nc'); // 'a<br />b<br />c'
|
|
|
450
457
|
newLine('a\n\nbc'); // 'a<br /><br />bc'
|
|
451
458
|
```
|
|
452
459
|
|
|
460
|
+
<!-- @param {string} str The string to make a newline.
|
|
461
|
+
@returns {string} A newline with `br`.
|
|
462
|
+
@category DOM -->
|
|
463
|
+
|
|
464
|
+
#### Class
|
|
465
|
+
|
|
466
|
+
Modify `class`.
|
|
467
|
+
|
|
468
|
+
```
|
|
469
|
+
const dom = document.querySelector('#box');
|
|
470
|
+
|
|
471
|
+
// Determine `class`
|
|
472
|
+
hasClass(dom, 'test');
|
|
473
|
+
// Add `class`
|
|
474
|
+
addClass(dom, 'test');
|
|
475
|
+
// Remove `class`
|
|
476
|
+
removeClass(dom, 'test');
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
<!-- @category DOM -->
|
|
480
|
+
|
|
453
481
|
### URL
|
|
454
482
|
|
|
455
483
|
#### getQueryParam
|
|
@@ -464,7 +492,8 @@ getQueryParam('t4'); // 4
|
|
|
464
492
|
```
|
|
465
493
|
|
|
466
494
|
<!-- @param {string} param Query param.
|
|
467
|
-
@returns {string} value
|
|
495
|
+
@returns {string} value
|
|
496
|
+
@category URL -->
|
|
468
497
|
|
|
469
498
|
#### getUrlParam
|
|
470
499
|
|
|
@@ -477,30 +506,8 @@ getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // 4
|
|
|
477
506
|
|
|
478
507
|
<!-- @param {string} url URL string.
|
|
479
508
|
@param {string} param Query param.
|
|
480
|
-
@returns {string} value
|
|
481
|
-
|
|
482
|
-
#### updateQueryParam
|
|
483
|
-
|
|
484
|
-
Update the query param's value of the input URL.
|
|
485
|
-
|
|
486
|
-
Usage:
|
|
487
|
-
|
|
488
|
-
```
|
|
489
|
-
updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three');
|
|
490
|
-
updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four');
|
|
491
|
-
```
|
|
492
|
-
|
|
493
|
-
Output:
|
|
494
|
-
|
|
495
|
-
```
|
|
496
|
-
http://example.com/?t1=1&t2=2&t3=three&t4=4
|
|
497
|
-
http://example.com/?t1=1&t2=2&t3=3&t4=four
|
|
498
|
-
```
|
|
499
|
-
|
|
500
|
-
<!-- @param {string} url URL string.
|
|
501
|
-
@param {string} param Query param.
|
|
502
|
-
@param {string} value Param's value.
|
|
503
|
-
@returns {string} URL. -->
|
|
509
|
+
@returns {string} value
|
|
510
|
+
@category URL -->
|
|
504
511
|
|
|
505
512
|
#### getHashQueryParam
|
|
506
513
|
|
|
@@ -523,7 +530,8 @@ Output:
|
|
|
523
530
|
```
|
|
524
531
|
|
|
525
532
|
<!-- @param {string} param Query param.
|
|
526
|
-
@returns {string} value
|
|
533
|
+
@returns {string} value
|
|
534
|
+
@category URL -->
|
|
527
535
|
|
|
528
536
|
#### getDomain
|
|
529
537
|
|
|
@@ -544,7 +552,32 @@ example.com/test/thanks
|
|
|
544
552
|
```
|
|
545
553
|
|
|
546
554
|
<!-- @param {string} url
|
|
547
|
-
@param {array} rules Object.keys(location), ['href', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
|
|
555
|
+
@param {array} rules Object.keys(location), ['href', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
|
|
556
|
+
@category URL -->
|
|
557
|
+
|
|
558
|
+
#### updateQueryParam
|
|
559
|
+
|
|
560
|
+
Update the query param's value of the input URL.
|
|
561
|
+
|
|
562
|
+
Usage:
|
|
563
|
+
|
|
564
|
+
```
|
|
565
|
+
updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three');
|
|
566
|
+
updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four');
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
Output:
|
|
570
|
+
|
|
571
|
+
```
|
|
572
|
+
http://example.com/?t1=1&t2=2&t3=three&t4=4
|
|
573
|
+
http://example.com/?t1=1&t2=2&t3=3&t4=four
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
<!-- @param {string} url URL string.
|
|
577
|
+
@param {string} param Query param.
|
|
578
|
+
@param {string} value Param's value.
|
|
579
|
+
@returns {string} URL.
|
|
580
|
+
@category URL -->
|
|
548
581
|
|
|
549
582
|
### Cache Data
|
|
550
583
|
|
|
@@ -552,6 +585,8 @@ example.com/test/thanks
|
|
|
552
585
|
|
|
553
586
|
Handle Storage (Keep fit for JSON, it can tansfer format automatically).
|
|
554
587
|
|
|
588
|
+
<!-- ZH: 存储/获取数据到 sessionStorage/localStorage -->
|
|
589
|
+
|
|
555
590
|
```
|
|
556
591
|
setSessionStorage('test', '123');
|
|
557
592
|
getSessionStorage('test'); // 123
|
|
@@ -569,15 +604,23 @@ function mGetLocalStorage (key) {
|
|
|
569
604
|
}
|
|
570
605
|
```
|
|
571
606
|
|
|
607
|
+
<!-- @param {string} key 键
|
|
608
|
+
@returns {any} 返回值
|
|
609
|
+
@category Cache Data -->
|
|
610
|
+
|
|
572
611
|
#### Cookie
|
|
573
612
|
|
|
574
613
|
Handle Cookie.
|
|
575
614
|
|
|
615
|
+
<!-- ZH: 设置/获取 Cookie -->
|
|
616
|
+
|
|
576
617
|
```
|
|
577
618
|
setCookie('test', '123', 30, 'example.com'); // key value day domain
|
|
578
619
|
getCookie('test'); // 123
|
|
579
620
|
```
|
|
580
621
|
|
|
622
|
+
<!-- @category Cache Data -->
|
|
623
|
+
|
|
581
624
|
### Calculate and Formula
|
|
582
625
|
|
|
583
626
|
#### inRate
|
|
@@ -615,7 +658,8 @@ console.log(trueCount, falseCount); // 499994 500006
|
|
|
615
658
|
```
|
|
616
659
|
|
|
617
660
|
<!-- @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
|
|
618
|
-
@returns {boolean} true 命中
|
|
661
|
+
@returns {boolean} true 命中
|
|
662
|
+
@category Calculate and Formula -->
|
|
619
663
|
|
|
620
664
|
#### calLongestCommonSubstring
|
|
621
665
|
|
|
@@ -637,7 +681,8 @@ Output:
|
|
|
637
681
|
|
|
638
682
|
<!-- @param {string} aStr String
|
|
639
683
|
@param {string} bStr String
|
|
640
|
-
@returns {number} Length
|
|
684
|
+
@returns {number} Length
|
|
685
|
+
@category Calculate and Formula -->
|
|
641
686
|
|
|
642
687
|
#### calLongestCommonSubsequence
|
|
643
688
|
|
|
@@ -659,7 +704,8 @@ Output:
|
|
|
659
704
|
|
|
660
705
|
<!-- @param {string} aStr 字符串
|
|
661
706
|
@param {string} bStr 字符串
|
|
662
|
-
@returns {number} 长度
|
|
707
|
+
@returns {number} 长度
|
|
708
|
+
@category Calculate and Formula -->
|
|
663
709
|
|
|
664
710
|
### Browser Information
|
|
665
711
|
|
|
@@ -683,18 +729,18 @@ Output:
|
|
|
683
729
|
|
|
684
730
|
Results:
|
|
685
731
|
|
|
686
|
-
|
|
|
687
|
-
| --- | --- | --- |
|
|
688
|
-
| System |
|
|
689
|
-
| System version |
|
|
690
|
-
| Platform |
|
|
691
|
-
| Engine |
|
|
692
|
-
| Engine version |
|
|
693
|
-
| Supporter |
|
|
694
|
-
| Supporter version |
|
|
695
|
-
| Shell |
|
|
696
|
-
| Shell version |
|
|
697
|
-
| 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 |
|
|
698
744
|
|
|
699
745
|
Example: Determine the environment of the mobile QQ.
|
|
700
746
|
|
|
@@ -703,7 +749,29 @@ const { system, shell } = getBrowserInfo();
|
|
|
703
749
|
const isMobileQQ = ['android', 'ios'].includes(system) && ['qq_browser', 'qq_app'].includes(shell);
|
|
704
750
|
```
|
|
705
751
|
|
|
706
|
-
<!-- @returns 浏览器信息
|
|
752
|
+
<!-- @returns 浏览器信息
|
|
753
|
+
@category Browser Information -->
|
|
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 -->
|
|
707
775
|
|
|
708
776
|
### Web Performance
|
|
709
777
|
|
|
@@ -748,29 +816,8 @@ Results:
|
|
|
748
816
|
| Download | download_time | (Optional) responseEnd - responseStart |
|
|
749
817
|
|
|
750
818
|
<!-- @param {boolean} camelCase -- false(默认) 以下划线形式返回数据 true 以驼峰形式返回数据
|
|
751
|
-
@returns {Promise<object>} 加载数据
|
|
752
|
-
|
|
753
|
-
### Margin of Safety
|
|
754
|
-
|
|
755
|
-
#### isSafePWAEnv
|
|
756
|
-
|
|
757
|
-
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 是 -->
|
|
819
|
+
@returns {Promise<object>} 加载数据
|
|
820
|
+
@category Web Performance -->
|
|
774
821
|
|
|
775
822
|
### Debug
|
|
776
823
|
|
|
@@ -803,7 +850,8 @@ MazeyLog: I am object. {a: 123, b: 456}
|
|
|
803
850
|
@param {string} locales A locale string.
|
|
804
851
|
@param {function} logFn The function with Log.
|
|
805
852
|
@param {function} errorFn The function with Error.
|
|
806
|
-
@returns {object} 新实例
|
|
853
|
+
@returns {object} 新实例
|
|
854
|
+
@category Debug -->
|
|
807
855
|
|
|
808
856
|
## Contributing
|
|
809
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
|
|