From f0822e527e17cc2114b1fa2d75f95d33bf97ce91 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 9 Jul 2026 13:30:31 +0200 Subject: [PATCH] Replace a couple of `indexOf` calls with `startsWith` These cases weren't detected/fixed by the following ESLint plugin rule; see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-starts-ends-with.md Additionally, replace the `if` with a ternary statement in the `external/builder/builder.mjs` file since this patch touches that code anyway. --- external/builder/builder.mjs | 13 +++---------- external/cmapscompress/compress.mjs | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/external/builder/builder.mjs b/external/builder/builder.mjs index c212d01f9..223beff1e 100644 --- a/external/builder/builder.mjs +++ b/external/builder/builder.mjs @@ -113,16 +113,9 @@ function preprocess(inFilename, outFilename, defines) { const realPath = fs.realpathSync(inFilename); const dir = path.dirname(realPath); try { - let fullpath; - if (file.indexOf("$ROOT/") === 0) { - fullpath = path.join( - __dirname, - "../..", - file.substring("$ROOT/".length) - ); - } else { - fullpath = path.join(dir, file); - } + const fullpath = file.startsWith("$ROOT/") + ? path.join(__dirname, "../..", file.substring("$ROOT/".length)) + : path.join(dir, file); preprocess(fullpath, writeLine, defines); } catch (e) { if (e.code === "ENOENT") { diff --git a/external/cmapscompress/compress.mjs b/external/cmapscompress/compress.mjs index 06a46c499..4792b1f44 100644 --- a/external/cmapscompress/compress.mjs +++ b/external/cmapscompress/compress.mjs @@ -386,7 +386,7 @@ function writeNumber(n) { if (buffer > 0) { s = writeByte((buffer & 0x7f) | (s.length > 0 ? 0x80 : 0)) + s; } - while (s.indexOf("80") === 0) { + while (s.startsWith("80")) { s = s.substring(2); } return s;