@pie-lib/math-evaluator 2.4.0 → 2.5.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/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.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.4.0) (2025-07-31)
6
+ # [2.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.5.0) (2025-07-31)
7
7
 
8
8
  **Note:** Version bump only for package @pie-lib/math-evaluator
9
9
 
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
- # [2.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.3.0) (2025-07-31)
14
+ # [2.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.4.0) (2025-07-31)
15
15
 
16
16
  **Note:** Version bump only for package @pie-lib/math-evaluator
17
17
 
@@ -19,7 +19,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
19
19
 
20
20
 
21
21
 
22
- # [2.2.0-beta.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.8) (2025-07-25)
22
+ # [2.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.3.0) (2025-07-31)
23
23
 
24
24
  **Note:** Version bump only for package @pie-lib/math-evaluator
25
25
 
@@ -27,142 +27,90 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
27
27
 
28
28
 
29
29
 
30
- # [2.2.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.7) (2025-07-25)
30
+ # [2.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.3.0) (2025-07-31)
31
31
 
32
32
  **Note:** Version bump only for package @pie-lib/math-evaluator
33
33
 
34
+ # [2.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.4.0) (2025-07-31)
34
35
 
36
+ **Note:** Version bump only for package @pie-lib/math-evaluator
35
37
 
38
+ # [2.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.3.0) (2025-07-31)
36
39
 
40
+ **Note:** Version bump only for package @pie-lib/math-evaluator
37
41
 
38
- # [2.2.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.7) (2025-07-25)
42
+ # [2.2.0-beta.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.8) (2025-07-25)
39
43
 
40
44
  **Note:** Version bump only for package @pie-lib/math-evaluator
41
45
 
46
+ # [2.2.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.7) (2025-07-25)
42
47
 
48
+ **Note:** Version bump only for package @pie-lib/math-evaluator
43
49
 
50
+ # [2.2.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.7) (2025-07-25)
44
51
 
52
+ **Note:** Version bump only for package @pie-lib/math-evaluator
45
53
 
46
54
  # [2.2.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.6) (2025-07-25)
47
55
 
48
56
  **Note:** Version bump only for package @pie-lib/math-evaluator
49
57
 
50
-
51
-
52
-
53
-
54
58
  # [2.2.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.6) (2025-07-25)
55
59
 
56
60
  **Note:** Version bump only for package @pie-lib/math-evaluator
57
61
 
58
-
59
-
60
-
61
-
62
62
  # [2.2.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.5) (2025-07-25)
63
63
 
64
64
  **Note:** Version bump only for package @pie-lib/math-evaluator
65
65
 
66
-
67
-
68
-
69
-
70
66
  # [2.2.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.5) (2025-07-25)
71
67
 
72
68
  **Note:** Version bump only for package @pie-lib/math-evaluator
73
69
 
74
-
75
-
76
-
77
-
78
70
  # [2.2.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.4) (2025-07-25)
79
71
 
80
72
  **Note:** Version bump only for package @pie-lib/math-evaluator
81
73
 
82
-
83
-
84
-
85
-
86
74
  # [2.2.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.3) (2025-07-25)
87
75
 
88
76
  **Note:** Version bump only for package @pie-lib/math-evaluator
89
77
 
90
-
91
-
92
-
93
-
94
78
  # [2.2.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.4) (2025-07-23)
95
79
 
96
80
  **Note:** Version bump only for package @pie-lib/math-evaluator
97
81
 
98
-
99
-
100
-
101
-
102
82
  # [2.2.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.3) (2025-07-23)
103
83
 
104
84
  **Note:** Version bump only for package @pie-lib/math-evaluator
105
85
 
106
-
107
-
108
-
109
-
110
86
  # [2.2.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.3) (2025-07-20)
111
87
 
112
88
  **Note:** Version bump only for package @pie-lib/math-evaluator
113
89
 
114
-
115
-
116
-
117
-
118
90
  # [2.2.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.2) (2025-07-20)
119
91
 
120
92
  **Note:** Version bump only for package @pie-lib/math-evaluator
121
93
 
122
-
123
-
124
-
125
-
126
94
  # [2.2.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.1) (2025-07-20)
127
95
 
128
96
  **Note:** Version bump only for package @pie-lib/math-evaluator
129
97
 
130
-
131
-
132
-
133
-
134
98
  # [2.2.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.2) (2025-07-20)
135
99
 
136
100
  **Note:** Version bump only for package @pie-lib/math-evaluator
137
101
 
138
-
139
-
140
-
141
-
142
102
  # [2.2.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.1) (2025-07-20)
143
103
 
144
104
  **Note:** Version bump only for package @pie-lib/math-evaluator
145
105
 
146
-
147
-
148
-
149
-
150
106
  # [2.2.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.1) (2025-07-20)
151
107
 
152
108
  **Note:** Version bump only for package @pie-lib/math-evaluator
153
109
 
154
-
155
-
156
-
157
-
158
110
  # [2.2.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.2.0-beta.0) (2025-07-20)
159
111
 
160
112
  **Note:** Version bump only for package @pie-lib/math-evaluator
161
113
 
162
-
163
-
164
-
165
-
166
114
  # [2.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-evaluator@2.1.23...@pie-lib/math-evaluator@2.3.0-beta.0) (2025-07-15)
167
115
 
168
116
  **Note:** Version bump only for package @pie-lib/math-evaluator
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.4.0",
6
+ "version": "2.5.0",
7
7
  "description": "Math evaluator tool for comparing expressions for equality",
8
8
  "keywords": [
9
9
  "math",
@@ -23,8 +23,8 @@
23
23
  "mathjs": "^7.0.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@pie-lib/test-utils": "beta"
26
+ "@pie-lib/test-utils": "^0.6.0"
27
27
  },
28
28
  "scripts": {},
29
- "gitHead": "ecb1ca31aa1c24d23af00d5ad04ce73ed8871057"
29
+ "gitHead": "889a13bfea2c768b8a3a6eabfc6fe7b7725aa832"
30
30
  }
package/lib/index.js DELETED
@@ -1,189 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.textToMathText = exports.latexToText = exports["default"] = exports.ave = void 0;
11
-
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
- var mathjs = _interopRequireWildcard(require("mathjs"));
15
-
16
- var _mathExpressions = _interopRequireDefault(require("@pie-framework/math-expressions"));
17
-
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); }
19
-
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; }
21
-
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; }
23
-
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; }
25
-
26
- var decimalCommaRegex = /,/g;
27
- var decimalRegex = /\.|,/g;
28
- var decimalWithThousandSeparatorNumberRegex = /^(?!0+\.00)(?=.{1,9}(\.|$))(?!0(?!\.))\d{1,3}(,\d{3})*(\.\d+)?$/;
29
-
30
- var rationalizeAllPossibleSubNodes = function rationalizeAllPossibleSubNodes(expression) {
31
- return rationalize(mathjs.parse(expression));
32
- };
33
-
34
- var rationalize = function rationalize(tree) {
35
- var transformedTree = tree.transform(function (node) {
36
- try {
37
- var rationalizedNode = mathjs.rationalize(node);
38
- return rationalizedNode;
39
- } catch (_unused) {
40
- return node;
41
- }
42
- });
43
- return transformedTree;
44
- };
45
-
46
- function prepareExpression(string, isLatex) {
47
- var returnValue = string ? string.trim() : '';
48
- returnValue = returnValue.replace(decimalCommaRegex, '.');
49
- returnValue = isLatex ? latexToText("".concat(returnValue)) : textToMathText("".concat(returnValue), {
50
- unknownCommands: 'passthrough'
51
- }).toString();
52
- returnValue = returnValue.replace('=', '==');
53
- return rationalizeAllPossibleSubNodes(returnValue);
54
- }
55
-
56
- var latexToAstOpts = {
57
- missingFactor: function missingFactor(token, e) {
58
- console.warn('missing factor for: ', token.token_type);
59
-
60
- if (token.token_type === 'NUMBER') {
61
- throw e;
62
- }
63
-
64
- return 0;
65
- },
66
- unknownCommandBehavior: 'passthrough'
67
- };
68
- var astToTextOpts = {
69
- unicode_operators: {
70
- ne: function ne(operands) {
71
- return operands.join(' != ');
72
- },
73
- '%': function _(operands) {
74
- return "percent(".concat(operands[0], ")");
75
- }
76
- }
77
- };
78
-
79
- var latexToText = function latexToText(latex) {
80
- var extraOtps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
81
- var la = new _mathExpressions["default"].converters.latexToAstObj(_objectSpread(_objectSpread({}, latexToAstOpts), extraOtps));
82
- var at = new _mathExpressions["default"].converters.astToTextObj(_objectSpread(_objectSpread({}, astToTextOpts), extraOtps));
83
- var ast = la.convert(latex);
84
- return at.convert(ast);
85
- };
86
-
87
- exports.latexToText = latexToText;
88
-
89
- var textToMathText = function textToMathText(latex) {
90
- var extraOtps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
91
- var la = new _mathExpressions["default"].converters.textToAstObj(_objectSpread(_objectSpread({}, latexToAstOpts), extraOtps));
92
- var at = new _mathExpressions["default"].converters.astToTextObj(_objectSpread(_objectSpread({}, astToTextOpts), extraOtps));
93
- var ast = la.convert(latex);
94
- return at.convert(ast);
95
- };
96
-
97
- exports.textToMathText = textToMathText;
98
-
99
- function shouldRationalizeEntireTree(tree) {
100
- var shouldDoIt = true; // we need to iterate the entire tree to check for some conditions that might make rationalization impossible
101
-
102
- try {
103
- tree.traverse(function (node) {
104
- // if we have a variable as an exponent for power operation, we should not rationalize
105
- // try to see if there are power operations with variable exponents
106
- if (node.type === 'OperatorNode' && node.fn === 'pow') {
107
- var exponent = node.args[1]; // try to see if it can be compiled and evaluated - if it's a non-numerical value, it'll throw an error
108
-
109
- exponent.compile().eval();
110
- } // we cannot have variables for unresolved function calls either
111
-
112
-
113
- if (node.type === 'FunctionNode') {
114
- //try to see if the argument that the function is called with can be resolved as non-variable
115
- var functionParameter = node.args[0]; // if it holds variables, this will throw an error
116
-
117
- functionParameter.compile().eval();
118
- }
119
- });
120
- mathjs.rationalize(tree);
121
- } catch (_unused2) {
122
- shouldDoIt = false;
123
- }
124
-
125
- return shouldDoIt;
126
- }
127
-
128
- function containsDecimal() {
129
- var expression = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
130
- return expression.match(decimalRegex);
131
- }
132
-
133
- var SIMPLIFY_RULES = [{
134
- l: 'n1^(1/n2)',
135
- r: 'nthRoot(n1, n2)'
136
- }, {
137
- l: 'sqrt(n1)',
138
- r: 'nthRoot(n1, 2)'
139
- }];
140
-
141
- var simplify = function simplify(v) {
142
- return mathjs.simplify(v, SIMPLIFY_RULES.concat(mathjs.simplify.rules));
143
- }; //.concat(SIMPLIFY_RULES));
144
-
145
-
146
- var areValuesEqual = function areValuesEqual(valueOne, valueTwo) {
147
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
148
- var allowDecimals = options.allowDecimals,
149
- isLatex = options.isLatex,
150
- inverse = options.inverse;
151
- var valueOneToUse = valueOne;
152
- var valueTwoToUse = valueTwo;
153
-
154
- if (allowDecimals === false) {
155
- if (containsDecimal(valueOne) || containsDecimal(valueTwo)) {
156
- return false;
157
- }
158
- } else if (allowDecimals === true) {
159
- if (containsDecimal(valueOne) && decimalWithThousandSeparatorNumberRegex.test(valueOne)) {
160
- valueOneToUse = valueOne.replace(decimalCommaRegex, '');
161
- }
162
-
163
- if (containsDecimal(valueTwo) && decimalWithThousandSeparatorNumberRegex.test(valueTwo)) {
164
- valueTwoToUse = valueTwo.replace(decimalCommaRegex, '');
165
- }
166
- }
167
-
168
- var preparedValueOne = prepareExpression(valueOneToUse, isLatex, allowDecimals);
169
- var preparedValueTwo = prepareExpression(valueTwoToUse, isLatex, allowDecimals);
170
- var one = shouldRationalizeEntireTree(preparedValueOne) ? mathjs.rationalize(preparedValueOne) : preparedValueOne;
171
- var two = shouldRationalizeEntireTree(preparedValueTwo) ? mathjs.rationalize(preparedValueTwo) : preparedValueTwo;
172
- one = simplify(one);
173
- two = simplify(two);
174
- var equals = one.equals(two);
175
- return inverse ? !equals : equals;
176
- };
177
-
178
- var ave = function ave(a, b) {
179
- var am = mathjs.parse(a);
180
- var bm = mathjs.parse(b);
181
- var arm = simplify(am);
182
- var brm = simplify(bm);
183
- return arm.equals(brm);
184
- };
185
-
186
- exports.ave = ave;
187
- var _default = areValuesEqual;
188
- exports["default"] = _default;
189
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
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,CAA3B;AAAA,CAAvC;;AACA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACG,IAAD,EAAU;AAC5B,MAAMC,eAAe,GAAGD,IAAI,CAACE,SAAL,CAAe,UAACC,IAAD,EAAU;AAC/C,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,GACjBI,WAAW,WAAIH,WAAJ,EADM,GAEjBI,cAAc,WAAIJ,WAAJ,GAAmB;AAAEK,IAAAA,eAAe,EAAE;AAAnB,GAAnB,CAAd,CAAqEC,QAArE,EAFJ;AAIAN,EAAAA,WAAW,GAAGA,WAAW,CAACE,OAAZ,CAAoB,GAApB,EAAyB,IAAz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AAC2D,aAAD,EAAgBzD,OAAhB,EAAyBuD,aAAzB,CAA1C;AACA,MAAMM,gBAAgB,GAAG/D,iBAAiB,CAAC4D,aAAD,EAAgB1D,OAAhB,EAAyBuD,aAAzB,CAA1C;AAEA,MAAIO,GAAG,GAAG9B,2BAA2B,CAAC4B,gBAAD,CAA3B,GAAgDrE,MAAM,CAACD,WAAP,CAAmBsE,gBAAnB,CAAhD,GAAuFA,gBAAjG;AACA,MAAIG,GAAG,GAAG/B,2BAA2B,CAAC6B,gBAAD,CAA3B,GAAgDtE,MAAM,CAACD,WAAP,CAAmBuE,gBAAnB,CAAhD,GAAuFA,gBAAjG;AAEAC,EAAAA,GAAG,GAAGf,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"}