mazey 4.13.2 → 5.0.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 +56 -36
- package/README.zh-CN.md +1032 -193
- package/lib/global.d.ts +5 -9
- package/lib/index.cjs.js +2 -2
- package/lib/index.d.ts +115 -45
- package/lib/index.esm.js +2 -2
- package/lib/mazey.min.js +2 -2
- package/lib/typing.d.ts +2 -2
- package/package.json +28 -23
- package/scripts/legacy/README.md +56 -0
- package/scripts/{build-helper.js → legacy/build-helper.js} +2 -1
- package/scripts/{dev.js → legacy/dev.js} +1 -2
- package/scripts/{git-helper.js → legacy/git-helper.js} +3 -3
- package/scripts/{release.js → legacy/release.js} +1 -1
- package/scripts/README.md +0 -38
- package/scripts/change-package-name.js +0 -15
- package/scripts/rollup.config.mjs +0 -139
package/README.md
CHANGED
|
@@ -12,21 +12,28 @@ English | [简体中文](https://github.com/chengchuu/mazey/blob/main/README.zh-
|
|
|
12
12
|
|
|
13
13
|
Mazey is a functional library for daily frontend work. There are already many excellent libraries for frontend 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 frontend needs.
|
|
14
14
|
|
|
15
|
+
Website: [chengchuu.github.io/mazey](https://chengchuu.github.io/mazey/)
|
|
16
|
+
|
|
17
|
+
- [Interactive playground](https://chengchuu.github.io/mazey/playground/)
|
|
18
|
+
- [TypeScript API documentation](https://chengchuu.github.io/mazey/api/)
|
|
19
|
+
|
|
15
20
|
## Install
|
|
16
21
|
|
|
17
22
|
Use Mazey via [npm](https://www.npmjs.com/package/mazey).
|
|
18
23
|
|
|
19
24
|
```bash
|
|
20
|
-
npm install mazey
|
|
25
|
+
npm install mazey
|
|
21
26
|
```
|
|
22
27
|
|
|
23
28
|
Use Mazey from CDN.
|
|
24
29
|
|
|
25
30
|
```html
|
|
26
|
-
<script src="
|
|
31
|
+
<script src="https://cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js"></script>
|
|
27
32
|
```
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
You can also download and serve the
|
|
35
|
+
[latest browser bundle](https://cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js)
|
|
36
|
+
yourself.
|
|
30
37
|
|
|
31
38
|
## Usage
|
|
32
39
|
|
|
@@ -48,7 +55,7 @@ isNumber(z, { isInfinityAsNumber: true }); // Output: true
|
|
|
48
55
|
Import from CDN.
|
|
49
56
|
|
|
50
57
|
```html
|
|
51
|
-
<script src="
|
|
58
|
+
<script src="https://cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js"></script>
|
|
52
59
|
<script>
|
|
53
60
|
const x = 123;
|
|
54
61
|
mazey.isNumber(x); // Output: true
|
|
@@ -57,7 +64,8 @@ Import from CDN.
|
|
|
57
64
|
|
|
58
65
|
## API Examples
|
|
59
66
|
|
|
60
|
-
There are some examples maintained by hand below. For more information, please check the
|
|
67
|
+
There are some examples maintained by hand below. For more information, please check the
|
|
68
|
+
[full API documentation](https://chengchuu.github.io/mazey/api/).
|
|
61
69
|
|
|
62
70
|
### Table of Contents
|
|
63
71
|
|
|
@@ -75,6 +83,7 @@ There are some examples maintained by hand below. For more information, please c
|
|
|
75
83
|
- [isValidData](#isvaliddata)
|
|
76
84
|
- [genRndNumString](#genrndnumstring)
|
|
77
85
|
- [formatDate](#formatdate)
|
|
86
|
+
- [isValidDate](#isvaliddate)
|
|
78
87
|
- [generateCalendarVersion](#generatecalendarversion)
|
|
79
88
|
- [formatDurationFromMs](#formatdurationfromms)
|
|
80
89
|
- [deepCopy](#deepcopy)
|
|
@@ -362,9 +371,41 @@ Number formatDate value: 2022-01-11 14:07:15
|
|
|
362
371
|
Date formatDate value: 02/11/2014
|
|
363
372
|
```
|
|
364
373
|
|
|
374
|
+
#### isValidDate
|
|
375
|
+
|
|
376
|
+
Check whether an unknown value represents a valid date. The function accepts
|
|
377
|
+
`Date` instances, finite millisecond timestamps, supported local date strings,
|
|
378
|
+
and ISO 8601 strings with `Z` or a numeric timezone offset.
|
|
379
|
+
|
|
380
|
+
Supported string forms are `YYYY-MM-DD`, `YYYY-MM-DD HH:mm[:ss]`,
|
|
381
|
+
`YYYY-MM-DDTHH:mm[:ss]`, and the same `T`-separated date-time with `Z` or a
|
|
382
|
+
`+HH:mm`/`-HH:mm` offset. Zoned strings may include 1-3 millisecond digits.
|
|
383
|
+
|
|
384
|
+
Structured strings are parsed into numeric components and validated strictly.
|
|
385
|
+
Invalid calendar dates such as `"2020-02-30"` are rejected instead of being
|
|
386
|
+
normalized into another date.
|
|
387
|
+
|
|
388
|
+
Usage:
|
|
389
|
+
|
|
390
|
+
```javascript
|
|
391
|
+
const ret1 = isValidDate(1577877720000);
|
|
392
|
+
const ret2 = isValidDate("2020-01-01 11:22");
|
|
393
|
+
const ret3 = isValidDate("2020-02-30");
|
|
394
|
+
const ret4 = isValidDate(new Date("invalid"));
|
|
395
|
+
console.log(ret1, ret2, ret3, ret4);
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Output:
|
|
399
|
+
|
|
400
|
+
```text
|
|
401
|
+
true true false false
|
|
402
|
+
```
|
|
403
|
+
|
|
365
404
|
#### generateCalendarVersion
|
|
366
405
|
|
|
367
|
-
Generate
|
|
406
|
+
Generate a local-time Calendar Versioning string using the conceptual format `yyyy.MMdd.HHmmss`. Leading zeroes are removed from each numeric segment for Semantic Versioning compatibility.
|
|
407
|
+
|
|
408
|
+
Versions increase with the supplied local date and time under normal clock progression. Because the function intentionally follows local time, a manual clock rollback or daylight-saving fallback can produce a value lower than one generated earlier.
|
|
368
409
|
|
|
369
410
|
Usage:
|
|
370
411
|
|
|
@@ -1026,7 +1067,6 @@ Get page load time(`PerformanceNavigationTiming`).
|
|
|
1026
1067
|
|
|
1027
1068
|
This function uses the [`PerformanceNavigationTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming) API to get page load time data.
|
|
1028
1069
|
The `PerformanceNavigationTiming` API provides more accurate and detailed information about page load time than the deprecated [`PerformanceTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming) API.
|
|
1029
|
-
If you are using an older browser that does not support `PerformanceNavigationTiming`, you can still use the `PerformanceTiming` API by using the previous version of this library ([`v3.9.7`](https://github.com/chengchuu/mazey/releases/tag/v3.9.7)).
|
|
1030
1070
|
|
|
1031
1071
|
Usage:
|
|
1032
1072
|
|
|
@@ -1098,35 +1138,15 @@ MazeyLog: I am object. {a: 123, b: 456}
|
|
|
1098
1138
|
|
|
1099
1139
|
### Scripts
|
|
1100
1140
|
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
npm
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
npm run dev
|
|
1111
|
-
```
|
|
1112
|
-
|
|
1113
|
-
Build:
|
|
1114
|
-
|
|
1115
|
-
```bash
|
|
1116
|
-
npm run build
|
|
1117
|
-
```
|
|
1118
|
-
|
|
1119
|
-
Test:
|
|
1120
|
-
|
|
1121
|
-
```bash
|
|
1122
|
-
npm run test
|
|
1123
|
-
```
|
|
1124
|
-
|
|
1125
|
-
Documentation:
|
|
1126
|
-
|
|
1127
|
-
```bash
|
|
1128
|
-
npm run docs
|
|
1129
|
-
```
|
|
1141
|
+
| Command | Purpose |
|
|
1142
|
+
| --------------------- | --------------------------------------------------------------- |
|
|
1143
|
+
| `npm install` | Install development dependencies. |
|
|
1144
|
+
| `npm run dev` | Start the website and playground development server. |
|
|
1145
|
+
| `npm run build` | Build the publishable package files. |
|
|
1146
|
+
| `npm test` | Run the Jest test suite. |
|
|
1147
|
+
| `npm run docs` | Build and validate the complete GitHub Pages artifact. |
|
|
1148
|
+
| `npm run preview` | Run the full type, lint, build, test, and documentation checks. |
|
|
1149
|
+
| `npm run pwa:preview` | Serve the production Pages artifact at the `/mazey/` base path. |
|
|
1130
1150
|
|
|
1131
1151
|
### Returns
|
|
1132
1152
|
|