@pie-lib/math-evaluator 2.1.4 → 2.1.7

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/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [2.1.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.3...@pie-lib/math-evaluator@2.1.4) (2021-02-15)
6
+ ## [2.1.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.6...@pie-lib/math-evaluator@2.1.7) (2022-11-23)
7
7
 
8
8
  **Note:** Version bump only for package @pie-lib/math-evaluator
9
9
 
@@ -11,318 +11,179 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
- ## [2.1.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.1...@pie-lib/math-evaluator@2.1.3) (2021-02-15)
14
+ ## [2.1.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.4...@pie-lib/math-evaluator@2.1.6) (2021-06-25)
15
15
 
16
16
  **Note:** Version bump only for package @pie-lib/math-evaluator
17
17
 
18
+ ## [2.1.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.3...@pie-lib/math-evaluator@2.1.4) (2021-02-15)
18
19
 
20
+ **Note:** Version bump only for package @pie-lib/math-evaluator
19
21
 
22
+ ## [2.1.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.1...@pie-lib/math-evaluator@2.1.3) (2021-02-15)
20
23
 
24
+ **Note:** Version bump only for package @pie-lib/math-evaluator
21
25
 
22
26
  ## [2.1.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.0...@pie-lib/math-evaluator@2.1.1) (2020-08-11)
23
27
 
24
28
  **Note:** Version bump only for package @pie-lib/math-evaluator
25
29
 
26
-
27
-
28
-
29
-
30
30
  # [2.1.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.0.0...@pie-lib/math-evaluator@2.1.0) (2020-06-05)
31
31
 
32
-
33
32
  ### Features
34
33
 
35
- * bump mathjs@^7.0.1 ([865de4b](https://github.com/pie-framework/pie-lib/commit/865de4b))
36
-
37
-
38
-
39
-
34
+ - bump mathjs@^7.0.1 ([865de4b](https://github.com/pie-framework/pie-lib/commit/865de4b))
40
35
 
41
36
  # [2.0.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.22...@pie-lib/math-evaluator@2.0.0) (2020-04-27)
42
37
 
43
-
44
38
  ### Features
45
39
 
46
- * major version bump ([78da9d5](https://github.com/pie-framework/pie-lib/commit/78da9d5))
47
-
40
+ - major version bump ([78da9d5](https://github.com/pie-framework/pie-lib/commit/78da9d5))
48
41
 
49
42
  ### BREAKING CHANGES
50
43
 
51
- * The last release should have been breaking - this
52
- should trigger a major bump now
53
-
54
-
55
-
56
-
44
+ - The last release should have been breaking - this
45
+ should trigger a major bump now
57
46
 
58
47
  ## [0.6.22](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.21...@pie-lib/math-evaluator@0.6.22) (2020-04-27)
59
48
 
60
49
  **Note:** Version bump only for package @pie-lib/math-evaluator
61
50
 
62
-
63
-
64
-
65
-
66
51
  ## [0.6.21](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.20...@pie-lib/math-evaluator@0.6.21) (2020-04-15)
67
52
 
68
-
69
53
  ### Bug Fixes
70
54
 
71
- * **math-evaluator:** support `x^(1/y) == sqrt(x,y)` PD-3 ([fa148ff](https://github.com/pie-framework/pie-lib/commit/fa148ff))
72
-
73
-
74
-
75
-
55
+ - **math-evaluator:** support `x^(1/y) == sqrt(x,y)` PD-3 ([fa148ff](https://github.com/pie-framework/pie-lib/commit/fa148ff))
76
56
 
77
57
  ## [0.6.20](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.19...@pie-lib/math-evaluator@0.6.20) (2020-04-14)
78
58
 
79
59
  **Note:** Version bump only for package @pie-lib/math-evaluator
80
60
 
81
-
82
-
83
-
84
-
85
61
  ## [0.6.19](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.18...@pie-lib/math-evaluator@0.6.19) (2020-04-08)
86
62
 
87
63
  **Note:** Version bump only for package @pie-lib/math-evaluator
88
64
 
89
-
90
-
91
-
92
-
93
65
  ## [0.6.18](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.17...@pie-lib/math-evaluator@0.6.18) (2020-03-31)
94
66
 
95
67
  **Note:** Version bump only for package @pie-lib/math-evaluator
96
68
 
97
-
98
-
99
-
100
-
101
69
  ## [0.6.17](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.16...@pie-lib/math-evaluator@0.6.17) (2020-03-31)
102
70
 
103
71
  **Note:** Version bump only for package @pie-lib/math-evaluator
104
72
 
105
-
106
-
107
-
108
-
109
73
  ## [0.6.16](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.15...@pie-lib/math-evaluator@0.6.16) (2020-03-31)
110
74
 
111
75
  **Note:** Version bump only for package @pie-lib/math-evaluator
112
76
 
113
-
114
-
115
-
116
-
117
77
  ## [0.6.15](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.14...@pie-lib/math-evaluator@0.6.15) (2020-03-30)
118
78
 
119
79
  **Note:** Version bump only for package @pie-lib/math-evaluator
120
80
 
121
-
122
-
123
-
124
-
125
81
  ## [0.6.14](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.13...@pie-lib/math-evaluator@0.6.14) (2020-03-30)
126
82
 
127
83
  **Note:** Version bump only for package @pie-lib/math-evaluator
128
84
 
129
-
130
-
131
-
132
-
133
85
  ## [0.6.13](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.12...@pie-lib/math-evaluator@0.6.13) (2020-03-30)
134
86
 
135
87
  **Note:** Version bump only for package @pie-lib/math-evaluator
136
88
 
137
-
138
-
139
-
140
-
141
89
  ## [0.6.12](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.11...@pie-lib/math-evaluator@0.6.12) (2020-03-30)
142
90
 
143
91
  **Note:** Version bump only for package @pie-lib/math-evaluator
144
92
 
145
-
146
-
147
-
148
-
149
93
  ## [0.6.11](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.10...@pie-lib/math-evaluator@0.6.11) (2020-03-30)
150
94
 
151
95
  **Note:** Version bump only for package @pie-lib/math-evaluator
152
96
 
153
-
154
-
155
-
156
-
157
97
  ## [0.6.10](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.9...@pie-lib/math-evaluator@0.6.10) (2020-03-30)
158
98
 
159
99
  **Note:** Version bump only for package @pie-lib/math-evaluator
160
100
 
161
-
162
-
163
-
164
-
165
101
  ## [0.6.9](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.8...@pie-lib/math-evaluator@0.6.9) (2020-03-30)
166
102
 
167
-
168
103
  ### Bug Fixes
169
104
 
170
- * add module prop to package.json ([f0d7718](https://github.com/pie-framework/pie-lib/commit/f0d7718))
171
-
172
-
173
-
174
-
105
+ - add module prop to package.json ([f0d7718](https://github.com/pie-framework/pie-lib/commit/f0d7718))
175
106
 
176
107
  ## [0.6.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.7...@pie-lib/math-evaluator@0.6.8) (2020-02-05)
177
108
 
178
109
  **Note:** Version bump only for package @pie-lib/math-evaluator
179
110
 
180
-
181
-
182
-
183
-
184
111
  ## [0.6.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.6...@pie-lib/math-evaluator@0.6.7) (2020-01-28)
185
112
 
186
-
187
113
  ### Bug Fixes
188
114
 
189
- * throw error if number missing factor ([3b23b28](https://github.com/pie-framework/pie-lib/commit/3b23b28))
190
-
191
-
192
-
193
-
115
+ - throw error if number missing factor ([3b23b28](https://github.com/pie-framework/pie-lib/commit/3b23b28))
194
116
 
195
117
  ## [0.6.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.5...@pie-lib/math-evaluator@0.6.6) (2020-01-27)
196
118
 
197
-
198
119
  ### Bug Fixes
199
120
 
200
- * bump @pie-framework/math-expressions@2.2.0 [ch7119] ([b7fa810](https://github.com/pie-framework/pie-lib/commit/b7fa810))
201
-
202
-
203
-
204
-
121
+ - bump @pie-framework/math-expressions@2.2.0 [ch7119](<[b7fa810](https://github.com/pie-framework/pie-lib/commit/b7fa810)>)
205
122
 
206
123
  ## [0.6.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.4...@pie-lib/math-evaluator@0.6.5) (2019-12-20)
207
124
 
208
-
209
125
  ### Bug Fixes
210
126
 
211
- * bump @pie-framework/math-expressions@^2.1.0 ch6456 ([d57971f](https://github.com/pie-framework/pie-lib/commit/d57971f))
212
-
213
-
214
-
215
-
127
+ - bump @pie-framework/math-expressions@^2.1.0 ch6456 ([d57971f](https://github.com/pie-framework/pie-lib/commit/d57971f))
216
128
 
217
129
  ## [0.6.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.3...@pie-lib/math-evaluator@0.6.4) (2019-12-10)
218
130
 
219
131
  **Note:** Version bump only for package @pie-lib/math-evaluator
220
132
 
221
-
222
-
223
-
224
-
225
133
  ## [0.6.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.2...@pie-lib/math-evaluator@0.6.3) (2019-12-10)
226
134
 
227
135
  **Note:** Version bump only for package @pie-lib/math-evaluator
228
136
 
229
-
230
-
231
-
232
-
233
137
  ## [0.6.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.1...@pie-lib/math-evaluator@0.6.2) (2019-12-03)
234
138
 
235
139
  **Note:** Version bump only for package @pie-lib/math-evaluator
236
140
 
237
-
238
-
239
-
240
-
241
141
  ## [0.6.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.6.0...@pie-lib/math-evaluator@0.6.1) (2019-11-28)
242
142
 
243
143
  **Note:** Version bump only for package @pie-lib/math-evaluator
244
144
 
245
-
246
-
247
-
248
-
249
145
  # [0.6.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.5.7...@pie-lib/math-evaluator@0.6.0) (2019-11-27)
250
146
 
251
-
252
147
  ### Bug Fixes
253
148
 
254
- * **math-evaluator:** finalize fix for PIE-188 ([d7bd4a1](https://github.com/pie-framework/pie-lib/commit/d7bd4a1))
255
- * **math-evaluator:** finalize fix for PIE-188, custom and unrecognized latex commands ([b37184d](https://github.com/pie-framework/pie-lib/commit/b37184d))
256
- * **math-evaluator:** PIE-188 related fixes and tests ([76424c6](https://github.com/pie-framework/pie-lib/commit/76424c6))
257
-
149
+ - **math-evaluator:** finalize fix for PIE-188 ([d7bd4a1](https://github.com/pie-framework/pie-lib/commit/d7bd4a1))
150
+ - **math-evaluator:** finalize fix for PIE-188, custom and unrecognized latex commands ([b37184d](https://github.com/pie-framework/pie-lib/commit/b37184d))
151
+ - **math-evaluator:** PIE-188 related fixes and tests ([76424c6](https://github.com/pie-framework/pie-lib/commit/76424c6))
258
152
 
259
153
  ### Features
260
154
 
261
- * **math-evaluator:** change math-expressions to pie fork ([06e8b61](https://github.com/pie-framework/pie-lib/commit/06e8b61))
262
-
263
-
264
-
265
-
155
+ - **math-evaluator:** change math-expressions to pie fork ([06e8b61](https://github.com/pie-framework/pie-lib/commit/06e8b61))
266
156
 
267
157
  ## [0.5.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.5.6...@pie-lib/math-evaluator@0.5.7) (2019-08-21)
268
158
 
269
159
  **Note:** Version bump only for package @pie-lib/math-evaluator
270
160
 
271
-
272
-
273
-
274
-
275
161
  ## [0.5.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.5.5...@pie-lib/math-evaluator@0.5.6) (2019-07-08)
276
162
 
277
163
  **Note:** Version bump only for package @pie-lib/math-evaluator
278
164
 
279
-
280
-
281
-
282
-
283
165
  ## [0.5.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.5.4...@pie-lib/math-evaluator@0.5.5) (2019-07-05)
284
166
 
285
167
  **Note:** Version bump only for package @pie-lib/math-evaluator
286
168
 
287
-
288
-
289
-
290
-
291
169
  ## [0.5.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.5.3...@pie-lib/math-evaluator@0.5.4) (2019-07-02)
292
170
 
293
-
294
171
  ### Bug Fixes
295
172
 
296
- * **math-evaluator:** fix equals sign treatment in expressions ([f81e924](https://github.com/pie-framework/pie-lib/commit/f81e924))
297
-
298
-
299
-
300
-
173
+ - **math-evaluator:** fix equals sign treatment in expressions ([f81e924](https://github.com/pie-framework/pie-lib/commit/f81e924))
301
174
 
302
175
  ## [0.5.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.5.2...@pie-lib/math-evaluator@0.5.3) (2019-06-17)
303
176
 
304
177
  **Note:** Version bump only for package @pie-lib/math-evaluator
305
178
 
306
-
307
-
308
-
309
-
310
179
  ## [0.5.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.5.1...@pie-lib/math-evaluator@0.5.2) (2019-06-12)
311
180
 
312
181
  **Note:** Version bump only for package @pie-lib/math-evaluator
313
182
 
314
-
315
-
316
-
317
-
318
183
  ## [0.5.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.5.0...@pie-lib/math-evaluator@0.5.1) (2019-06-05)
319
184
 
320
185
  **Note:** Version bump only for package @pie-lib/math-evaluator
321
186
 
322
-
323
-
324
-
325
-
326
187
  # [0.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@0.4.4...@pie-lib/math-evaluator@0.5.0) (2019-05-14)
327
188
 
328
189
  ### Features
package/lib/index.js CHANGED
@@ -1,23 +1,27 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
3
7
  Object.defineProperty(exports, "__esModule", {
4
8
  value: true
5
9
  });
6
- exports["default"] = exports.ave = exports.textToMathText = exports.latexToText = void 0;
10
+ exports.textToMathText = exports.latexToText = exports["default"] = exports.ave = void 0;
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
13
 
8
14
  var mathjs = _interopRequireWildcard(require("mathjs"));
9
15
 
10
16
  var _mathExpressions = _interopRequireDefault(require("@pie-framework/math-expressions"));
11
17
 
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
19
 
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
21
 
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
23
 
20
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
25
 
22
26
  var decimalCommaRegex = /,/g;
23
27
  var decimalRegex = /\.|,/g;
@@ -74,8 +78,8 @@ var astToTextOpts = {
74
78
 
75
79
  var latexToText = function latexToText(latex) {
76
80
  var extraOtps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
77
- var la = new _mathExpressions["default"].converters.latexToAstObj(_objectSpread({}, latexToAstOpts, {}, extraOtps));
78
- var at = new _mathExpressions["default"].converters.astToTextObj(_objectSpread({}, astToTextOpts, {}, extraOtps));
81
+ var la = new _mathExpressions["default"].converters.latexToAstObj(_objectSpread(_objectSpread({}, latexToAstOpts), extraOtps));
82
+ var at = new _mathExpressions["default"].converters.astToTextObj(_objectSpread(_objectSpread({}, astToTextOpts), extraOtps));
79
83
  var ast = la.convert(latex);
80
84
  return at.convert(ast);
81
85
  };
@@ -84,8 +88,8 @@ exports.latexToText = latexToText;
84
88
 
85
89
  var textToMathText = function textToMathText(latex) {
86
90
  var extraOtps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
87
- var la = new _mathExpressions["default"].converters.textToAstObj(_objectSpread({}, latexToAstOpts, {}, extraOtps));
88
- var at = new _mathExpressions["default"].converters.astToTextObj(_objectSpread({}, astToTextOpts, {}, extraOtps));
91
+ var la = new _mathExpressions["default"].converters.textToAstObj(_objectSpread(_objectSpread({}, latexToAstOpts), extraOtps));
92
+ var at = new _mathExpressions["default"].converters.astToTextObj(_objectSpread(_objectSpread({}, astToTextOpts), extraOtps));
89
93
  var ast = la.convert(latex);
90
94
  return at.convert(ast);
91
95
  };
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["decimalCommaRegex","decimalRegex","decimalWithThousandSeparatorNumberRegex","rationalizeAllPossibleSubNodes","expression","rationalize","mathjs","parse","tree","transformedTree","transform","node","rationalizedNode","prepareExpression","string","isLatex","returnValue","trim","replace","latexToText","textToMathText","unknownCommands","toString","latexToAstOpts","missingFactor","token","e","console","warn","token_type","unknownCommandBehavior","astToTextOpts","unicode_operators","ne","operands","join","latex","extraOtps","la","me","converters","latexToAstObj","at","astToTextObj","ast","convert","textToAstObj","shouldRationalizeEntireTree","shouldDoIt","traverse","type","fn","exponent","args","compile","eval","functionParameter","containsDecimal","match","SIMPLIFY_RULES","l","r","simplify","v","concat","rules","areValuesEqual","valueOne","valueTwo","options","allowDecimals","inverse","valueOneToUse","valueTwoToUse","test","preparedValueOne","preparedValueTwo","one","two","equals","ave","a","b","am","bm","arm","brm"],"mappings":";;;;;;;AACA;;AACA;;;;;;;;;;;;AAEA,IAAMA,iBAAiB,GAAG,IAA1B;AACA,IAAMC,YAAY,GAAG,OAArB;AACA,IAAMC,uCAAuC,GAAG,iEAAhD;;AAEA,IAAMC,8BAA8B,GAAG,SAAjCA,8BAAiC,CAAAC,UAAU;AAAA,SAAIC,WAAW,CAACC,MAAM,CAACC,KAAP,CAAaH,UAAb,CAAD,CAAf;AAAA,CAAjD;;AACA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAAAG,IAAI,EAAI;AAC1B,MAAMC,eAAe,GAAGD,IAAI,CAACE,SAAL,CAAe,UAAAC,IAAI,EAAI;AAC7C,QAAI;AACF,UAAMC,gBAAgB,GAAGN,MAAM,CAACD,WAAP,CAAmBM,IAAnB,CAAzB;AACA,aAAOC,gBAAP;AACD,KAHD,CAGE,gBAAM;AACN,aAAOD,IAAP;AACD;AACF,GAPuB,CAAxB;AAQA,SAAOF,eAAP;AACD,CAVD;;AAYA,SAASI,iBAAT,CAA2BC,MAA3B,EAAmCC,OAAnC,EAA4C;AAC1C,MAAIC,WAAW,GAAGF,MAAM,GAAGA,MAAM,CAACG,IAAP,EAAH,GAAmB,EAA3C;AAEAD,EAAAA,WAAW,GAAGA,WAAW,CAACE,OAAZ,CAAoBlB,iBAApB,EAAuC,GAAvC,CAAd;AAEAgB,EAAAA,WAAW,GAAGD,OAAO,GAC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;;eASQpB,c","sourcesContent":["/* eslint-disable no-console */\nimport * as mathjs from 'mathjs';\nimport me from '@pie-framework/math-expressions';\n\nconst decimalCommaRegex = /,/g;\nconst decimalRegex = /\\.|,/g;\nconst decimalWithThousandSeparatorNumberRegex = /^(?!0+\\.00)(?=.{1,9}(\\.|$))(?!0(?!\\.))\\d{1,3}(,\\d{3})*(\\.\\d+)?$/;\n\nconst rationalizeAllPossibleSubNodes = expression => rationalize(mathjs.parse(expression));\nconst rationalize = tree => {\n const transformedTree = tree.transform(node => {\n try {\n const rationalizedNode = mathjs.rationalize(node);\n return rationalizedNode;\n } catch {\n return node;\n }\n });\n return transformedTree;\n};\n\nfunction prepareExpression(string, isLatex) {\n let returnValue = string ? string.trim() : '';\n\n returnValue = returnValue.replace(decimalCommaRegex, '.');\n\n returnValue = isLatex\n ? latexToText(`${returnValue}`)\n : textToMathText(`${returnValue}`, { unknownCommands: 'passthrough' }).toString();\n\n returnValue = returnValue.replace('=', '==');\n return rationalizeAllPossibleSubNodes(returnValue);\n}\n\nconst latexToAstOpts = {\n missingFactor: (token, e) => {\n console.warn('missing factor for: ', token.token_type);\n if (token.token_type === 'NUMBER') {\n throw e;\n }\n return 0;\n },\n unknownCommandBehavior: 'passthrough'\n};\n\nconst astToTextOpts = {\n unicode_operators: {\n ne: function(operands) {\n return operands.join(' != ');\n },\n '%': function(operands) {\n return `percent(${operands[0]})`;\n }\n }\n};\n\nexport const latexToText = (latex, extraOtps = {}) => {\n const la = new me.converters.latexToAstObj({ ...latexToAstOpts, ...extraOtps });\n\n const at = new me.converters.astToTextObj({ ...astToTextOpts, ...extraOtps });\n\n const ast = la.convert(latex);\n\n return at.convert(ast);\n};\n\nexport const textToMathText = (latex, extraOtps = {}) => {\n const la = new me.converters.textToAstObj({ ...latexToAstOpts, ...extraOtps });\n\n const at = new me.converters.astToTextObj({ ...astToTextOpts, ...extraOtps });\n\n const ast = la.convert(latex);\n\n return at.convert(ast);\n};\n\nfunction shouldRationalizeEntireTree(tree) {\n let shouldDoIt = true;\n\n // we need to iterate the entire tree to check for some conditions that might make rationalization impossible\n try {\n tree.traverse(node => {\n // if we have a variable as an exponent for power operation, we should not rationalize\n // try to see if there are power operations with variable exponents\n if (node.type === 'OperatorNode' && node.fn === 'pow') {\n const exponent = node.args[1];\n\n // try to see if it can be compiled and evaluated - if it's a non-numerical value, it'll throw an error\n exponent.compile().eval();\n }\n\n // we cannot have variables for unresolved function calls either\n if (node.type === 'FunctionNode') {\n //try to see if the argument that the function is called with can be resolved as non-variable\n const functionParameter = node.args[0];\n\n // if it holds variables, this will throw an error\n functionParameter.compile().eval();\n }\n });\n\n mathjs.rationalize(tree);\n } catch {\n shouldDoIt = false;\n }\n\n return shouldDoIt;\n}\n\nfunction containsDecimal(expression = '') {\n return expression.match(decimalRegex);\n}\nconst SIMPLIFY_RULES = [\n { l: 'n1^(1/n2)', r: 'nthRoot(n1, n2)' },\n { l: 'sqrt(n1)', r: 'nthRoot(n1, 2)' }\n];\n\nconst simplify = v => mathjs.simplify(v, SIMPLIFY_RULES.concat(mathjs.simplify.rules)); //.concat(SIMPLIFY_RULES));\n\nconst areValuesEqual = (valueOne, valueTwo, options = {}) => {\n const {\n // if explicitly set to false, having a decimal value in either side will result in a false equality\n // regardless of mathematical correctness\n allowDecimals,\n isLatex, // if the passed in values are latex, they need to be escaped\n inverse // returns inverse for the comparison result\n } = options;\n\n let valueOneToUse = valueOne;\n let valueTwoToUse = valueTwo;\n\n if (allowDecimals === false) {\n if (containsDecimal(valueOne) || containsDecimal(valueTwo)) {\n return false;\n }\n } else if (allowDecimals === true) {\n if (containsDecimal(valueOne) && decimalWithThousandSeparatorNumberRegex.test(valueOne)) {\n valueOneToUse = valueOne.replace(decimalCommaRegex, '');\n }\n\n if (containsDecimal(valueTwo) && decimalWithThousandSeparatorNumberRegex.test(valueTwo)) {\n valueTwoToUse = valueTwo.replace(decimalCommaRegex, '');\n }\n }\n\n const preparedValueOne = prepareExpression(valueOneToUse, isLatex, allowDecimals);\n const preparedValueTwo = prepareExpression(valueTwoToUse, isLatex, allowDecimals);\n\n let one = shouldRationalizeEntireTree(preparedValueOne)\n ? mathjs.rationalize(preparedValueOne)\n : preparedValueOne;\n let two = shouldRationalizeEntireTree(preparedValueTwo)\n ? mathjs.rationalize(preparedValueTwo)\n : preparedValueTwo;\n\n one = simplify(one);\n two = simplify(two);\n\n const equals = one.equals(two);\n\n return inverse ? !equals : equals;\n};\n\nexport const ave = (a, b) => {\n const am = mathjs.parse(a);\n const bm = mathjs.parse(b);\n\n const arm = simplify(am);\n const brm = simplify(bm);\n return arm.equals(brm);\n};\n\nexport default areValuesEqual;\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["decimalCommaRegex","decimalRegex","decimalWithThousandSeparatorNumberRegex","rationalizeAllPossibleSubNodes","expression","rationalize","mathjs","parse","tree","transformedTree","transform","node","rationalizedNode","prepareExpression","string","isLatex","returnValue","trim","replace","latexToText","textToMathText","unknownCommands","toString","latexToAstOpts","missingFactor","token","e","console","warn","token_type","unknownCommandBehavior","astToTextOpts","unicode_operators","ne","operands","join","latex","extraOtps","la","me","converters","latexToAstObj","at","astToTextObj","ast","convert","textToAstObj","shouldRationalizeEntireTree","shouldDoIt","traverse","type","fn","exponent","args","compile","eval","functionParameter","containsDecimal","match","SIMPLIFY_RULES","l","r","simplify","v","concat","rules","areValuesEqual","valueOne","valueTwo","options","allowDecimals","inverse","valueOneToUse","valueTwoToUse","test","preparedValueOne","preparedValueTwo","one","two","equals","ave","a","b","am","bm","arm","brm"],"mappings":";;;;;;;;;;;;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,iBAAiB,GAAG,IAA1B;AACA,IAAMC,YAAY,GAAG,OAArB;AACA,IAAMC,uCAAuC,GAAG,iEAAhD;;AAEA,IAAMC,8BAA8B,GAAG,SAAjCA,8BAAiC,CAACC,UAAD;AAAA,SAAgBC,WAAW,CAACC,MAAM,CAACC,KAAP,CAAaH,UAAb,CAAD,CAA3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AAGf,QAAQ,CAACe,GAAD,CAAd;AACAC,EAAAA,GAAG,GAAGhB,QAAQ,CAACgB,GAAD,CAAd;AAEA,MAAMC,MAAM,GAAGF,GAAG,CAACE,MAAJ,CAAWD,GAAX,CAAf;AAEA,SAAOP,OAAO,GAAG,CAACQ,MAAJ,GAAaA,MAA3B;AACD,CAtCD;;AAwCO,IAAMC,GAAG,GAAG,SAANA,GAAM,CAACC,CAAD,EAAIC,CAAJ,EAAU;AAC3B,MAAMC,EAAE,GAAG7E,MAAM,CAACC,KAAP,CAAa0E,CAAb,CAAX;AACA,MAAMG,EAAE,GAAG9E,MAAM,CAACC,KAAP,CAAa2E,CAAb,CAAX;AAEA,MAAMG,GAAG,GAAGvB,QAAQ,CAACqB,EAAD,CAApB;AACA,MAAMG,GAAG,GAAGxB,QAAQ,CAACsB,EAAD,CAApB;AACA,SAAOC,GAAG,CAACN,MAAJ,CAAWO,GAAX,CAAP;AACD,CAPM;;;eASQpB,c","sourcesContent":["/* eslint-disable no-console */\nimport * as mathjs from 'mathjs';\nimport me from '@pie-framework/math-expressions';\n\nconst decimalCommaRegex = /,/g;\nconst decimalRegex = /\\.|,/g;\nconst decimalWithThousandSeparatorNumberRegex = /^(?!0+\\.00)(?=.{1,9}(\\.|$))(?!0(?!\\.))\\d{1,3}(,\\d{3})*(\\.\\d+)?$/;\n\nconst rationalizeAllPossibleSubNodes = (expression) => rationalize(mathjs.parse(expression));\nconst rationalize = (tree) => {\n const transformedTree = tree.transform((node) => {\n try {\n const rationalizedNode = mathjs.rationalize(node);\n return rationalizedNode;\n } catch {\n return node;\n }\n });\n return transformedTree;\n};\n\nfunction prepareExpression(string, isLatex) {\n let returnValue = string ? string.trim() : '';\n\n returnValue = returnValue.replace(decimalCommaRegex, '.');\n\n returnValue = isLatex\n ? latexToText(`${returnValue}`)\n : textToMathText(`${returnValue}`, { unknownCommands: 'passthrough' }).toString();\n\n returnValue = returnValue.replace('=', '==');\n return rationalizeAllPossibleSubNodes(returnValue);\n}\n\nconst latexToAstOpts = {\n missingFactor: (token, e) => {\n console.warn('missing factor for: ', token.token_type);\n if (token.token_type === 'NUMBER') {\n throw e;\n }\n return 0;\n },\n unknownCommandBehavior: 'passthrough',\n};\n\nconst astToTextOpts = {\n unicode_operators: {\n ne: function(operands) {\n return operands.join(' != ');\n },\n '%': function(operands) {\n return `percent(${operands[0]})`;\n },\n },\n};\n\nexport const latexToText = (latex, extraOtps = {}) => {\n const la = new me.converters.latexToAstObj({ ...latexToAstOpts, ...extraOtps });\n\n const at = new me.converters.astToTextObj({ ...astToTextOpts, ...extraOtps });\n\n const ast = la.convert(latex);\n\n return at.convert(ast);\n};\n\nexport const textToMathText = (latex, extraOtps = {}) => {\n const la = new me.converters.textToAstObj({ ...latexToAstOpts, ...extraOtps });\n\n const at = new me.converters.astToTextObj({ ...astToTextOpts, ...extraOtps });\n\n const ast = la.convert(latex);\n\n return at.convert(ast);\n};\n\nfunction shouldRationalizeEntireTree(tree) {\n let shouldDoIt = true;\n\n // we need to iterate the entire tree to check for some conditions that might make rationalization impossible\n try {\n tree.traverse((node) => {\n // if we have a variable as an exponent for power operation, we should not rationalize\n // try to see if there are power operations with variable exponents\n if (node.type === 'OperatorNode' && node.fn === 'pow') {\n const exponent = node.args[1];\n\n // try to see if it can be compiled and evaluated - if it's a non-numerical value, it'll throw an error\n exponent.compile().eval();\n }\n\n // we cannot have variables for unresolved function calls either\n if (node.type === 'FunctionNode') {\n //try to see if the argument that the function is called with can be resolved as non-variable\n const functionParameter = node.args[0];\n\n // if it holds variables, this will throw an error\n functionParameter.compile().eval();\n }\n });\n\n mathjs.rationalize(tree);\n } catch {\n shouldDoIt = false;\n }\n\n return shouldDoIt;\n}\n\nfunction containsDecimal(expression = '') {\n return expression.match(decimalRegex);\n}\nconst SIMPLIFY_RULES = [\n { l: 'n1^(1/n2)', r: 'nthRoot(n1, n2)' },\n { l: 'sqrt(n1)', r: 'nthRoot(n1, 2)' },\n];\n\nconst simplify = (v) => mathjs.simplify(v, SIMPLIFY_RULES.concat(mathjs.simplify.rules)); //.concat(SIMPLIFY_RULES));\n\nconst areValuesEqual = (valueOne, valueTwo, options = {}) => {\n const {\n // if explicitly set to false, having a decimal value in either side will result in a false equality\n // regardless of mathematical correctness\n allowDecimals,\n isLatex, // if the passed in values are latex, they need to be escaped\n inverse, // returns inverse for the comparison result\n } = options;\n\n let valueOneToUse = valueOne;\n let valueTwoToUse = valueTwo;\n\n if (allowDecimals === false) {\n if (containsDecimal(valueOne) || containsDecimal(valueTwo)) {\n return false;\n }\n } else if (allowDecimals === true) {\n if (containsDecimal(valueOne) && decimalWithThousandSeparatorNumberRegex.test(valueOne)) {\n valueOneToUse = valueOne.replace(decimalCommaRegex, '');\n }\n\n if (containsDecimal(valueTwo) && decimalWithThousandSeparatorNumberRegex.test(valueTwo)) {\n valueTwoToUse = valueTwo.replace(decimalCommaRegex, '');\n }\n }\n\n const preparedValueOne = prepareExpression(valueOneToUse, isLatex, allowDecimals);\n const preparedValueTwo = prepareExpression(valueTwoToUse, isLatex, allowDecimals);\n\n let one = shouldRationalizeEntireTree(preparedValueOne) ? mathjs.rationalize(preparedValueOne) : preparedValueOne;\n let two = shouldRationalizeEntireTree(preparedValueTwo) ? mathjs.rationalize(preparedValueTwo) : preparedValueTwo;\n\n one = simplify(one);\n two = simplify(two);\n\n const equals = one.equals(two);\n\n return inverse ? !equals : equals;\n};\n\nexport const ave = (a, b) => {\n const am = mathjs.parse(a);\n const bm = mathjs.parse(b);\n\n const arm = simplify(am);\n const brm = simplify(bm);\n return arm.equals(brm);\n};\n\nexport default areValuesEqual;\n"],"file":"index.js"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.1.4",
6
+ "version": "2.1.7",
7
7
  "description": "Math evaluator tool for comparing expressions for equality",
8
8
  "keywords": [
9
9
  "math",
@@ -22,8 +22,8 @@
22
22
  "mathjs": "^7.0.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@pie-lib/test-utils": "^0.2.17"
25
+ "@pie-lib/test-utils": "^0.2.20"
26
26
  },
27
27
  "scripts": {},
28
- "gitHead": "e6de0d62291ecfdeb3a62b988c526d97ee41eaa6"
28
+ "gitHead": "f81076118e63884db5f5d65a41cff9aad111137e"
29
29
  }
package/src/index.js CHANGED
@@ -6,9 +6,9 @@ const decimalCommaRegex = /,/g;
6
6
  const decimalRegex = /\.|,/g;
7
7
  const decimalWithThousandSeparatorNumberRegex = /^(?!0+\.00)(?=.{1,9}(\.|$))(?!0(?!\.))\d{1,3}(,\d{3})*(\.\d+)?$/;
8
8
 
9
- const rationalizeAllPossibleSubNodes = expression => rationalize(mathjs.parse(expression));
10
- const rationalize = tree => {
11
- const transformedTree = tree.transform(node => {
9
+ const rationalizeAllPossibleSubNodes = (expression) => rationalize(mathjs.parse(expression));
10
+ const rationalize = (tree) => {
11
+ const transformedTree = tree.transform((node) => {
12
12
  try {
13
13
  const rationalizedNode = mathjs.rationalize(node);
14
14
  return rationalizedNode;
@@ -40,7 +40,7 @@ const latexToAstOpts = {
40
40
  }
41
41
  return 0;
42
42
  },
43
- unknownCommandBehavior: 'passthrough'
43
+ unknownCommandBehavior: 'passthrough',
44
44
  };
45
45
 
46
46
  const astToTextOpts = {
@@ -50,8 +50,8 @@ const astToTextOpts = {
50
50
  },
51
51
  '%': function(operands) {
52
52
  return `percent(${operands[0]})`;
53
- }
54
- }
53
+ },
54
+ },
55
55
  };
56
56
 
57
57
  export const latexToText = (latex, extraOtps = {}) => {
@@ -79,7 +79,7 @@ function shouldRationalizeEntireTree(tree) {
79
79
 
80
80
  // we need to iterate the entire tree to check for some conditions that might make rationalization impossible
81
81
  try {
82
- tree.traverse(node => {
82
+ tree.traverse((node) => {
83
83
  // if we have a variable as an exponent for power operation, we should not rationalize
84
84
  // try to see if there are power operations with variable exponents
85
85
  if (node.type === 'OperatorNode' && node.fn === 'pow') {
@@ -112,10 +112,10 @@ function containsDecimal(expression = '') {
112
112
  }
113
113
  const SIMPLIFY_RULES = [
114
114
  { l: 'n1^(1/n2)', r: 'nthRoot(n1, n2)' },
115
- { l: 'sqrt(n1)', r: 'nthRoot(n1, 2)' }
115
+ { l: 'sqrt(n1)', r: 'nthRoot(n1, 2)' },
116
116
  ];
117
117
 
118
- const simplify = v => mathjs.simplify(v, SIMPLIFY_RULES.concat(mathjs.simplify.rules)); //.concat(SIMPLIFY_RULES));
118
+ const simplify = (v) => mathjs.simplify(v, SIMPLIFY_RULES.concat(mathjs.simplify.rules)); //.concat(SIMPLIFY_RULES));
119
119
 
120
120
  const areValuesEqual = (valueOne, valueTwo, options = {}) => {
121
121
  const {
@@ -123,7 +123,7 @@ const areValuesEqual = (valueOne, valueTwo, options = {}) => {
123
123
  // regardless of mathematical correctness
124
124
  allowDecimals,
125
125
  isLatex, // if the passed in values are latex, they need to be escaped
126
- inverse // returns inverse for the comparison result
126
+ inverse, // returns inverse for the comparison result
127
127
  } = options;
128
128
 
129
129
  let valueOneToUse = valueOne;
@@ -146,12 +146,8 @@ const areValuesEqual = (valueOne, valueTwo, options = {}) => {
146
146
  const preparedValueOne = prepareExpression(valueOneToUse, isLatex, allowDecimals);
147
147
  const preparedValueTwo = prepareExpression(valueTwoToUse, isLatex, allowDecimals);
148
148
 
149
- let one = shouldRationalizeEntireTree(preparedValueOne)
150
- ? mathjs.rationalize(preparedValueOne)
151
- : preparedValueOne;
152
- let two = shouldRationalizeEntireTree(preparedValueTwo)
153
- ? mathjs.rationalize(preparedValueTwo)
154
- : preparedValueTwo;
149
+ let one = shouldRationalizeEntireTree(preparedValueOne) ? mathjs.rationalize(preparedValueOne) : preparedValueOne;
150
+ let two = shouldRationalizeEntireTree(preparedValueTwo) ? mathjs.rationalize(preparedValueTwo) : preparedValueTwo;
155
151
 
156
152
  one = simplify(one);
157
153
  two = simplify(two);