mazey 4.13.2 → 5.0.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 +63 -6
- package/README.zh-CN.md +1028 -193
- package/lib/global.d.ts +5 -9
- package/lib/index.cjs.js +2 -2
- package/lib/index.d.ts +96 -42
- package/lib/index.esm.js +2 -2
- package/lib/mazey.min.js +2 -2
- package/lib/typing.d.ts +2 -2
- package/package.json +22 -11
- package/scripts/README.md +0 -38
- package/scripts/build-helper.js +0 -76
- package/scripts/change-package-name.js +0 -15
- package/scripts/dev.js +0 -7
- package/scripts/git-helper.js +0 -164
- package/scripts/release.js +0 -9
- package/scripts/rollup.config.mjs +0 -139
package/README.md
CHANGED
|
@@ -12,6 +12,11 @@ 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).
|
|
@@ -23,10 +28,12 @@ npm install mazey --save
|
|
|
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
|
|
|
@@ -1128,6 +1168,23 @@ Documentation:
|
|
|
1128
1168
|
npm run docs
|
|
1129
1169
|
```
|
|
1130
1170
|
|
|
1171
|
+
The documentation command builds the production website, playground, and TypeDoc API into `docs`,
|
|
1172
|
+
then validates the final SEO and PWA metadata. Use the focused checks while developing:
|
|
1173
|
+
|
|
1174
|
+
```bash
|
|
1175
|
+
npm run typecheck
|
|
1176
|
+
npm run lint
|
|
1177
|
+
npm run build:site
|
|
1178
|
+
npm run seo:validate
|
|
1179
|
+
npm run pwa:validate
|
|
1180
|
+
```
|
|
1181
|
+
|
|
1182
|
+
Preview the production Pages artifact at `http://127.0.0.1:4173/mazey/`:
|
|
1183
|
+
|
|
1184
|
+
```bash
|
|
1185
|
+
npm run pwa:preview
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1131
1188
|
### Returns
|
|
1132
1189
|
|
|
1133
1190
|
| Values | Description | Type |
|