@202195808yy/simple-math-utils
v1.0.2
Published
Простая библиотека математических функций для демонстрации публикации npm пакета
Readme
markdown
# @202195808yy/simple-math-utils
用于演示 npm 包发布的简单数学函数库。
## 安装
```bash
npm install @202195808yy/simple-math-utils快速开始
javascript
import { add, subtract, square } from '@202195808yy/simple-math-utils';
console.log(add(2, 3)); // 5
console.log(subtract(5, 2)); // 3
console.log(square(4)); // 16API
add(a, b)
两数相加。
a{number} 第一个加数b{number} 第二个加数- 返回 {number} 两数之和
subtract(a, b)
两数相减。
a{number} 被减数b{number} 减数- 返回 {number} 差
square(x)
计算一个数的平方。
x{number}- 返回 {number} 平方值
示例
javascript
import { square } from '@202195808yy/simple-math-utils';
const nums = [1, 2, 3, 4];
const squares = nums.map(square);
console.log(squares); // [1, 4, 9, 16]常见问题
运行示例代码时出现 MODULE_TYPELESS_PACKAGE_JSON 警告
如果你在使用 import 导入本包时看到类似以下警告:
text
Warning: Module type of file ... is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected.这是因为你的项目 package.json 中没有声明模块类型。解决方法很简单:
在你的项目根目录的 package.json 中添加:
json
"type": "module"添加后,Node.js 就能正确识别 ES 模块语法,警告就会消失,性能也会更好。
如果你的项目无法使用 "type": "module"(例如因为部分旧代码仍用 require),可以改用该文件扩展名 .mjs,然后用 node index.mjs 运行。
许可证
ISC
作者:Янь Яо
text
