mazey 5.0.0 → 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 CHANGED
@@ -22,7 +22,7 @@ Website: [chengchuu.github.io/mazey](https://chengchuu.github.io/mazey/)
22
22
  Use Mazey via [npm](https://www.npmjs.com/package/mazey).
23
23
 
24
24
  ```bash
25
- npm install mazey --save
25
+ npm install mazey
26
26
  ```
27
27
 
28
28
  Use Mazey from CDN.
@@ -1138,52 +1138,15 @@ MazeyLog: I am object. {a: 123, b: 456}
1138
1138
 
1139
1139
  ### Scripts
1140
1140
 
1141
- Install Dependencies:
1142
-
1143
- ```bash
1144
- npm i
1145
- ```
1146
-
1147
- Development:
1148
-
1149
- ```bash
1150
- npm run dev
1151
- ```
1152
-
1153
- Build:
1154
-
1155
- ```bash
1156
- npm run build
1157
- ```
1158
-
1159
- Test:
1160
-
1161
- ```bash
1162
- npm run test
1163
- ```
1164
-
1165
- Documentation:
1166
-
1167
- ```bash
1168
- npm run docs
1169
- ```
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
- ```
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. |
1187
1150
 
1188
1151
  ### Returns
1189
1152
 
package/README.zh-CN.md CHANGED
@@ -17,7 +17,7 @@ Mazey 是一个面向日常前端开发的函数工具库。前端生态已有
17
17
  通过 [npm](https://www.npmjs.com/package/mazey) 安装 Mazey。
18
18
 
19
19
  ```bash
20
- npm install mazey --save
20
+ npm install mazey
21
21
  ```
22
22
 
23
23
  通过内容分发网络 (Content Delivery Network,CDN) 使用 Mazey。
@@ -63,6 +63,7 @@ isNumber(z, { isInfinityAsNumber: true }); // 输出: true
63
63
  ### 目录
64
64
 
65
65
  <!-- toc - begin -->
66
+ - [目录](#目录)
66
67
  - [加载资源](#加载资源)
67
68
  - [loadScript](#loadscript)
68
69
  - [loadScriptIfUndefined](#loadscriptifundefined)
@@ -112,6 +113,9 @@ isNumber(z, { isInfinityAsNumber: true }); // 输出: true
112
113
  - [getPerformance](#getperformance)
113
114
  - [调试](#调试)
114
115
  - [genCustomConsole](#gencustomconsole)
116
+ - [开发环境](#开发环境)
117
+ - [脚本](#脚本)
118
+ - [返回值](#返回值)
115
119
  <!-- toc - end -->
116
120
 
117
121
  ### 加载资源
package/lib/index.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Mazey v5.0.0 https://github.com/chengchuu/mazey
2
+ * Mazey v5.0.1 https://github.com/chengchuu/mazey
3
3
  * (c) 2018-2026 Cheng
4
4
  * Released under the MIT License.
5
5
  */
package/lib/index.d.ts CHANGED
@@ -1286,6 +1286,22 @@ declare function isValidDate(value: unknown): boolean;
1286
1286
  /**
1287
1287
  * Return the formatted date string in the given format.
1288
1288
  *
1289
+ * Supported format tokens:
1290
+ *
1291
+ * | Token | Meaning | Range or example |
1292
+ * | ------ | -------------------------------------- | ---------------- |
1293
+ * | `yyyy` | Four-digit year | `2022` |
1294
+ * | `MM` | Two-digit month | `01`–`12` |
1295
+ * | `dd` | Two-digit day of the month | `01`–`31` |
1296
+ * | `HH` | Two-digit hour using the 24-hour clock | `00`–`23` |
1297
+ * | `hh` | Two-digit hour using the 12-hour clock | `01`–`12` |
1298
+ * | `mm` | Two-digit minute | `00`–`59` |
1299
+ * | `ss` | Two-digit second | `00`–`59` |
1300
+ * | `a` | Uppercase meridiem indicator | `AM` or `PM` |
1301
+ *
1302
+ * The function creates a native `Date` and reads its local date and time
1303
+ * fields. Timestamp output can therefore differ between runtime time zones.
1304
+ *
1289
1305
  * Usage:
1290
1306
  *
1291
1307
  * ```javascript
@@ -1310,9 +1326,9 @@ declare function isValidDate(value: unknown): boolean;
1310
1326
  * Date formatDate value: 02/11/2014
1311
1327
  * ```
1312
1328
  *
1313
- * @param {MazeyDate} dateIns Original Date
1314
- * @param {string} format Format String
1315
- * @returns {string} Return the formatted date string.
1329
+ * @param {MazeyDate} dateIns Original date value. Defaults to the current date and time.
1330
+ * @param {string} format Format string composed of supported format tokens. Defaults to `yyyy-MM-dd`.
1331
+ * @returns {string} The formatted date string.
1316
1332
  * @throws {RangeError} If `dateIns` is not a valid date.
1317
1333
  * @category Util
1318
1334
  */
package/lib/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Mazey v5.0.0 https://github.com/chengchuu/mazey
2
+ * Mazey v5.0.1 https://github.com/chengchuu/mazey
3
3
  * (c) 2018-2026 Cheng
4
4
  * Released under the MIT License.
5
5
  */
package/lib/mazey.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Mazey v5.0.0 https://github.com/chengchuu/mazey
2
+ * Mazey v5.0.1 https://github.com/chengchuu/mazey
3
3
  * (c) 2018-2026 Cheng
4
4
  * Released under the MIT License.
5
5
  */
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "mazey",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "A functional library for daily frontend work.",
5
5
  "main": "lib/index.cjs.js",
6
6
  "module": "lib/index.esm.js",
7
7
  "typings": "lib/index.d.ts",
8
8
  "types": "lib/index.d.ts",
9
9
  "mainEntryPointFilePath": "lib/index.d.ts",
10
+ "files": [
11
+ "README.md",
12
+ "LICENSE",
13
+ "lib",
14
+ "scripts/legacy"
15
+ ],
10
16
  "directories": {
11
17
  "lib": "./lib"
12
18
  },
@@ -30,8 +36,7 @@
30
36
  "pwa:validate": "node scripts/validate-pwa.js",
31
37
  "pwa:preview": "npm run docs && node scripts/preview-pages.js",
32
38
  "preview": "npm run typecheck && npm run lint && npm run build && npm run test && npm run docs",
33
- "release": "npm run preview && cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js",
34
- "release:win": "bash scripts/shell/env-win.sh && npm i --registry=https://registry.npmmirror.com && npm run release",
39
+ "release": "npm run preview && cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/legacy/release.js",
35
40
  "skill:sync": "node ./scripts/sync-prefer-mazey-skill.mjs",
36
41
  "skill:sync:dry-run": "node ./scripts/sync-prefer-mazey-skill.mjs --dry-run",
37
42
  "skill:sync:check": "node ./scripts/sync-prefer-mazey-skill.mjs --check"
@@ -85,8 +90,6 @@
85
90
  "@babel/preset-typescript": "^7.23.2",
86
91
  "@babel/runtime": "^7.23.2",
87
92
  "@babel/runtime-corejs3": "^7.23.2",
88
- "@commitlint/cli": "^17.8.1",
89
- "@commitlint/config-conventional": "^17.8.1",
90
93
  "@rollup/plugin-babel": "^6.0.3",
91
94
  "@rollup/plugin-commonjs": "^25.0.7",
92
95
  "@rollup/plugin-node-resolve": "^16.0.3",
@@ -106,14 +109,11 @@
106
109
  "eslint-plugin-standard": "^4.1.0",
107
110
  "execa": "^5.1.1",
108
111
  "html-webpack-plugin": "^5.5.3",
109
- "husky": "^8.0.3",
110
112
  "jest": "^29.7.0",
111
113
  "jest-environment-jsdom": "^29.7.0",
112
- "lint-staged": "^14.0.1",
113
114
  "markdown-toc": "^1.2.0",
114
115
  "mini-css-extract-plugin": "^2.9.2",
115
116
  "prettier": "^2.8.8",
116
- "prettier-eslint-cli": "^8.0.1",
117
117
  "rollup": "^3.29.4",
118
118
  "rollup-plugin-cleaner": "^1.0.0",
119
119
  "rollup-plugin-copy": "^3.4.0",
@@ -126,11 +126,5 @@
126
126
  "webpack": "^5.89.0",
127
127
  "webpack-cli": "^5.1.4",
128
128
  "webpack-dev-server": "^4.15.1"
129
- },
130
- "husky": {
131
- "hooks": {
132
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
133
- "pre-commit": "lint-staged"
134
- }
135
129
  }
136
130
  }
@@ -0,0 +1,56 @@
1
+ # Legacy scripts
2
+
3
+ These scripts are retained for compatibility with historical Mazey release
4
+ workflows. New project automation should use the maintained npm scripts and
5
+ GitHub Actions workflows instead.
6
+
7
+ Mazey does not install the legacy helpers' dependencies for library consumers.
8
+ Install them in the project that uses these scripts:
9
+
10
+ ```bash
11
+ npm install --save-dev date-fns@^2.30.0 execa@^5.1.1 markdown-toc@^1.2.0
12
+ ```
13
+
14
+ The canonical helper import is:
15
+
16
+ ```javascript
17
+ const { release } = require("mazey/scripts/legacy/git-helper.js");
18
+ ```
19
+
20
+ ## release
21
+
22
+ Release this project with an explicit version. The bundled entry point reads
23
+ `SCRIPTS_NPM_PACKAGE_VERSION` or `VERSION`.
24
+
25
+ Usage:
26
+
27
+ ```javascript
28
+ const pkgVersion = process.env.VERSION;
29
+ release(pkgVersion);
30
+ ```
31
+
32
+ It will be more straightforward if you use the development dependence CrossEnv.
33
+
34
+ ```shell
35
+ # Install
36
+ npm i cross-env -D
37
+
38
+ # scripts
39
+ cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/legacy/release.js
40
+ ```
41
+
42
+ ```javascript
43
+ // release.js
44
+ release();
45
+ ```
46
+
47
+ <!-- @param {string} ver Version
48
+ @returns {void} -->
49
+
50
+ ## generateToc
51
+
52
+ Generate table of contents for the markdown file.
53
+
54
+ <!-- @param {string} path Path of markdown file.
55
+ @param {array} options.hiddenHeadings Hidden headings.
56
+ @returns {void} -->
@@ -0,0 +1,77 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ /* eslint-disable no-undef */
3
+ const path = require("path");
4
+ const scriptsDirectory = path.resolve(__dirname, "..");
5
+ const _resolve = (_path) => path.resolve(scriptsDirectory, _path);
6
+ const format = require("date-fns/format");
7
+ const toc = require("markdown-toc");
8
+ const fs = require("fs");
9
+ // Generate version: 20210308.072903
10
+ const genVersion = () => {
11
+ const d = new Date();
12
+ const version = format(d, "yyyyMMdd.HHmmss");
13
+ return version;
14
+ };
15
+ const version = genVersion();
16
+ const defaultHiddenHeadings = [
17
+ "mazey",
18
+ "Install",
19
+ "Usage",
20
+ "Contributing",
21
+ "License",
22
+ "API Examples",
23
+ "Development Environment",
24
+ "Returns",
25
+ "Scripts",
26
+ "Node.js",
27
+ "TypeScript",
28
+ "Table of Contents",
29
+ ];
30
+
31
+ /**
32
+ * Generate table of contents for the markdown file.
33
+ *
34
+ * @param {string} path Path of markdown file.
35
+ * @param {array} options.hiddenHeadings Hidden headings.
36
+ * @returns {void}
37
+ */
38
+ const generateToc = (path = "../README.md", options = {
39
+ hiddenHeadings: defaultHiddenHeadings,
40
+ }) => {
41
+ console.log("Generating Table of Contents...");
42
+ options = Object.assign({
43
+ hiddenHeadings: defaultHiddenHeadings,
44
+ }, options);
45
+ const RMFilePath = _resolve(path);
46
+ // https://melvingeorge.me/blog/get-all-the-contents-from-file-as-string-nodejs
47
+ console.log("running...");
48
+ const buffer = fs.readFileSync(RMFilePath);
49
+ const fileContent = buffer.toString();
50
+ // https://github.com/jonschlinkert/markdown-toc
51
+ const removeUnnecessaryHeadings = (str) => {
52
+ return !options.hiddenHeadings.some(v => {
53
+ return str.includes(v);
54
+ });
55
+ };
56
+ let tocContent = toc(fileContent, {
57
+ filter: removeUnnecessaryHeadings,
58
+ bullets: [ "-", "-" ],
59
+ }).content;
60
+ tocContent = tocContent.replace(/[ ]{4}/gm, "");
61
+ tocContent = "<!-- toc - begin -->\n" + "- Generated with ❤️\n" + tocContent;
62
+ tocContent = tocContent + "\n<!-- toc - end -->";
63
+ // Insert to file.
64
+ // https://stackoverflow.com/questions/14177087/replace-a-string-in-a-file-with-nodejs
65
+ let newFileContent = fileContent;
66
+ // https://stackoverflow.com/questions/1979884/how-to-use-javascript-regex-over-multiple-lines
67
+ newFileContent = newFileContent.replace(/<!-- toc - begin -->[\s\S]*<!-- toc - end -->/gm, tocContent);
68
+ console.log("running...");
69
+ fs.writeFileSync(RMFilePath, newFileContent);
70
+ console.log("Generating Table of Contents is done.");
71
+ };
72
+
73
+ module.exports = {
74
+ _resolve,
75
+ version,
76
+ generateToc,
77
+ };
@@ -0,0 +1,6 @@
1
+ /* eslint-disable no-undef, @typescript-eslint/no-var-requires */
2
+ const { generateToc } = require("./build-helper");
3
+
4
+ (async () => {
5
+ generateToc();
6
+ })();
@@ -0,0 +1,164 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ /* eslint-disable no-undef */
3
+ // Git Helper
4
+ const execa = require("execa");
5
+
6
+ /**
7
+ * Release this project with an explicit version or `SCRIPTS_NPM_PACKAGE_VERSION`.
8
+ *
9
+ * Usage:
10
+ *
11
+ * ```javascript
12
+ * const pkgVersion = process.env.VERSION;
13
+ * release(pkgVersion);
14
+ * ```
15
+ *
16
+ * It will be more straightforward if you use the development dependence CrossEnv.
17
+ *
18
+ * ```shell
19
+ * # Install
20
+ * npm i cross-env -D
21
+ *
22
+ * # scripts
23
+ * cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/legacy/release.js
24
+ * ```
25
+ *
26
+ * ```javascript
27
+ * // release.js
28
+ * release();
29
+ * ```
30
+ *
31
+ * @param {string} ver Version
32
+ * @returns {void}
33
+ */
34
+ async function release (ver, { canGenerateToc = false, generateTocOnly = false, defaultBranch = "main" } = {}) {
35
+ if (!ver) {
36
+ ver = process.env.SCRIPTS_NPM_PACKAGE_VERSION;
37
+ }
38
+ if (!ver) {
39
+ console.error("Fail to get the current version.");
40
+ return;
41
+ }
42
+ const { generateToc } = require("./build-helper");
43
+ const releaseVersion = `v${ver}`;
44
+ const { stdout: releaseStdout } = await execa("echo", [ `Start release ${releaseVersion}...` ]);
45
+ console.log(releaseStdout);
46
+ // Generating Table of Contents
47
+ if (canGenerateToc) {
48
+ generateToc();
49
+ }
50
+ if (generateTocOnly) {
51
+ return;
52
+ }
53
+ // Commit
54
+ await gitCommit(`${releaseVersion} stage`);
55
+ // Marge
56
+ await gitMergeMain2Release(defaultBranch);
57
+ // Build
58
+ await execa("npm", [ "run", "preview" ]);
59
+ await execa("npm", [ "publish" ]);
60
+ // Commit Again
61
+ await gitCommit(releaseVersion);
62
+ // Push
63
+ console.log("Pushing to the remote Git...");
64
+ await gitTagPush(releaseVersion);
65
+ await gitPush();
66
+ console.log("All done.");
67
+ }
68
+
69
+ /**
70
+ * Push git tag.
71
+ *
72
+ * @example
73
+ * ```
74
+ * await gitTagPush("v1.0.0");
75
+ * ```
76
+ *
77
+ * @param {string} ver Release version
78
+ * @returns {boolean} Is success
79
+ */
80
+ async function gitTagPush (ver = "") {
81
+ if (!ver) {
82
+ console.error("Fail to get the current version.");
83
+ return false;
84
+ }
85
+ if (!ver.startsWith("v")) {
86
+ ver = `v${ver}`;
87
+ }
88
+ await execa("git", [ "tag", "-a", `${ver}`, "-m", `Release ${ver}` ]);
89
+ await execa("git", [ "push", "origin", `refs/tags/${ver}` ]);
90
+ return true;
91
+ }
92
+
93
+ /**
94
+ * Push code.
95
+ */
96
+ async function gitPush () {
97
+ try {
98
+ await execa("git", [ "push" ], { stdio: "pipe" });
99
+ } catch (error) {
100
+ console.log("Error:", error.message);
101
+ const { stdout: currentBranch } = await execa("git", [ "branch", "--show-current" ], { stdio: "pipe" });
102
+ console.log(`Current Branch: ${currentBranch}`);
103
+ await execa("git", [ "push", "--set-upstream", "origin", currentBranch ]);
104
+ }
105
+ return true;
106
+ }
107
+
108
+ /**
109
+ * Merge main to current branch.
110
+ */
111
+ async function gitMergeMain2Release (defaultBranch = "main") {
112
+ const currentBranch = await getGitCurrentBranch();
113
+ await execa("git", [ "checkout", defaultBranch ]);
114
+ await execa("git", [ "pull" ]);
115
+ await execa("git", [ "checkout", currentBranch ]);
116
+ await execa("git", [ "merge", defaultBranch ]);
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * Alias of `gitMergeMain2Release`.
122
+ */
123
+ async function gitMergeMaster2Release (defaultBranch = "main") {
124
+ return await gitMergeMain2Release(defaultBranch);
125
+ }
126
+
127
+ /**
128
+ * Get git current branch.
129
+ */
130
+ async function getGitCurrentBranch () {
131
+ let currentBranch = "";
132
+ try {
133
+ ({ stdout: currentBranch } = await execa("git", [ "branch", "--show-current" ], { stdio: "pipe" }));
134
+ } catch (error) {
135
+ ({ stdout: currentBranch } = await execa("git", [ "rev-parse", "--abbrev-ref", "HEAD" ], { stdio: "pipe" }));
136
+ }
137
+ console.log(`Current Branch: ${currentBranch}`);
138
+ return currentBranch;
139
+ }
140
+
141
+ /**
142
+ * Commit current code.
143
+ */
144
+ async function gitCommit (releaseVersion = 0) {
145
+ const { stdout: diffStdout } = await execa("git", [ "diff" ], { stdio: "pipe" });
146
+ if (diffStdout) {
147
+ console.log("Committing changes...");
148
+ await execa("git", [ "add", "-A" ]);
149
+ await execa("git", [ "commit", "-m", `release: ${releaseVersion}` ]);
150
+ } else {
151
+ console.log("No changes to commit.");
152
+ }
153
+ return true;
154
+ }
155
+
156
+ module.exports = {
157
+ release,
158
+ gitPush,
159
+ gitMergeMaster2Release, // Deprecated
160
+ gitMergeMain2Release,
161
+ getGitCurrentBranch,
162
+ gitCommit,
163
+ gitTagPush,
164
+ };
@@ -0,0 +1,9 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ /* eslint-disable no-undef */
3
+ // release
4
+ const { release } = require("./git-helper.js");
5
+ const pkgVersion = process.env.SCRIPTS_NPM_PACKAGE_VERSION || process.env.VERSION;
6
+
7
+ console.log("release: SCRIPTS_NPM_PACKAGE_VERSION", process.env.SCRIPTS_NPM_PACKAGE_VERSION);
8
+
9
+ release(pkgVersion, { canGenerateToc: true, generateTocOnly: true });