yh-mvvm-tools 0.0.0-stage → 1.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
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # yh-mvvm-tools
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ MVVM 前端框架开发技术 第六次实验 npm 包。包内包含两个 JS 模块,每个模块都提供了属性与方法,
4
+ 方法被调用时只负责打印日志。
5
+
6
+ ## 安装
7
+
8
+ ```bash
9
+ npm install yh-mvvm-tools
10
+ ```
11
+
12
+ ## 使用
13
+
14
+ ```js
15
+ const tools = require('yh-mvvm-tools');
16
+
17
+ console.log(tools.version); // 1.0.0
18
+ console.log(tools.stringUtils.name); // stringUtils
19
+ console.log(tools.mathUtils.name); // mathUtils
20
+
21
+ tools.stringUtils.capitalize('mvvm');
22
+ tools.mathUtils.add(1, 2);
23
+ ```
24
+
25
+ ## API
26
+
27
+ ### stringUtils
28
+
29
+ | 类型 | 名称 | 说明 |
30
+ | --- | --- | --- |
31
+ | 属性 | name / author / version | 模块名称、作者、版本 |
32
+ | 方法 | capitalize(str) | 首字母大写并打印日志 |
33
+ | 方法 | repeat(str, times) | 重复字符串并打印日志 |
34
+ | 方法 | toKebabCase(str) | 转短横线命名并打印日志 |
35
+
36
+ ### mathUtils
37
+
38
+ | 类型 | 名称 | 说明 |
39
+ | --- | --- | --- |
40
+ | 属性 | name / author / version | 模块名称、作者、版本 |
41
+ | 方法 | add(a, b) | 求和并打印日志 |
42
+ | 方法 | multiply(a, b) | 求积并打印日志 |
43
+ | 方法 | isEven(n) | 判断偶数并打印日志 |
44
+
45
+ ## License
46
+
47
+ MIT
package/index.js ADDED
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * yh-mvvm-tools 入口文件
5
+ * 汇总两个子模块,统一对外暴露:version 属性 + stringUtils / mathUtils 两个模块对象
6
+ */
7
+
8
+ const stringUtils = require('./lib/string.js');
9
+ const mathUtils = require('./lib/math.js');
10
+
11
+ const version = '1.0.0';
12
+ const author = '余鸿宇';
13
+ const description = 'MVVM 前端框架开发技术 第六次实验:包含两个 JS 模块的 npm 包示例';
14
+
15
+ console.log('[yh-mvvm-tools] 包已加载,版本:', version);
16
+
17
+ module.exports = {
18
+ version,
19
+ author,
20
+ description,
21
+ stringUtils,
22
+ mathUtils
23
+ };
package/lib/math.js ADDED
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 数字工具模块
5
+ * 提供 3 个属性(name / author / version)和 3 个方法(add / multiply / isEven)
6
+ * 方法内部只负责 console.log 打印日志,并返回一个简单结果
7
+ */
8
+
9
+ const name = 'mathUtils';
10
+ const author = '余鸿宇';
11
+ const version = '1.0.0';
12
+
13
+ function add(a, b) {
14
+ console.log('[mathUtils] 调用 add,参数:', a, b);
15
+ const result = Number(a) + Number(b);
16
+ console.log('[mathUtils] add 返回:', result);
17
+ return result;
18
+ }
19
+
20
+ function multiply(a, b) {
21
+ console.log('[mathUtils] 调用 multiply,参数:', a, b);
22
+ const result = Number(a) * Number(b);
23
+ console.log('[mathUtils] multiply 返回:', result);
24
+ return result;
25
+ }
26
+
27
+ function isEven(n) {
28
+ console.log('[mathUtils] 调用 isEven,参数:', n);
29
+ const result = Number(n) % 2 === 0;
30
+ console.log('[mathUtils] isEven 返回:', result);
31
+ return result;
32
+ }
33
+
34
+ module.exports = {
35
+ name,
36
+ author,
37
+ version,
38
+ add,
39
+ multiply,
40
+ isEven
41
+ };
package/lib/string.js ADDED
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 字符串工具模块
5
+ * 提供 3 个属性(name / author / version)和 3 个方法(capitalize / repeat / toKebabCase)
6
+ * 方法内部只负责 console.log 打印日志,并返回一个简单结果
7
+ */
8
+
9
+ const name = 'stringUtils';
10
+ const author = '余鸿宇';
11
+ const version = '1.0.0';
12
+
13
+ function capitalize(str) {
14
+ console.log('[stringUtils] 调用 capitalize,参数:', str);
15
+ const result = String(str).charAt(0).toUpperCase() + String(str).slice(1);
16
+ console.log('[stringUtils] capitalize 返回:', result);
17
+ return result;
18
+ }
19
+
20
+ function repeat(str, times) {
21
+ console.log('[stringUtils] 调用 repeat,参数:', str, times);
22
+ const result = String(str).repeat(Number(times) || 0);
23
+ console.log('[stringUtils] repeat 返回:', result);
24
+ return result;
25
+ }
26
+
27
+ function toKebabCase(str) {
28
+ console.log('[stringUtils] 调用 toKebabCase,参数:', str);
29
+ const result = String(str)
30
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
31
+ .replace(/[\s_]+/g, '-')
32
+ .toLowerCase();
33
+ console.log('[stringUtils] toKebabCase 返回:', result);
34
+ return result;
35
+ }
36
+
37
+ module.exports = {
38
+ name,
39
+ author,
40
+ version,
41
+ capitalize,
42
+ repeat,
43
+ toKebabCase
44
+ };
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "yh-mvvm-tools",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "MVVM 前端框架开发技术 第六次实验 npm 包:包含 stringUtils 与 mathUtils 两个 JS 模块",
5
+ "main": "index.js",
6
+ "files": [
7
+ "index.js",
8
+ "lib",
9
+ "README.md"
10
+ ],
11
+ "keywords": [
12
+ "mvvm",
13
+ "utils",
14
+ "string",
15
+ "math",
16
+ "homework"
17
+ ],
18
+ "author": "余鸿宇",
19
+ "license": "MIT"
20
+ }