@fsyyft/npmjs-add 0.0.2 → 0.1.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 +159 -0
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -4
- package/dist/index.d.ts +27 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# @fsyyft/npmjs-add
|
|
2
|
+
|
|
3
|
+
> 一个简单的加法工具库
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@fsyyft/npmjs-add)
|
|
6
|
+
[](https://www.npmjs.com/package/@fsyyft/npmjs-add)
|
|
7
|
+
[](https://www.npmjs.com/package/@fsyyft/npmjs-add)
|
|
8
|
+
[](https://github.com/fsyyft-ts/npmjs-add/actions)
|
|
9
|
+
[](https://github.com/fsyyft-ts/npmjs-add/actions)
|
|
10
|
+
[](https://www.typescriptlang.org/)
|
|
11
|
+
[](https://www.npmjs.com/package/@fsyyft/npmjs-add)
|
|
12
|
+
[](https://bundlephobia.com/package/@fsyyft/npmjs-add)
|
|
13
|
+
|
|
14
|
+
## 特性
|
|
15
|
+
|
|
16
|
+
- 📦 零依赖
|
|
17
|
+
- 🎯 支持 TypeScript
|
|
18
|
+
- 🔄 兼容 ESM 和 CommonJS
|
|
19
|
+
- 🚀 包含 CLI 工具
|
|
20
|
+
- ✅ 完整的测试覆盖
|
|
21
|
+
|
|
22
|
+
## 安装
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @fsyyft/npmjs-add
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 使用方法
|
|
29
|
+
|
|
30
|
+
### 作为库使用
|
|
31
|
+
|
|
32
|
+
**CommonJS:**
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const { add } = require('@fsyyft/npmjs-add');
|
|
36
|
+
|
|
37
|
+
console.log(add(1, 2)); // 3
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**ESM:**
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
import { add } from '@fsyyft/npmjs-add';
|
|
44
|
+
|
|
45
|
+
console.log(add(10, 20)); // 30
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**TypeScript:**
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { add } from '@fsyyft/npmjs-add';
|
|
52
|
+
|
|
53
|
+
const result: number = add(100, 200);
|
|
54
|
+
console.log(result); // 300
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 作为 CLI 工具
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# 全局安装
|
|
61
|
+
npm install -g @fsyyft/npmjs-add
|
|
62
|
+
|
|
63
|
+
# 或使用 npx(无需安装)
|
|
64
|
+
npx npmjs-add 1 2
|
|
65
|
+
# 输出: 3
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## API
|
|
69
|
+
|
|
70
|
+
### `add(a, b)`
|
|
71
|
+
|
|
72
|
+
计算两个数的和。
|
|
73
|
+
|
|
74
|
+
**参数:**
|
|
75
|
+
|
|
76
|
+
| 名称 | 类型 | 描述 |
|
|
77
|
+
|------|------|-------------|
|
|
78
|
+
| `a` | `number` | 第一个数 |
|
|
79
|
+
| `b` | `number` | 第二个数 |
|
|
80
|
+
|
|
81
|
+
**返回值:** `number` - a 和 b 的和
|
|
82
|
+
|
|
83
|
+
**示例:**
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
add(1, 2); // 3
|
|
87
|
+
add(-1, 5); // 4
|
|
88
|
+
add(0.1, 0.2); // 0.30000000000000004
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## CLI 使用
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npmjs-add <数字1> <数字2>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**示例:**
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npmjs-add 1 2 # 3
|
|
101
|
+
npmjs-add 100 200 # 300
|
|
102
|
+
npmjs-add -5 3 # -2
|
|
103
|
+
npmjs-add 1.5 2.5 # 4
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 文档
|
|
107
|
+
|
|
108
|
+
更多文档请查看 [docs](./docs) 目录:
|
|
109
|
+
|
|
110
|
+
- [项目结构](./docs/project-structure.md) - 项目结构和文件说明
|
|
111
|
+
- [本地开发指南](./docs/local-development-guide.md) - 如何本地开发和测试
|
|
112
|
+
- [发布指南](./docs/publishing-guide.md) - 如何发布到 npm
|
|
113
|
+
|
|
114
|
+
## 开发
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# 克隆仓库
|
|
118
|
+
git clone https://github.com/fsyyft-ts/npmjs-add.git
|
|
119
|
+
|
|
120
|
+
# 安装依赖
|
|
121
|
+
npm install
|
|
122
|
+
|
|
123
|
+
# 开发模式运行
|
|
124
|
+
npm run dev
|
|
125
|
+
|
|
126
|
+
# 运行测试
|
|
127
|
+
npm test
|
|
128
|
+
|
|
129
|
+
# 运行代码检查
|
|
130
|
+
npm run lint
|
|
131
|
+
|
|
132
|
+
# 构建项目
|
|
133
|
+
npm run build
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 发布
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# 测试发布脚本(不实际发布)
|
|
140
|
+
npm run test:publish
|
|
141
|
+
|
|
142
|
+
# 发布到 npm
|
|
143
|
+
npm run publish:npm
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
详细说明请查看 [发布指南](./docs/publishing-guide.md)。
|
|
147
|
+
|
|
148
|
+
## 许可证
|
|
149
|
+
|
|
150
|
+
ISC
|
|
151
|
+
|
|
152
|
+
## 作者
|
|
153
|
+
|
|
154
|
+
fsyyft
|
|
155
|
+
|
|
156
|
+
## 链接
|
|
157
|
+
|
|
158
|
+
- [npm 包](https://www.npmjs.com/package/@fsyyft/npmjs-add)
|
|
159
|
+
- [GitHub 仓库](https://github.com/fsyyft-ts/npmjs-add)
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/cli.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/cli.ts"],"sourcesContent":["/**\n * 加法工具库。\n *\n * @description\n * 提供数字加法运算功能,支持整数、负数和小数运算。\n *\n * @example\n * ```typescript\n * import { add } from '@fsyyft/npmjs-add';\n * const result = add(1, 2); // 3\n * ```\n */\n\n/**\n * 计算两个数的和。\n *\n * @description\n * 接收两个数字参数,返回它们的和。支持正数、负数和小数运算。\n *\n * @param a - 第一个加数\n * @param b - 第二个加数\n * @returns 两个数的和\n *\n * @example\n * ```typescript\n * add(1, 2); // 3\n * add(-1, 5); // 4\n * add(0.1, 0.2); // 0.30000000000000004\n * ```\n */\nexport function add(a: number, b: number): number {\n return a + b;\n}\n","#!/usr/bin/env node\n/**\n * CLI 入口文件。\n *\n * @description\n * npmjs-add 命令行工具的入口文件,负责解析命令行参数、\n * 验证输入、调用加法函数并输出结果。\n *\n * @remarks\n * - 解析命令行参数,要求两个数字输入;\n * - 验证参数数量和有效性;\n * - 调用 add 函数执行加法运算;\n * - 错误时输出使用说明并退出。\n *\n * @example\n * ```bash\n * npmjs-add 1 2 # 输出: 3\n * npmjs-add 100 200 # 输出: 300\n * npmjs-add -5 3 # 输出: -2\n * ```\n */\nimport { add } from \"./index\";\n\n// 从命令行参数中获取用户输入,跳过前两个系统参数\nconst args = process.argv.slice(2);\n\n// 参数验证:确保提供了两个数字\nif (args.length < 2) {\n console.error(\"Usage: npmjs-add <number1> <number2>\");\n process.exit(1);\n}\n\n// 将参数转换为数字\nconst a = Number(args[0]);\nconst b = Number(args[1]);\n\n// 验证参数是否为有效数字\nif (isNaN(a) || isNaN(b)) {\n console.error(\"Error: Both arguments must be valid numbers\");\n process.exit(1);\n}\n\n// 执行加法运算并输出结果\nconsole.log(add(a, b));\n"],"mappings":";;;;AA8BO,SAAS,IAAIA,IAAWC,IAAmB;AAChD,SAAOD,KAAIC;AACb;;;ACRA,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAGjC,IAAI,KAAK,SAAS,GAAG;AACnB,UAAQ,MAAM,sCAAsC;AACpD,UAAQ,KAAK,CAAC;AAChB;AAGA,IAAM,IAAI,OAAO,KAAK,CAAC,CAAC;AACxB,IAAM,IAAI,OAAO,KAAK,CAAC,CAAC;AAGxB,IAAI,MAAM,CAAC,KAAK,MAAM,CAAC,GAAG;AACxB,UAAQ,MAAM,6CAA6C;AAC3D,UAAQ,KAAK,CAAC;AAChB;AAGA,QAAQ,IAAI,IAAI,GAAG,CAAC,CAAC;","names":["a","b"]}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/cli.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/cli.ts"],"sourcesContent":["/**\n * 加法工具库。\n *\n * @description\n * 提供数字加法运算功能,支持整数、负数和小数运算。\n *\n * @example\n * ```typescript\n * import { add } from '@fsyyft/npmjs-add';\n * const result = add(1, 2); // 3\n * ```\n */\n\n/**\n * 计算两个数的和。\n *\n * @description\n * 接收两个数字参数,返回它们的和。支持正数、负数和小数运算。\n *\n * @param a - 第一个加数\n * @param b - 第二个加数\n * @returns 两个数的和\n *\n * @example\n * ```typescript\n * add(1, 2); // 3\n * add(-1, 5); // 4\n * add(0.1, 0.2); // 0.30000000000000004\n * ```\n */\nexport function add(a: number, b: number): number {\n return a + b;\n}\n","#!/usr/bin/env node\n/**\n * CLI 入口文件。\n *\n * @description\n * npmjs-add 命令行工具的入口文件,负责解析命令行参数、\n * 验证输入、调用加法函数并输出结果。\n *\n * @remarks\n * - 解析命令行参数,要求两个数字输入;\n * - 验证参数数量和有效性;\n * - 调用 add 函数执行加法运算;\n * - 错误时输出使用说明并退出。\n *\n * @example\n * ```bash\n * npmjs-add 1 2 # 输出: 3\n * npmjs-add 100 200 # 输出: 300\n * npmjs-add -5 3 # 输出: -2\n * ```\n */\nimport { add } from \"./index\";\n\n// 从命令行参数中获取用户输入,跳过前两个系统参数\nconst args = process.argv.slice(2);\n\n// 参数验证:确保提供了两个数字\nif (args.length < 2) {\n console.error(\"Usage: npmjs-add <number1> <number2>\");\n process.exit(1);\n}\n\n// 将参数转换为数字\nconst a = Number(args[0]);\nconst b = Number(args[1]);\n\n// 验证参数是否为有效数字\nif (isNaN(a) || isNaN(b)) {\n console.error(\"Error: Both arguments must be valid numbers\");\n process.exit(1);\n}\n\n// 执行加法运算并输出结果\nconsole.log(add(a, b));\n"],"mappings":";;;AA8BO,SAAS,IAAIA,IAAWC,IAAmB;AAChD,SAAOD,KAAIC;AACb;;;ACRA,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAGjC,IAAI,KAAK,SAAS,GAAG;AACnB,UAAQ,MAAM,sCAAsC;AACpD,UAAQ,KAAK,CAAC;AAChB;AAGA,IAAM,IAAI,OAAO,KAAK,CAAC,CAAC;AACxB,IAAM,IAAI,OAAO,KAAK,CAAC,CAAC;AAGxB,IAAI,MAAM,CAAC,KAAK,MAAM,CAAC,GAAG;AACxB,UAAQ,MAAM,6CAA6C;AAC3D,UAAQ,KAAK,CAAC;AAChB;AAGA,QAAQ,IAAI,IAAI,GAAG,CAAC,CAAC;","names":["a","b"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * 加法工具库。\n *\n * @description\n * 提供数字加法运算功能,支持整数、负数和小数运算。\n *\n * @example\n * ```typescript\n * import { add } from '@fsyyft/npmjs-add';\n * const result = add(1, 2); // 3\n * ```\n */\n\n/**\n * 计算两个数的和。\n *\n * @description\n * 接收两个数字参数,返回它们的和。支持正数、负数和小数运算。\n *\n * @param a - 第一个加数\n * @param b - 第二个加数\n * @returns 两个数的和\n *\n * @example\n * ```typescript\n * add(1, 2); // 3\n * add(-1, 5); // 4\n * add(0.1, 0.2); // 0.30000000000000004\n * ```\n */\nexport function add(a: number, b: number): number {\n return a + b;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,SAAS,IAAI,GAAW,GAAmB;AAChD,SAAO,IAAI;AACb;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
*
|
|
2
|
+
* 加法工具库。
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* 提供数字加法运算功能,支持整数、负数和小数运算。
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { add } from '@fsyyft/npmjs-add';
|
|
10
|
+
* const result = add(1, 2); // 3
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* 计算两个数的和。
|
|
15
|
+
*
|
|
16
|
+
* @description
|
|
17
|
+
* 接收两个数字参数,返回它们的和。支持正数、负数和小数运算。
|
|
18
|
+
*
|
|
19
|
+
* @param a - 第一个加数
|
|
20
|
+
* @param b - 第二个加数
|
|
21
|
+
* @returns 两个数的和
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* add(1, 2); // 3
|
|
26
|
+
* add(-1, 5); // 4
|
|
27
|
+
* add(0.1, 0.2); // 0.30000000000000004
|
|
28
|
+
* ```
|
|
6
29
|
*/
|
|
7
30
|
declare function add(a: number, b: number): number;
|
|
8
31
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
*
|
|
2
|
+
* 加法工具库。
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* 提供数字加法运算功能,支持整数、负数和小数运算。
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { add } from '@fsyyft/npmjs-add';
|
|
10
|
+
* const result = add(1, 2); // 3
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* 计算两个数的和。
|
|
15
|
+
*
|
|
16
|
+
* @description
|
|
17
|
+
* 接收两个数字参数,返回它们的和。支持正数、负数和小数运算。
|
|
18
|
+
*
|
|
19
|
+
* @param a - 第一个加数
|
|
20
|
+
* @param b - 第二个加数
|
|
21
|
+
* @returns 两个数的和
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* add(1, 2); // 3
|
|
26
|
+
* add(-1, 5); // 4
|
|
27
|
+
* add(0.1, 0.2); // 0.30000000000000004
|
|
28
|
+
* ```
|
|
6
29
|
*/
|
|
7
30
|
declare function add(a: number, b: number): number;
|
|
8
31
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * 加法工具库。\n *\n * @description\n * 提供数字加法运算功能,支持整数、负数和小数运算。\n *\n * @example\n * ```typescript\n * import { add } from '@fsyyft/npmjs-add';\n * const result = add(1, 2); // 3\n * ```\n */\n\n/**\n * 计算两个数的和。\n *\n * @description\n * 接收两个数字参数,返回它们的和。支持正数、负数和小数运算。\n *\n * @param a - 第一个加数\n * @param b - 第二个加数\n * @returns 两个数的和\n *\n * @example\n * ```typescript\n * add(1, 2); // 3\n * add(-1, 5); // 4\n * add(0.1, 0.2); // 0.30000000000000004\n * ```\n */\nexport function add(a: number, b: number): number {\n return a + b;\n}\n"],"mappings":";AA8BO,SAAS,IAAI,GAAW,GAAmB;AAChD,SAAO,IAAI;AACb;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fsyyft/npmjs-add",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "一个关于加法运算的 npm 管理的项目示例",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"lint:fix": "eslint src --fix",
|
|
21
21
|
"test": "vitest",
|
|
22
22
|
"test:run": "vitest run",
|
|
23
|
+
"test:publish": "bash scripts/test-publish.sh",
|
|
23
24
|
"publish:npm": "bash scripts/publish.sh"
|
|
24
25
|
},
|
|
25
26
|
"repository": {
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"url": "git+https://github.com/fsyyft-ts/npmjs-add.git"
|
|
28
29
|
},
|
|
29
30
|
"keywords": [],
|
|
30
|
-
"author": "",
|
|
31
|
+
"author": "fsyyft-ts",
|
|
31
32
|
"license": "ISC",
|
|
32
33
|
"bin": {
|
|
33
34
|
"npmjs-add": "./dist/cli.js"
|