zhangwenyan-utils 0.0.0-stage → 1.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
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # zhangwenyan-utils
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 包,使用 CommonJS 规范,包含两个独立的 JS 模块。
4
+
5
+ ## 模块说明
6
+
7
+ ### math 模块
8
+ - 属性:`PI`(圆周率)、`version`(模块版本)
9
+ - 方法:`add(a, b)` —— 计算两数之和并打印日志
10
+
11
+ ### greet 模块
12
+ - 属性:`author`(作者)、`defaultName`(默认称呼)
13
+ - 方法:`sayHello(name)` —— 打印问候日志
14
+
15
+ ## 使用方法
16
+
17
+ ```js
18
+ const { math, greet } = require('zhangwenyan-utils');
19
+
20
+ console.log(math.PI);
21
+ math.add(3, 5);
22
+
23
+ console.log(greet.author);
24
+ greet.sayHello('张文龑');
25
+ ```
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // index.js:npm 包的统一入口,汇总两个模块
2
+ const math = require('./lib/math');
3
+ const greet = require('./lib/greet');
4
+
5
+ module.exports = {
6
+ math,
7
+ greet
8
+ };
package/lib/greet.js ADDED
@@ -0,0 +1,14 @@
1
+ // greet.js 模块:问候模块(CommonJS 规范)
2
+ const greet = {
3
+ // 属性:模块作者
4
+ author: '张文龑',
5
+ // 属性:默认称呼
6
+ defaultName: '同学',
7
+ // 方法:打印问候日志
8
+ sayHello(name) {
9
+ const target = name || this.defaultName;
10
+ console.log(`[greet] 调用 sayHello 方法:你好,${target}!欢迎使用本模块。`);
11
+ }
12
+ };
13
+
14
+ module.exports = greet;
package/lib/math.js ADDED
@@ -0,0 +1,15 @@
1
+ // math.js 模块:数学计算模块(CommonJS 规范)
2
+ const math = {
3
+ // 属性:圆周率
4
+ PI: 3.141592653589793,
5
+ // 属性:模块版本
6
+ version: '1.0.0',
7
+ // 方法:求和并打印日志
8
+ add(a, b) {
9
+ const result = a + b;
10
+ console.log(`[math] 调用 add 方法:${a} + ${b} = ${result}`);
11
+ return result;
12
+ }
13
+ };
14
+
15
+ module.exports = math;
package/package.json CHANGED
@@ -1,6 +1,22 @@
1
1
  {
2
2
  "name": "zhangwenyan-utils",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "MVVM实验六:包含 math 与 greet 两个模块的 npm 包,每个模块提供属性和打印日志的方法",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test.js"
8
+ },
9
+ "keywords": [
10
+ "npm",
11
+ "utils",
12
+ "math",
13
+ "greet",
14
+ "实验六"
15
+ ],
16
+ "author": "张文龑",
17
+ "license": "ISC",
18
+ "files": [
19
+ "index.js",
20
+ "lib"
21
+ ]
22
+ }