mm_maths 1.1.9 → 1.2.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 +140 -0
- package/package.json +6 -6
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# mm_maths
|
|
2
|
+
|
|
3
|
+
这是一个可以将数学公式推导变形,并转成js和计算的模块。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install mm_maths
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 基本使用
|
|
12
|
+
|
|
13
|
+
### 1. 初始化模块
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const Maths = require('mm_maths');
|
|
17
|
+
|
|
18
|
+
// 创建实例并指定模块路径
|
|
19
|
+
const maths = new Maths(__dirname);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. 载入公式
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
// 载入基础数学公式
|
|
26
|
+
maths.update(__dirname, "base");
|
|
27
|
+
|
|
28
|
+
// 也可以分别载入不同类型的公式
|
|
29
|
+
maths.load_identities(__dirname, "base"); // 载入恒等式
|
|
30
|
+
maths.load_convert(__dirname, "base"); // 载入转换函数
|
|
31
|
+
maths.load_symbol(__dirname, "base"); // 载入符号处理函数
|
|
32
|
+
maths.load_math(__dirname, "base"); // 载入计算函数
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. 设置常量和变量
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
// 设置常量
|
|
39
|
+
const consts = {
|
|
40
|
+
a: 10,
|
|
41
|
+
b: 3
|
|
42
|
+
};
|
|
43
|
+
maths.set_const(consts);
|
|
44
|
+
|
|
45
|
+
// 设置变量
|
|
46
|
+
const vars = {
|
|
47
|
+
ma5: "MA(CLOSE, 5)", // 可以设置公式作为变量
|
|
48
|
+
price: null
|
|
49
|
+
};
|
|
50
|
+
maths.set_var(vars);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 4. 公式转换和计算
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// 转换公式
|
|
57
|
+
const expression = "y = abc * ab * 3c * 2";
|
|
58
|
+
const express = maths.convertTo(expression);
|
|
59
|
+
console.log('转换后的公式:', express);
|
|
60
|
+
|
|
61
|
+
// 运行代码
|
|
62
|
+
const result = maths.run_code("return " + express);
|
|
63
|
+
console.log('计算结果:', result);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API 说明
|
|
67
|
+
|
|
68
|
+
### 主要类
|
|
69
|
+
|
|
70
|
+
#### Maths
|
|
71
|
+
|
|
72
|
+
数学公式计算的主类,提供公式转换、计算等功能。
|
|
73
|
+
|
|
74
|
+
**构造函数参数:**
|
|
75
|
+
- `dir` {String} 模块路径,默认为 __dirname
|
|
76
|
+
|
|
77
|
+
### 主要方法
|
|
78
|
+
|
|
79
|
+
#### update(path, type)
|
|
80
|
+
|
|
81
|
+
更新并载入指定类型的所有公式。
|
|
82
|
+
|
|
83
|
+
- `path` {String} 检索路径
|
|
84
|
+
- `type` {String} 公式类型,如 "base"(基础数学)、"stock"(股票)
|
|
85
|
+
|
|
86
|
+
#### set_const(constant)
|
|
87
|
+
|
|
88
|
+
设置常量。
|
|
89
|
+
|
|
90
|
+
- `constant` {Object} 常量集合,如 `{ a: 10, b: 15 }`
|
|
91
|
+
|
|
92
|
+
#### set_var(vars)
|
|
93
|
+
|
|
94
|
+
设置变量。
|
|
95
|
+
|
|
96
|
+
- `vars` {Object} 变量集合,如 `{ ma5: "MA(CLOSE, 5)", price: null }`
|
|
97
|
+
|
|
98
|
+
#### convertTo(express)
|
|
99
|
+
|
|
100
|
+
转换公式。
|
|
101
|
+
|
|
102
|
+
- `express` {String} 要转换的表达式
|
|
103
|
+
- 返回 {String} 转换后的表达式
|
|
104
|
+
|
|
105
|
+
#### run_code(express)
|
|
106
|
+
|
|
107
|
+
运行代码。
|
|
108
|
+
|
|
109
|
+
- `express` {String} 要执行的表达式
|
|
110
|
+
- 返回 {Object} 执行结果
|
|
111
|
+
|
|
112
|
+
## 支持的公式类型
|
|
113
|
+
|
|
114
|
+
- 基础数学 (base)
|
|
115
|
+
- 四则运算
|
|
116
|
+
- 指数运算
|
|
117
|
+
- 对数运算
|
|
118
|
+
- 三角函数
|
|
119
|
+
|
|
120
|
+
- 数组运算 (array)
|
|
121
|
+
- 求和
|
|
122
|
+
- 平均值
|
|
123
|
+
- 最大/最小值
|
|
124
|
+
- 中位数
|
|
125
|
+
|
|
126
|
+
- 股票技术指标 (stock)
|
|
127
|
+
- MA (移动平均线)
|
|
128
|
+
- MACD
|
|
129
|
+
- RSI
|
|
130
|
+
- BBANDS (布林带)
|
|
131
|
+
|
|
132
|
+
## 注意事项
|
|
133
|
+
|
|
134
|
+
1. 在使用前请确保已正确载入所需的公式类型
|
|
135
|
+
2. 设置常量和变量时注意避免名称冲突
|
|
136
|
+
3. 公式转换时注意检查语法正确性
|
|
137
|
+
|
|
138
|
+
## 许可证
|
|
139
|
+
|
|
140
|
+
ISC License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_maths",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "这是一个可以将数学公式推导变形,并转成js和计算的模块。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://gitee.com/qiuwenwu91/mm_maths.git"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"math",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"author": "邱文武",
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"bugs": {
|
|
27
|
-
"url": "https://
|
|
27
|
+
"url": "https://gitee.com/qiuwenwu91/mm_maths/issues"
|
|
28
28
|
},
|
|
29
|
-
"homepage": "https://
|
|
29
|
+
"homepage": "https://gitee.com/qiuwenwu91/mm_maths#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"mm_expand": "^1.
|
|
31
|
+
"mm_expand": "^1.8.3"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|