Skip to content

Commit

Permalink
Math precision support
Browse files Browse the repository at this point in the history
  • Loading branch information
QartemisT committed Jan 3, 2025
1 parent 85c2235 commit 5318df2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,12 @@ const sanityText = (cacheData, text, overrideSpellID, spellMultiplier) => {
return data.ProcCharges.toLocaleString();
});
text = text.replaceAll('$pri', '<stat>');
text = text.replaceAll(/\${([^}]+)}/g, (repl, math) => { // Math
text = text.replaceAll(/\${([^}]+)}(\.\d+)?/g, (repl, math, precision) => { // Math
math = math.replaceAll(" sec", "").replaceAll(",", ""); // e.g. "30 sec*20"
precision = precision?.replaceAll(".", "") ?? 2;
try {
if (math.match(/^[\s\d().*/+-]+$/g)) { // Matches: Spaces, numbers, brackets, math operations
return eval(math).toLocaleString();
return eval(math).toLocaleString(undefined, { maximumFractionDigits: precision });
}
} catch (_) {
// Do nothing
Expand Down

0 comments on commit 5318df2

Please sign in to comment.