mazey 4.13.1 → 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 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="//cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js"></script>
31
+ <script src="https://cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js"></script>
27
32
  ```
28
33
 
29
- Of course, you can also download and serve the file [jsdelivr/lib/mazey.min.js](https://cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js) yourself.
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="//cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js"></script>
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 [full documentation](https://mazey.cn/t/m).
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,9 +83,11 @@ 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)
90
+ - [deepFreeze](#deepfreeze)
81
91
  - [debounce](#debounce)
82
92
  - [throttle](#throttle)
83
93
  - [convertCamelToKebab](#convertcameltokebab)
@@ -361,9 +371,41 @@ Number formatDate value: 2022-01-11 14:07:15
361
371
  Date formatDate value: 02/11/2014
362
372
  ```
363
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
+
364
404
  #### generateCalendarVersion
365
405
 
366
- Generate an increasing Calendar Versioning string using the conceptual format `yyyy.MMdd.HHmmss`. Leading zeroes are removed from each numeric segment for Semantic Versioning compatibility.
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.
367
409
 
368
410
  Usage:
369
411
 
@@ -426,6 +468,31 @@ Output:
426
468
  abc
427
469
  ```
428
470
 
471
+ #### deepFreeze
472
+
473
+ Recursively freeze an object and its nested enumerable values. Primitive values
474
+ and objects that are already frozen are returned unchanged.
475
+
476
+ Usage:
477
+
478
+ ```javascript
479
+ const config = deepFreeze({
480
+ api: {
481
+ timeout: 5000,
482
+ },
483
+ });
484
+
485
+ console.log(Object.isFrozen(config));
486
+ console.log(Object.isFrozen(config.api));
487
+ ```
488
+
489
+ Output:
490
+
491
+ ```text
492
+ true
493
+ true
494
+ ```
495
+
429
496
  #### debounce
430
497
 
431
498
  Debounce
@@ -1000,7 +1067,6 @@ Get page load time(`PerformanceNavigationTiming`).
1000
1067
 
1001
1068
  This function uses the [`PerformanceNavigationTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming) API to get page load time data.
1002
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.
1003
- 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)).
1004
1070
 
1005
1071
  Usage:
1006
1072
 
@@ -1102,6 +1168,23 @@ Documentation:
1102
1168
  npm run docs
1103
1169
  ```
1104
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
+
1105
1188
  ### Returns
1106
1189
 
1107
1190
  | Values | Description | Type |