mazey 3.6.2 → 3.6.4
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 +43 -31
- package/lib/index.cjs.js +259 -135
- package/lib/index.d.ts +101 -26
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +253 -135
- package/lib/mazey.min.js +2 -2
- package/package.json +2 -1
- package/scripts/README.md +8 -0
- package/scripts/build-helper.js +23 -10
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
English | [简体中文](https://github.com/mazeyqian/mazey/blob/master/
|
|
1
|
+
English | [简体中文](https://github.com/mazeyqian/mazey/blob/master/README_ZH.md)
|
|
2
2
|
|
|
3
3
|
# mazey
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ English | [简体中文](https://github.com/mazeyqian/mazey/blob/master/README_C
|
|
|
10
10
|
[l-image]: https://img.shields.io/npm/l/mazey
|
|
11
11
|
[l-url]: https://github.com/mazeyqian/mazey
|
|
12
12
|
|
|
13
|
-
Mazey's functional library for daily front-end work. There are already many excellent libraries for front-end development, but creating a file named
|
|
13
|
+
Mazey's functional library for daily front-end work. There are already many excellent libraries for front-end development, but creating a file named `utils.js` or `common.js` is generally used to supply common functions in projects. It's boring to copy similar functions across multiple projects. That's why I've created this library and will keep updating it to serve as a reliable resource for front-end needs.
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
@@ -37,7 +37,9 @@ Import from [npm](https://www.npmjs.com/package/mazey).
|
|
|
37
37
|
```
|
|
38
38
|
import { isNumber } from 'mazey';
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const x = Infinity;
|
|
41
|
+
isNumber(x); // <=> typeof x === 'string' && !isNaN(x) && isFinite(x)
|
|
42
|
+
// Output: false
|
|
41
43
|
```
|
|
42
44
|
|
|
43
45
|
Import from CDN.
|
|
@@ -45,7 +47,9 @@ Import from CDN.
|
|
|
45
47
|
```
|
|
46
48
|
<script type="text/javascript" src="//i.mazey.net/mazey/lib/mazey.min.js"></script>
|
|
47
49
|
<script>
|
|
48
|
-
|
|
50
|
+
const x = Infinity;
|
|
51
|
+
mazey.isNumber(x, { isUnFiniteAsNumber: true }); // <=> typeof x === 'string' && !isNaN(x)
|
|
52
|
+
// Output: true
|
|
49
53
|
</script>
|
|
50
54
|
```
|
|
51
55
|
|
|
@@ -63,14 +67,14 @@ There ara some examples maintained by hand below. For more information, please c
|
|
|
63
67
|
* [windowLoaded](#windowloaded)
|
|
64
68
|
- [Util](#util)
|
|
65
69
|
* [isNumber](#isnumber)
|
|
66
|
-
* [
|
|
70
|
+
* [isJSONString](#isjsonstring)
|
|
67
71
|
* [isValidData](#isvaliddata)
|
|
68
72
|
* [generateRndNum](#generaterndnum)
|
|
69
73
|
* [formatDate](#formatdate)
|
|
70
74
|
* [debounce](#debounce)
|
|
71
75
|
* [throttle](#throttle)
|
|
72
|
-
* [
|
|
73
|
-
* [
|
|
76
|
+
* [convertCamelToKebab](#convertcameltokebab)
|
|
77
|
+
* [convertCamelToUnder](#convertcameltounder)
|
|
74
78
|
* [deepCopyObject](#deepcopyobject)
|
|
75
79
|
* [mTrim](#mtrim)
|
|
76
80
|
- [URL](#url)
|
|
@@ -210,15 +214,15 @@ isNumber(NaN, { isNaNAsNumber: true, isUnFiniteAsNumber: true }); // true
|
|
|
210
214
|
@returns {boolean} true 是数字
|
|
211
215
|
@category Util -->
|
|
212
216
|
|
|
213
|
-
####
|
|
217
|
+
#### isJSONString
|
|
214
218
|
|
|
215
219
|
Check whether it is a valid JSON string.
|
|
216
220
|
|
|
217
221
|
Usage:
|
|
218
222
|
|
|
219
223
|
```
|
|
220
|
-
|
|
221
|
-
|
|
224
|
+
isJSONString(`['a', 'b', 'c']`);
|
|
225
|
+
isJSONString(`["a", "b", "c"]`);
|
|
222
226
|
```
|
|
223
227
|
|
|
224
228
|
Output:
|
|
@@ -340,26 +344,26 @@ Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
|
|
|
340
344
|
|
|
341
345
|
<!-- @category Util -->
|
|
342
346
|
|
|
343
|
-
####
|
|
347
|
+
#### convertCamelToKebab
|
|
344
348
|
|
|
345
349
|
Transfer CamelCase to KebabCase.
|
|
346
350
|
|
|
347
351
|
```
|
|
348
|
-
|
|
349
|
-
|
|
352
|
+
convertCamelToKebab('ABC'); // a-b-c
|
|
353
|
+
convertCamelToKebab('aBC'); // a-b-c
|
|
350
354
|
```
|
|
351
355
|
|
|
352
356
|
<!-- @param {string} camelCase 'aBC' or 'ABC'
|
|
353
357
|
@returns {string} 'a-b-c'
|
|
354
358
|
@category Util -->
|
|
355
359
|
|
|
356
|
-
####
|
|
360
|
+
#### convertCamelToUnder
|
|
357
361
|
|
|
358
362
|
Transfer CamelCase to Underscore.
|
|
359
363
|
|
|
360
364
|
```
|
|
361
|
-
|
|
362
|
-
|
|
365
|
+
convertCamelToUnder('ABC'); // a_b_c
|
|
366
|
+
convertCamelToUnder('aBC'); // a_b_c
|
|
363
367
|
```
|
|
364
368
|
|
|
365
369
|
<!-- @param {string} camelCase 'aBC' or 'ABC'
|
|
@@ -465,6 +469,10 @@ Usage:
|
|
|
465
469
|
```
|
|
466
470
|
getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');
|
|
467
471
|
getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);
|
|
472
|
+
getDomain('http://example.com:7890/test/thanks', ['hostname']);
|
|
473
|
+
getDomain('http://example.com:7890/test/thanks', ['host']); // With Port
|
|
474
|
+
getDomain('http://example.com:7890/test/thanks', ['origin']);
|
|
475
|
+
getDomain('http://example.com:7890/test/thanks?id=1', ['origin', 'pathname', 'search']);
|
|
468
476
|
```
|
|
469
477
|
|
|
470
478
|
Output:
|
|
@@ -472,10 +480,14 @@ Output:
|
|
|
472
480
|
```
|
|
473
481
|
example.com
|
|
474
482
|
example.com/test/thanks
|
|
483
|
+
example.com
|
|
484
|
+
example.com:7890
|
|
485
|
+
http://example.com:7890
|
|
486
|
+
http://example.com:7890/test/thanks?id=1
|
|
475
487
|
```
|
|
476
488
|
|
|
477
489
|
<!-- @param {string} url
|
|
478
|
-
@param {array} rules Object.keys(location), ['href', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
|
|
490
|
+
@param {array} rules Object.keys(location), ['href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
|
|
479
491
|
@category URL -->
|
|
480
492
|
|
|
481
493
|
#### updateQueryParam
|
|
@@ -730,7 +742,7 @@ Output:
|
|
|
730
742
|
Results:
|
|
731
743
|
|
|
732
744
|
| Attribute | Description | Type | Values |
|
|
733
|
-
|
|
|
745
|
+
| :------------ | :------------ | :------------ | :------------ |
|
|
734
746
|
| **system** | System | string | android, ios, windows, macos, linux |
|
|
735
747
|
| systemVs | System version | string | windows: 2000, xp, 2003, vista, 7, 8, 8.1, 10 <br />macos: ... |
|
|
736
748
|
| platform | Platform | string | desktop, mobile |
|
|
@@ -801,19 +813,19 @@ Output:
|
|
|
801
813
|
|
|
802
814
|
Results:
|
|
803
815
|
|
|
804
|
-
|
|
|
805
|
-
|
|
|
806
|
-
| DNS
|
|
807
|
-
| Connection
|
|
808
|
-
| Requests and
|
|
809
|
-
| White
|
|
810
|
-
| DomReady |
|
|
811
|
-
| Onload |
|
|
812
|
-
| EventEnd |
|
|
813
|
-
| Unload |
|
|
814
|
-
| Redirect |
|
|
815
|
-
| SSL |
|
|
816
|
-
| Download |
|
|
816
|
+
| Attribute | Description | Type | Values |
|
|
817
|
+
| :------------ | :------------ | :------------ | :------------ |
|
|
818
|
+
| dns_time | DNS Lookup | number | domainLookupEnd - domainLookupStart |
|
|
819
|
+
| tcp_time | Connection Negotiation | number | connectEnd - connectStart |
|
|
820
|
+
| response_time | Requests and Responses | number | responseStart - requestStart |
|
|
821
|
+
| white_time | White Screen | number | responseStart - navigationStart |
|
|
822
|
+
| domready_time | DomReady | number | domContentLoadedEventStart - navigationStart |
|
|
823
|
+
| onload_time | Onload | number | loadEventStart - navigationStart |
|
|
824
|
+
| render_time | EventEnd | number | loadEventEnd -navigationStart |
|
|
825
|
+
| unload_time | Unload | number | (Optional) unloadEventEnd - unloadEventStart |
|
|
826
|
+
| redirect_time | Redirect | number | (Optional) redirectEnd - redirectStart |
|
|
827
|
+
| ssl_time | SSL | number | (Optional) connectEnd - secureConnectionStart |
|
|
828
|
+
| download_time | Download | number | (Optional) responseEnd - responseStart |
|
|
817
829
|
|
|
818
830
|
<!-- @param {boolean} camelCase -- false(默认) 以下划线形式返回数据 true 以驼峰形式返回数据
|
|
819
831
|
@returns {Promise<object>} 加载数据
|