mazey 3.10.0 → 3.10.2
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 +0 -104
- package/lib/index.cjs.js +2 -2
- package/lib/index.d.ts +1402 -1394
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +2 -2
- package/lib/mazey.min.js +2 -2
- package/package.json +10 -10
- package/global.d.ts +0 -64
package/README.md
CHANGED
|
@@ -135,14 +135,6 @@ loadScript(
|
|
|
135
135
|
);
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
<!-- @param {string} url -- JavaScript 资源路径
|
|
139
|
-
@param {string} options.id -- DOM ID
|
|
140
|
-
@param {function} options.callback -- 加载后回调函数
|
|
141
|
-
@param {number} options.timeout -- 超时时长
|
|
142
|
-
@param {boolean} options.isDefer -- 是否添加 defer 标签
|
|
143
|
-
@returns {Promise<boolean>} -- true 成功
|
|
144
|
-
@category Load Resource -->
|
|
145
|
-
|
|
146
138
|
#### loadScriptIfUndefined
|
|
147
139
|
|
|
148
140
|
Load a script from the given URL if it (`window['attribute']`) has not already been loaded.
|
|
@@ -182,11 +174,6 @@ loadCSS(
|
|
|
182
174
|
);
|
|
183
175
|
```
|
|
184
176
|
|
|
185
|
-
<!-- @param {string} url -- css资源路径
|
|
186
|
-
@param {string} options.id -- link标签id
|
|
187
|
-
@returns {Promise<boolean>} true -- 加载成功
|
|
188
|
-
@category Load Resource -->
|
|
189
|
-
|
|
190
177
|
#### loadImage
|
|
191
178
|
|
|
192
179
|
Load an image from the given URL.
|
|
@@ -221,10 +208,6 @@ windowLoaded(30) // second
|
|
|
221
208
|
});
|
|
222
209
|
```
|
|
223
210
|
|
|
224
|
-
<!-- @param {number} timeout 超时时间 / 单位:秒
|
|
225
|
-
@returns {Promise<string>} document is loaded? 'complete' 'load' / 'timeout'
|
|
226
|
-
@category Load Resource -->
|
|
227
|
-
|
|
228
211
|
### Util
|
|
229
212
|
|
|
230
213
|
#### isNumber
|
|
@@ -243,12 +226,6 @@ isNumber(NaN); // false
|
|
|
243
226
|
isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true }); // true
|
|
244
227
|
```
|
|
245
228
|
|
|
246
|
-
<!-- @param {*} num 被判断的值
|
|
247
|
-
@param {boolean} options.isNaNAsNumber 是否 NaN 算数字(默认不算)
|
|
248
|
-
@param {boolean} options.isInfinityAsNumber 是否 无限 算数字(默认不算)
|
|
249
|
-
@returns {boolean} true 是数字
|
|
250
|
-
@category Util -->
|
|
251
|
-
|
|
252
229
|
#### isJSONString
|
|
253
230
|
|
|
254
231
|
Check whether it is a valid JSON string.
|
|
@@ -267,10 +244,6 @@ false
|
|
|
267
244
|
true
|
|
268
245
|
```
|
|
269
246
|
|
|
270
|
-
<!-- @param {string} str The string to check.
|
|
271
|
-
@returns {boolean} Return the result of checking.
|
|
272
|
-
@category Util -->
|
|
273
|
-
|
|
274
247
|
#### isValidData
|
|
275
248
|
|
|
276
249
|
Determine the validity of the data.
|
|
@@ -303,12 +276,6 @@ isValidDataResB: true
|
|
|
303
276
|
isValidDataResC: false
|
|
304
277
|
```
|
|
305
278
|
|
|
306
|
-
<!-- @param {any} data Original Data
|
|
307
|
-
@param {string[]} attributes Data Attributes
|
|
308
|
-
@param {any} validValue Given Value for verifying.
|
|
309
|
-
@returns {boolean} Return TRUE if the data is valid.
|
|
310
|
-
@category Util -->
|
|
311
|
-
|
|
312
279
|
#### genRndNumString
|
|
313
280
|
|
|
314
281
|
Produce a random string of number, `genRndNumString(7)` => '7658495'.
|
|
@@ -340,11 +307,6 @@ Number formatDate value: 2022-01-11 14:07:15
|
|
|
340
307
|
Date formatDate value: 02/11/2014
|
|
341
308
|
```
|
|
342
309
|
|
|
343
|
-
<!-- @param {Date|number|string} dateIns Original Date
|
|
344
|
-
@param {string} format Format String
|
|
345
|
-
@returns {string} Return the formatted date string.
|
|
346
|
-
@category Util -->
|
|
347
|
-
|
|
348
310
|
#### debounce
|
|
349
311
|
|
|
350
312
|
Debounce
|
|
@@ -357,8 +319,6 @@ const foo = debounce(() => {
|
|
|
357
319
|
}, 1000, true);
|
|
358
320
|
```
|
|
359
321
|
|
|
360
|
-
<!-- @category Util -->
|
|
361
|
-
|
|
362
322
|
#### throttle
|
|
363
323
|
|
|
364
324
|
Throttle
|
|
@@ -373,8 +333,6 @@ const foo = throttle(() => {
|
|
|
373
333
|
|
|
374
334
|
Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
|
|
375
335
|
|
|
376
|
-
<!-- @category Util -->
|
|
377
|
-
|
|
378
336
|
#### convertCamelToKebab
|
|
379
337
|
|
|
380
338
|
Transfer CamelCase to KebabCase.
|
|
@@ -384,10 +342,6 @@ convertCamelToKebab('ABC'); // a-b-c
|
|
|
384
342
|
convertCamelToKebab('aBC'); // a-b-c
|
|
385
343
|
```
|
|
386
344
|
|
|
387
|
-
<!-- @param {string} camelCase 'aBC' or 'ABC'
|
|
388
|
-
@returns {string} 'a-b-c'
|
|
389
|
-
@category Util -->
|
|
390
|
-
|
|
391
345
|
#### convertCamelToUnder
|
|
392
346
|
|
|
393
347
|
Transfer CamelCase to Underscore.
|
|
@@ -397,10 +351,6 @@ convertCamelToUnder('ABC'); // a_b_c
|
|
|
397
351
|
convertCamelToUnder('aBC'); // a_b_c
|
|
398
352
|
```
|
|
399
353
|
|
|
400
|
-
<!-- @param {string} camelCase 'aBC' or 'ABC'
|
|
401
|
-
@returns {string} 'a_b_c'
|
|
402
|
-
@category Util -->
|
|
403
|
-
|
|
404
354
|
#### deepCopy
|
|
405
355
|
|
|
406
356
|
Copy/Clone Object deeply.
|
|
@@ -432,10 +382,6 @@ getQueryParam('t3'); // 3
|
|
|
432
382
|
getQueryParam('t4'); // 4
|
|
433
383
|
```
|
|
434
384
|
|
|
435
|
-
<!-- @param {string} param Query param.
|
|
436
|
-
@returns {string} value
|
|
437
|
-
@category URL -->
|
|
438
|
-
|
|
439
385
|
#### getUrlParam
|
|
440
386
|
|
|
441
387
|
Returns the value of the specified query parameter in the input URL.
|
|
@@ -445,11 +391,6 @@ getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3'); // Returns '3'
|
|
|
445
391
|
getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4'); // Returns '4'
|
|
446
392
|
```
|
|
447
393
|
|
|
448
|
-
<!-- @param {string} url The URL string.
|
|
449
|
-
@param {string} param The query parameter to retrieve the value for.
|
|
450
|
-
@returns {string|string[]} The value of the specified query parameter, or an empty string if the parameter is not found.
|
|
451
|
-
@category URL -->
|
|
452
|
-
|
|
453
394
|
#### getHashQueryParam
|
|
454
395
|
|
|
455
396
|
Get the hash query param's value of the current Web URL(`location.hash`).
|
|
@@ -470,10 +411,6 @@ Output:
|
|
|
470
411
|
4
|
|
471
412
|
```
|
|
472
413
|
|
|
473
|
-
<!-- @param {string} param Query param.
|
|
474
|
-
@returns {string} value
|
|
475
|
-
@category URL -->
|
|
476
|
-
|
|
477
414
|
#### getDomain
|
|
478
415
|
|
|
479
416
|
Get the domain of URL, and other params.
|
|
@@ -500,10 +437,6 @@ http://example.com:7890
|
|
|
500
437
|
http://example.com:7890/test/thanks?id=1
|
|
501
438
|
```
|
|
502
439
|
|
|
503
|
-
<!-- @param {string} url
|
|
504
|
-
@param {array} rules Object.keys(location), ['href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
|
|
505
|
-
@category URL -->
|
|
506
|
-
|
|
507
440
|
#### updateQueryParam
|
|
508
441
|
|
|
509
442
|
Update the query param's value of the input URL.
|
|
@@ -522,12 +455,6 @@ http://example.com/?t1=1&t2=2&t3=three&t4=4
|
|
|
522
455
|
http://example.com/?t1=1&t2=2&t3=3&t4=four
|
|
523
456
|
```
|
|
524
457
|
|
|
525
|
-
<!-- @param {string} url URL string.
|
|
526
|
-
@param {string} param Query param.
|
|
527
|
-
@param {string} value Param's value.
|
|
528
|
-
@returns {string} URL.
|
|
529
|
-
@category URL -->
|
|
530
|
-
|
|
531
458
|
#### isValidUrl
|
|
532
459
|
|
|
533
460
|
Checks if the given string is a valid URL, including **scheme URLs**.
|
|
@@ -568,8 +495,6 @@ setCookie('test', '123', 30, 'example.com'); // key value day domain
|
|
|
568
495
|
getCookie('test'); // 123
|
|
569
496
|
```
|
|
570
497
|
|
|
571
|
-
<!-- @category Cache Data -->
|
|
572
|
-
|
|
573
498
|
#### Storage
|
|
574
499
|
|
|
575
500
|
Handle Storage (Keep fit for JSON, it can transfer format automatically).
|
|
@@ -593,10 +518,6 @@ function mGetLocalStorage (key) {
|
|
|
593
518
|
}
|
|
594
519
|
```
|
|
595
520
|
|
|
596
|
-
<!-- @param {string} key 键
|
|
597
|
-
@returns {void} 返回值
|
|
598
|
-
@category Cache Data -->
|
|
599
|
-
|
|
600
521
|
### DOM
|
|
601
522
|
|
|
602
523
|
#### addStyle
|
|
@@ -642,8 +563,6 @@ addStyle(
|
|
|
642
563
|
// </style>
|
|
643
564
|
```
|
|
644
565
|
|
|
645
|
-
<!-- @category DOM -->
|
|
646
|
-
|
|
647
566
|
#### Class
|
|
648
567
|
|
|
649
568
|
Modify `class`.
|
|
@@ -659,8 +578,6 @@ addClass(dom, 'test');
|
|
|
659
578
|
removeClass(dom, 'test');
|
|
660
579
|
```
|
|
661
580
|
|
|
662
|
-
<!-- @category DOM -->
|
|
663
|
-
|
|
664
581
|
#### newLine
|
|
665
582
|
|
|
666
583
|
Make a new line of HTML.
|
|
@@ -670,10 +587,6 @@ newLine('a\nb\nc'); // 'a<br />b<br />c'
|
|
|
670
587
|
newLine('a\n\nbc'); // 'a<br /><br />bc'
|
|
671
588
|
```
|
|
672
589
|
|
|
673
|
-
<!-- @param {string} str The string to make a new line.
|
|
674
|
-
@returns {string} A newline with `br`.
|
|
675
|
-
@category DOM -->
|
|
676
|
-
|
|
677
590
|
### Calculate and Formula
|
|
678
591
|
|
|
679
592
|
#### inRate
|
|
@@ -710,10 +623,6 @@ new Array(1000000).fill(0).forEach(() => {
|
|
|
710
623
|
console.log(trueCount, falseCount); // 499994 500006
|
|
711
624
|
```
|
|
712
625
|
|
|
713
|
-
<!-- @param {number} rate -- 0.1 ~ 1 => 1% ~ 100%
|
|
714
|
-
@returns {boolean} true 命中
|
|
715
|
-
@category Calculate and Formula -->
|
|
716
|
-
|
|
717
626
|
#### longestComSubstring
|
|
718
627
|
|
|
719
628
|
Computes the longest common substring of two strings.
|
|
@@ -788,9 +697,6 @@ const { system, shell } = getBrowserInfo();
|
|
|
788
697
|
const isMobileQQ = ['android', 'ios'].includes(system) && ['qq_browser', 'qq_app'].includes(shell);
|
|
789
698
|
```
|
|
790
699
|
|
|
791
|
-
<!-- @returns 浏览器信息
|
|
792
|
-
@category Browser Information -->
|
|
793
|
-
|
|
794
700
|
#### isSafePWAEnv
|
|
795
701
|
|
|
796
702
|
Detect the margin of Safety. Determine if it is a secure PWA environment that it can run.
|
|
@@ -809,9 +715,6 @@ Output:
|
|
|
809
715
|
true
|
|
810
716
|
```
|
|
811
717
|
|
|
812
|
-
<!-- @returns {boolean} true 是
|
|
813
|
-
@category Browser Information -->
|
|
814
|
-
|
|
815
718
|
### Web Performance
|
|
816
719
|
|
|
817
720
|
#### getPerformance
|
|
@@ -883,13 +786,6 @@ MazeyLog: I am number. 123 456
|
|
|
883
786
|
MazeyLog: I am object. {a: 123, b: 456}
|
|
884
787
|
```
|
|
885
788
|
|
|
886
|
-
<!-- @param {string} prefix 前缀
|
|
887
|
-
@param {string} locales A locale string.
|
|
888
|
-
@param {function} logFn The function with Log.
|
|
889
|
-
@param {function} errorFn The function with Error.
|
|
890
|
-
@returns {object} 新实例
|
|
891
|
-
@category Debug -->
|
|
892
|
-
|
|
893
789
|
## Contributing
|
|
894
790
|
|
|
895
791
|
### Development Environment
|