mazey 3.7.4 → 3.8.1
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 +63 -52
- package/lib/index.cjs.js +2 -7165
- package/lib/index.d.ts +72 -27
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +302 -166
- package/lib/mazey.min.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,20 +63,21 @@ There ara some examples maintained by hand below. For more information, please c
|
|
|
63
63
|
- Generated with ❤️
|
|
64
64
|
- [Load Resource](#load-resource)
|
|
65
65
|
* [loadScript](#loadscript)
|
|
66
|
+
* [loadScriptIfUndefined](#loadscriptifundefined)
|
|
66
67
|
* [loadCSS](#loadcss)
|
|
68
|
+
* [loadImage](#loadimage)
|
|
67
69
|
* [windowLoaded](#windowloaded)
|
|
68
70
|
- [Util](#util)
|
|
69
71
|
* [isNumber](#isnumber)
|
|
70
72
|
* [isJSONString](#isjsonstring)
|
|
71
73
|
* [isValidData](#isvaliddata)
|
|
72
|
-
* [
|
|
74
|
+
* [genRndNumString](#genrndnumstring)
|
|
73
75
|
* [formatDate](#formatdate)
|
|
74
76
|
* [debounce](#debounce)
|
|
75
77
|
* [throttle](#throttle)
|
|
76
78
|
* [convertCamelToKebab](#convertcameltokebab)
|
|
77
79
|
* [convertCamelToUnder](#convertcameltounder)
|
|
78
|
-
* [
|
|
79
|
-
* [mTrim](#mtrim)
|
|
80
|
+
* [deepCopy](#deepcopy)
|
|
80
81
|
- [URL](#url)
|
|
81
82
|
* [getQueryParam](#getqueryparam)
|
|
82
83
|
* [getUrlParam](#geturlparam)
|
|
@@ -92,8 +93,8 @@ There ara some examples maintained by hand below. For more information, please c
|
|
|
92
93
|
* [newLine](#newline)
|
|
93
94
|
- [Calculate and Formula](#calculate-and-formula)
|
|
94
95
|
* [inRate](#inrate)
|
|
95
|
-
* [
|
|
96
|
-
* [
|
|
96
|
+
* [longestComSubstring](#longestcomsubstring)
|
|
97
|
+
* [longestComSubsequence](#longestcomsubsequence)
|
|
97
98
|
- [Browser Information](#browser-information)
|
|
98
99
|
* [getBrowserInfo](#getbrowserinfo)
|
|
99
100
|
* [isSafePWAEnv](#issafepwaenv)
|
|
@@ -140,6 +141,20 @@ loadScript(
|
|
|
140
141
|
@returns {Promise<boolean>} -- true 成功
|
|
141
142
|
@category Load Resource -->
|
|
142
143
|
|
|
144
|
+
#### loadScriptIfUndefined
|
|
145
|
+
|
|
146
|
+
Load a script from the given URL if it (`window['attribute']`) has not already been loaded.
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
loadScriptIfUndefined('jQuery', 'https://example.com/lib/jquery.min.js')
|
|
150
|
+
.then(() => {
|
|
151
|
+
console.log('jQuery is loaded.');
|
|
152
|
+
})
|
|
153
|
+
.catch(err => {
|
|
154
|
+
console.log('Failed to load jQuery.', err);
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
143
158
|
#### loadCSS
|
|
144
159
|
|
|
145
160
|
Load a CSS file from the server.
|
|
@@ -170,6 +185,24 @@ loadCSS(
|
|
|
170
185
|
@returns {Promise<boolean>} true -- 加载成功
|
|
171
186
|
@category Load Resource -->
|
|
172
187
|
|
|
188
|
+
#### loadImage
|
|
189
|
+
|
|
190
|
+
Load an image from the given URL.
|
|
191
|
+
|
|
192
|
+
The target image will be loaded in the background, and the Promise status will change after the image is loaded. If the image fails to load, the Promise status will change to `reject` with the error object. If the image is loaded successfully, the Promise status will change to `resolve` with the image object. This method can be used to preload images and cache them in the browser. It can also be used to implement lazy loading of images.
|
|
193
|
+
|
|
194
|
+
Note that this method will not add the image to the DOM.
|
|
195
|
+
|
|
196
|
+
```js
|
|
197
|
+
loadImage('https://example.com/example.png')
|
|
198
|
+
.then((img) => {
|
|
199
|
+
console.log(img);
|
|
200
|
+
})
|
|
201
|
+
.catch((err) => {
|
|
202
|
+
console.log(err);
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
173
206
|
#### windowLoaded
|
|
174
207
|
|
|
175
208
|
Check whether the page is loaded successfully (Keepe the compatibility in case that browser's `load` event has been triggered).
|
|
@@ -274,19 +307,15 @@ isValidDataResC: false
|
|
|
274
307
|
@returns {boolean} Return TRUE if the data is valid.
|
|
275
308
|
@category Util -->
|
|
276
309
|
|
|
277
|
-
####
|
|
310
|
+
#### genRndNumString
|
|
278
311
|
|
|
279
|
-
Produce a random string of number, `
|
|
312
|
+
Produce a random string of number, `genRndNumString(7)` => '7658495'.
|
|
280
313
|
|
|
281
314
|
```
|
|
282
|
-
|
|
283
|
-
|
|
315
|
+
genRndNumString(4); // '9730'
|
|
316
|
+
genRndNumString(7); // '2262490'
|
|
284
317
|
```
|
|
285
318
|
|
|
286
|
-
<!-- @param {number} n Length
|
|
287
|
-
@returns {string} Return the random string.
|
|
288
|
-
@category Util -->
|
|
289
|
-
|
|
290
319
|
#### formatDate
|
|
291
320
|
|
|
292
321
|
Return the formatted date string in the given format.
|
|
@@ -370,15 +399,15 @@ convertCamelToUnder('aBC'); // a_b_c
|
|
|
370
399
|
@returns {string} 'a_b_c'
|
|
371
400
|
@category Util -->
|
|
372
401
|
|
|
373
|
-
####
|
|
402
|
+
#### deepCopy
|
|
374
403
|
|
|
375
|
-
Clone Object deeply.
|
|
404
|
+
Copy/Clone Object deeply.
|
|
376
405
|
|
|
377
406
|
Usage:
|
|
378
407
|
|
|
379
408
|
```
|
|
380
|
-
|
|
381
|
-
|
|
409
|
+
deepCopy(['a', 'b', 'c']);
|
|
410
|
+
deepCopy('abc');
|
|
382
411
|
```
|
|
383
412
|
|
|
384
413
|
Output:
|
|
@@ -388,23 +417,6 @@ Output:
|
|
|
388
417
|
'abc'
|
|
389
418
|
```
|
|
390
419
|
|
|
391
|
-
<!-- @param {object} obj The value to clone.
|
|
392
|
-
@returns {object} Returns the deep cloned value.
|
|
393
|
-
@category Util -->
|
|
394
|
-
|
|
395
|
-
#### mTrim
|
|
396
|
-
|
|
397
|
-
Remove leading and trailing whitespace or specified characters from string.
|
|
398
|
-
|
|
399
|
-
```
|
|
400
|
-
mTrim(' 1 2 3 '); // '1 2 3'
|
|
401
|
-
mTrim('abc '); // 'abc'
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
<!-- @param {string} str The string to trim.
|
|
405
|
-
@returns {string} Trimmed string.
|
|
406
|
-
@category Util -->
|
|
407
|
-
|
|
408
420
|
### URL
|
|
409
421
|
|
|
410
422
|
#### getQueryParam
|
|
@@ -673,16 +685,14 @@ console.log(trueCount, falseCount); // 499994 500006
|
|
|
673
685
|
@returns {boolean} true 命中
|
|
674
686
|
@category Calculate and Formula -->
|
|
675
687
|
|
|
676
|
-
####
|
|
688
|
+
#### longestComSubstring
|
|
677
689
|
|
|
678
690
|
Computes the longest common substring of two strings.
|
|
679
691
|
|
|
680
|
-
<!-- ZH: 计算两个字符串的最长公共子串 -->
|
|
681
|
-
|
|
682
692
|
Usage:
|
|
683
693
|
|
|
684
694
|
```
|
|
685
|
-
|
|
695
|
+
longestComSubstring('fish', 'finish');
|
|
686
696
|
```
|
|
687
697
|
|
|
688
698
|
Output:
|
|
@@ -691,21 +701,14 @@ Output:
|
|
|
691
701
|
3
|
|
692
702
|
```
|
|
693
703
|
|
|
694
|
-
|
|
695
|
-
@param {string} bStr String
|
|
696
|
-
@returns {number} Length
|
|
697
|
-
@category Calculate and Formula -->
|
|
698
|
-
|
|
699
|
-
#### calLongestCommonSubsequence
|
|
704
|
+
#### longestComSubsequence
|
|
700
705
|
|
|
701
706
|
Computes the longest common subsequence of two strings.
|
|
702
707
|
|
|
703
|
-
<!-- ZH: 计算两个字符串的最长公共子序列 -->
|
|
704
|
-
|
|
705
708
|
Usage:
|
|
706
709
|
|
|
707
710
|
```
|
|
708
|
-
|
|
711
|
+
longestComSubsequence('fish', 'finish');
|
|
709
712
|
```
|
|
710
713
|
|
|
711
714
|
Output:
|
|
@@ -714,11 +717,6 @@ Output:
|
|
|
714
717
|
4
|
|
715
718
|
```
|
|
716
719
|
|
|
717
|
-
<!-- @param {string} aStr 字符串
|
|
718
|
-
@param {string} bStr 字符串
|
|
719
|
-
@returns {number} 长度
|
|
720
|
-
@category Calculate and Formula -->
|
|
721
|
-
|
|
722
720
|
### Browser Information
|
|
723
721
|
|
|
724
722
|
#### getBrowserInfo
|
|
@@ -884,6 +882,19 @@ npm run docs
|
|
|
884
882
|
npm run test
|
|
885
883
|
```
|
|
886
884
|
|
|
885
|
+
Returns:
|
|
886
|
+
|
|
887
|
+
| Values | Description | Type |
|
|
888
|
+
| :-------- | :--------------------------------------- | :------ |
|
|
889
|
+
| ok | The operation was successful. | string |
|
|
890
|
+
| loaded | Some assets have been loaded. | string |
|
|
891
|
+
| fail | An error occurred. | string |
|
|
892
|
+
| defined | The value is defined. | string |
|
|
893
|
+
| undefined | The value is undefined. | string |
|
|
894
|
+
| timeout | The operation timed out. | string |
|
|
895
|
+
| true | The value is true. | boolean |
|
|
896
|
+
| false | The value is false. | boolean |
|
|
897
|
+
|
|
887
898
|
## License
|
|
888
899
|
|
|
889
900
|
This software is released under the terms of the [MIT license](https://github.com/mazeyqian/mazey/blob/master/LICENSE).
|