Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
beb630d5a2 | ||
|
|
eeb4f8a0fa |
10
lib/calc.js
10
lib/calc.js
@ -1,4 +1,8 @@
|
|||||||
module.exports = function (s) {
|
/* eslint-disable */
|
||||||
|
// 四则运算
|
||||||
|
|
||||||
|
!(function () {
|
||||||
|
var calculate = function (s) {
|
||||||
s = s.trim();
|
s = s.trim();
|
||||||
const stack = new Array();
|
const stack = new Array();
|
||||||
let preSign = '+';
|
let preSign = '+';
|
||||||
@ -18,7 +22,7 @@ module.exports = function (s) {
|
|||||||
numStr = `${calculate(s.slice(i + 1, j))}`;
|
numStr = `${calculate(s.slice(i + 1, j))}`;
|
||||||
i = 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);
|
let num = parseFloat(numStr);
|
||||||
switch (preSign) {
|
switch (preSign) {
|
||||||
case '+':
|
case '+':
|
||||||
@ -46,3 +50,5 @@ module.exports = function (s) {
|
|||||||
}
|
}
|
||||||
return ans;
|
return ans;
|
||||||
};
|
};
|
||||||
|
module.exports = calculate;
|
||||||
|
})();
|
||||||
|
|||||||
@ -851,7 +851,7 @@ function setStringPrototype(screenK, scale) {
|
|||||||
const formula = /^calc\((.+)\)$/.exec(this);
|
const formula = /^calc\((.+)\)$/.exec(this);
|
||||||
if (formula && formula[1]) {
|
if (formula && formula[1]) {
|
||||||
// 进行 calc 计算
|
// 进行 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('.');
|
const [id, attr] = word.split('.');
|
||||||
return penCache.viewRect[id][attr];
|
return penCache.viewRect[id][attr];
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user