mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Convert some usage of indexOf
to startsWith
/includes
where applicable
In many cases in the code you don't actually care about the index itself, but rather just want to know if something exists in a String/Array or if a String starts in a particular way. With modern JavaScript functionality, it's thus possible to remove a number of existing `indexOf` cases.
This commit is contained in:
parent
cdbc33ba06
commit
24a688d6c6
10 changed files with 22 additions and 28 deletions
8
external/builder/builder.js
vendored
8
external/builder/builder.js
vendored
|
@ -165,8 +165,8 @@ function preprocess(inFilename, outFilename, defines) {
|
|||
if (state === STATE_NONE) {
|
||||
writeLine(line);
|
||||
} else if ((state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) &&
|
||||
stack.indexOf(STATE_IF_FALSE) === -1 &&
|
||||
stack.indexOf(STATE_ELSE_FALSE) === -1) {
|
||||
!stack.includes(STATE_IF_FALSE) &&
|
||||
!stack.includes(STATE_ELSE_FALSE)) {
|
||||
writeLine(line.replace(/^\/\/|^<!--|-->$/g, ' '));
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ function preprocessCSS(mode, source, destination) {
|
|||
if (checkBracket) {
|
||||
if (checkBracket[1] === '{') {
|
||||
bracketLevel++;
|
||||
} else if (lines[j].indexOf('{') < 0) {
|
||||
} else if (!lines[j].includes('{')) {
|
||||
bracketLevel--;
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ function preprocessCSS(mode, source, destination) {
|
|||
lines.splice(i, 1);
|
||||
} while (i < lines.length &&
|
||||
!/\}\s*$/.test(lines[i]) &&
|
||||
lines[i].indexOf(':') < 0);
|
||||
!lines[i].includes(':'));
|
||||
if (i < lines.length && /\S\s*}\s*$/.test(lines[i])) {
|
||||
lines[i] = lines[i].substring(lines[i].indexOf('}'));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue