Skip to content

Commit

Permalink
Shorten a few helper functions in src/core/core_utils.js
Browse files Browse the repository at this point in the history
In a few cases we can ever so slightly shorten the code without negatively impacting the readability.
  • Loading branch information
Snuffleupagus committed Nov 5, 2024
1 parent cefd1eb commit 2c90eee
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/core/core_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,13 @@ function toRomanNumerals(number, lowerCase = false) {
"The number should be a positive integer."
);
const romanBuf = [];
let pos;
// Thousands
while (number >= 1000) {
number -= 1000;
romanBuf.push("M");
}
// Hundreds
pos = (number / 100) | 0;
let pos = (number / 100) | 0;
number %= 100;
romanBuf.push(ROMAN_NUMBER_MAP[pos]);
// Tens
Expand All @@ -191,10 +190,7 @@ function toRomanNumerals(number, lowerCase = false) {
// native function in the sense that it returns the ceiling value and that it
// returns 0 instead of `Infinity`/`NaN` for `x` values smaller than/equal to 0.
function log2(x) {
if (x <= 0) {
return 0;
}
return Math.ceil(Math.log2(x));
return x > 0 ? Math.ceil(Math.log2(x)) : 0;
}

function readInt8(data, offset) {
Expand Down Expand Up @@ -573,13 +569,10 @@ function recoverJsURL(str) {

const jsUrl = regex.exec(str);
if (jsUrl?.[2]) {
const url = jsUrl[2];
let newWindow = false;

if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") {
newWindow = true;
}
return { url, newWindow };
return {
url: jsUrl[2],
newWindow: jsUrl[1] === "app.launchURL" && jsUrl[3] === "true",
};
}

return null;
Expand Down

0 comments on commit 2c90eee

Please sign in to comment.