aprog 1.3.1 → 1.3.2
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/package.json +1 -1
- package/src/math.js +6 -12
package/package.json
CHANGED
package/src/math.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
export const mathInput = (target) => {
|
|
2
2
|
const enter = target.value.includes("=");
|
|
3
3
|
let result = target.value;
|
|
4
|
-
if (enter) {
|
|
5
|
-
const parts = target.value.slice(0, -1).split(/([\+\-\*\/])/);
|
|
6
|
-
|
|
7
|
-
const num1 = Number(parts[0]);
|
|
8
|
-
const operator = parts[1];
|
|
9
|
-
const num2 = Number(parts[2]);
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
if (enter) {
|
|
6
|
+
const expression = target.value.slice(0, -1);
|
|
7
|
+
try {
|
|
8
|
+
result = new Function(`return ${expression}`)();
|
|
9
|
+
} catch (error) {
|
|
10
|
+
result = target.value;
|
|
17
11
|
}
|
|
18
12
|
|
|
19
13
|
target.value = result;
|