a-calc 0.0.78 → 0.0.79
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 +63 -49
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -157,59 +157,73 @@ calc("111111 + 11111 | ,",{_fmt: "=2"}) // 122,222.00 很显然 , 和 =2 被组
|
|
|
157
157
|
> 在项目中编写庞大的第二个参数是不好的, 所以第二个参数你应该想办法固定他, 下面只是一个在VUE项目中的演示
|
|
158
158
|
|
|
159
159
|
```js
|
|
160
|
-
import { calc, fmt } from
|
|
161
|
-
|
|
162
|
-
Vue.mixin({
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
160
|
+
import { calc, fmt } from "a-calc";
|
|
161
|
+
|
|
162
|
+
Vue.mixin( {
|
|
163
|
+
methods: {
|
|
164
|
+
calc ( expr, obj )
|
|
165
|
+
{
|
|
166
|
+
let dataArr = [this];
|
|
167
|
+
let _fmt = undefined;
|
|
168
|
+
let _error = undefined;
|
|
169
|
+
|
|
170
|
+
if ( obj !== undefined )
|
|
171
|
+
{
|
|
172
|
+
dataArr.unshift( obj );
|
|
173
|
+
if ( obj._fmt !== undefined )
|
|
174
|
+
{
|
|
175
|
+
_fmt = obj._fmt;
|
|
176
|
+
}
|
|
177
|
+
if ( obj._error !== undefined )
|
|
178
|
+
{
|
|
179
|
+
_error = obj._error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return calc( expr, {
|
|
184
|
+
_fillData: dataArr,
|
|
185
|
+
_error: _error === undefined ? "-" : _error,
|
|
186
|
+
_fmt, // 格式化参数在没有字符串格式化的时候才有用
|
|
187
|
+
} );
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
fmt ( expr, obj )
|
|
191
|
+
{
|
|
192
|
+
// 专门格式化的
|
|
193
|
+
let dataArr = [this];
|
|
194
|
+
let _fmt = undefined;
|
|
195
|
+
let _error = undefined;
|
|
196
|
+
|
|
197
|
+
if ( obj !== undefined )
|
|
198
|
+
{
|
|
199
|
+
dataArr.unshift( obj );
|
|
200
|
+
if ( obj._fmt !== undefined )
|
|
201
|
+
{
|
|
202
|
+
_fmt = obj._fmt;
|
|
203
|
+
}
|
|
204
|
+
if ( obj._error !== undefined )
|
|
205
|
+
{
|
|
206
|
+
_error = obj._error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return fmt( expr,
|
|
211
|
+
{
|
|
212
|
+
_fillData: dataArr,
|
|
213
|
+
_error: _error === undefined ? "-" : _error,
|
|
214
|
+
_fmt,
|
|
215
|
+
_unit: true
|
|
216
|
+
} );
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
} );
|
|
208
220
|
```
|
|
209
221
|
|
|
210
222
|
## 版本变更
|
|
211
223
|
|
|
212
|
-
* 0.0.
|
|
224
|
+
* 0.0.79
|
|
225
|
+
* 更新文档
|
|
226
|
+
* 0.0.78
|
|
213
227
|
* 支持科学计数法的计算
|
|
214
228
|
* 完整的单元测试
|
|
215
229
|
* 更多边界情况的检测
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "a-calc",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "JavaScript
|
|
3
|
+
"version": "0.0.79",
|
|
4
|
+
"description": "JavaScript的精准四则运算库,支持格式化操作例如: 千分位格式化, 灵活指定小数点位数",
|
|
5
5
|
"main": "./cjs/index.cjs",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"dev": "rollup -c --environment build:dev",
|
|
25
25
|
"dev:w": "rollup -c -w --environment build:dev",
|
|
26
|
-
"build": "rollup -c --environment build:build",
|
|
26
|
+
"build": "rollup -c --environment build:build & yarn test",
|
|
27
27
|
"build:w": "rollup -c -w --environment build:build",
|
|
28
28
|
"test": "cross-env ava --verbose --tap test/*.mjs"
|
|
29
29
|
},
|