Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
beb630d5a2 | ||
|
|
eeb4f8a0fa |
12
lib/calc.js
12
lib/calc.js
@ -1,4 +1,8 @@
|
||||
module.exports = function (s) {
|
||||
/* eslint-disable */
|
||||
// 四则运算
|
||||
|
||||
!(function () {
|
||||
var calculate = function (s) {
|
||||
s = s.trim();
|
||||
const stack = new Array();
|
||||
let preSign = '+';
|
||||
@ -18,7 +22,7 @@ module.exports = function (s) {
|
||||
numStr = `${calculate(s.slice(i + 1, j))}`;
|
||||
i = j;
|
||||
}
|
||||
if (isNaN(Number(s[i]) && s[i] !== '.') || i === n - 1) {
|
||||
if ((isNaN(Number(s[i])) && s[i] !== '.') || i === n - 1) {
|
||||
let num = parseFloat(numStr);
|
||||
switch (preSign) {
|
||||
case '+':
|
||||
@ -45,4 +49,6 @@ module.exports = function (s) {
|
||||
ans += stack.pop();
|
||||
}
|
||||
return ans;
|
||||
};
|
||||
};
|
||||
module.exports = calculate;
|
||||
})();
|
||||
|
||||
@ -851,7 +851,7 @@ function setStringPrototype(screenK, scale) {
|
||||
const formula = /^calc\((.+)\)$/.exec(this);
|
||||
if (formula && formula[1]) {
|
||||
// 进行 calc 计算
|
||||
const afterOne = formula[1].replace(/([^\s]+)\.(left|right|bottom|top|width|height)/g, word => {
|
||||
const afterOne = formula[1].replace(/([^\s\(\+\-\*\/]+)\.(left|right|bottom|top|width|height)/g, word => {
|
||||
const [id, attr] = word.split('.');
|
||||
return penCache.viewRect[id][attr];
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user