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
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) {
|
if (state === STATE_NONE) {
|
||||||
writeLine(line);
|
writeLine(line);
|
||||||
} else if ((state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) &&
|
} else if ((state === STATE_IF_TRUE || state === STATE_ELSE_TRUE) &&
|
||||||
stack.indexOf(STATE_IF_FALSE) === -1 &&
|
!stack.includes(STATE_IF_FALSE) &&
|
||||||
stack.indexOf(STATE_ELSE_FALSE) === -1) {
|
!stack.includes(STATE_ELSE_FALSE)) {
|
||||||
writeLine(line.replace(/^\/\/|^<!--|-->$/g, ' '));
|
writeLine(line.replace(/^\/\/|^<!--|-->$/g, ' '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ function preprocessCSS(mode, source, destination) {
|
|||||||
if (checkBracket) {
|
if (checkBracket) {
|
||||||
if (checkBracket[1] === '{') {
|
if (checkBracket[1] === '{') {
|
||||||
bracketLevel++;
|
bracketLevel++;
|
||||||
} else if (lines[j].indexOf('{') < 0) {
|
} else if (!lines[j].includes('{')) {
|
||||||
bracketLevel--;
|
bracketLevel--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ function preprocessCSS(mode, source, destination) {
|
|||||||
lines.splice(i, 1);
|
lines.splice(i, 1);
|
||||||
} while (i < lines.length &&
|
} while (i < lines.length &&
|
||||||
!/\}\s*$/.test(lines[i]) &&
|
!/\}\s*$/.test(lines[i]) &&
|
||||||
lines[i].indexOf(':') < 0);
|
!lines[i].includes(':'));
|
||||||
if (i < lines.length && /\S\s*}\s*$/.test(lines[i])) {
|
if (i < lines.length && /\S\s*}\s*$/.test(lines[i])) {
|
||||||
lines[i] = lines[i].substring(lines[i].indexOf('}'));
|
lines[i] = lines[i].substring(lines[i].indexOf('}'));
|
||||||
}
|
}
|
||||||
|
@ -2533,13 +2533,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var fontNameStr = fontName && fontName.name;
|
var fontNameStr = fontName && fontName.name;
|
||||||
var baseFontStr = baseFont && baseFont.name;
|
var baseFontStr = baseFont && baseFont.name;
|
||||||
if (fontNameStr !== baseFontStr) {
|
if (fontNameStr !== baseFontStr) {
|
||||||
info('The FontDescriptor\'s FontName is "' + fontNameStr +
|
info(`The FontDescriptor\'s FontName is "${fontNameStr}" but ` +
|
||||||
'" but should be the same as the Font\'s BaseFont "' +
|
`should be the same as the Font\'s BaseFont "${baseFontStr}".`);
|
||||||
baseFontStr + '"');
|
|
||||||
// Workaround for cases where e.g. fontNameStr = 'Arial' and
|
// Workaround for cases where e.g. fontNameStr = 'Arial' and
|
||||||
// baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
|
// baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
|
||||||
if (fontNameStr && baseFontStr &&
|
if (fontNameStr && baseFontStr &&
|
||||||
baseFontStr.indexOf(fontNameStr) === 0) {
|
baseFontStr.startsWith(fontNameStr)) {
|
||||||
fontName = baseFont;
|
fontName = baseFont;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1200,7 +1200,7 @@ var Font = (function FontClosure() {
|
|||||||
// if at least one width is present, remeasure all chars when exists
|
// if at least one width is present, remeasure all chars when exists
|
||||||
this.remeasure = Object.keys(this.widths).length > 0;
|
this.remeasure = Object.keys(this.widths).length > 0;
|
||||||
if (isStandardFont && type === 'CIDFontType2' &&
|
if (isStandardFont && type === 'CIDFontType2' &&
|
||||||
this.cidEncoding.indexOf('Identity-') === 0) {
|
this.cidEncoding.startsWith('Identity-')) {
|
||||||
var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
|
var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
|
||||||
// Standard fonts might be embedded as CID font without glyph mapping.
|
// Standard fonts might be embedded as CID font without glyph mapping.
|
||||||
// Building one based on GlyphMapForStandardFonts.
|
// Building one based on GlyphMapForStandardFonts.
|
||||||
|
@ -701,10 +701,7 @@ class Catalog {
|
|||||||
static parseDestDictionary(params) {
|
static parseDestDictionary(params) {
|
||||||
// Lets URLs beginning with 'www.' default to using the 'http://' protocol.
|
// Lets URLs beginning with 'www.' default to using the 'http://' protocol.
|
||||||
function addDefaultProtocolToUrl(url) {
|
function addDefaultProtocolToUrl(url) {
|
||||||
if (url.indexOf('www.') === 0) {
|
return (url.startsWith('www.') ? `http://${url}` : url);
|
||||||
return `http://${url}`;
|
|
||||||
}
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
|
// According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
|
||||||
@ -1234,7 +1231,7 @@ var XRef = (function XRefClosure() {
|
|||||||
}
|
}
|
||||||
var token = readToken(buffer, position);
|
var token = readToken(buffer, position);
|
||||||
var m;
|
var m;
|
||||||
if (token.indexOf('xref') === 0 &&
|
if (token.startsWith('xref') &&
|
||||||
(token.length === 4 || /\s/.test(token[4]))) {
|
(token.length === 4 || /\s/.test(token[4]))) {
|
||||||
position += skipUntil(buffer, position, trailerBytes);
|
position += skipUntil(buffer, position, trailerBytes);
|
||||||
trailers.push(position);
|
trailers.push(position);
|
||||||
@ -1288,7 +1285,7 @@ var XRef = (function XRefClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
position += contentLength;
|
position += contentLength;
|
||||||
} else if (token.indexOf('trailer') === 0 &&
|
} else if (token.startsWith('trailer') &&
|
||||||
(token.length === 7 || /\s/.test(token[7]))) {
|
(token.length === 7 || /\s/.test(token[7]))) {
|
||||||
trailers.push(position);
|
trailers.push(position);
|
||||||
position += skipUntil(buffer, position, startxrefBytes);
|
position += skipUntil(buffer, position, startxrefBytes);
|
||||||
@ -1507,7 +1504,7 @@ var XRef = (function XRefClosure() {
|
|||||||
}
|
}
|
||||||
if (obj3.cmd !== 'obj') {
|
if (obj3.cmd !== 'obj') {
|
||||||
// some bad PDFs use "obj1234" and really mean 1234
|
// some bad PDFs use "obj1234" and really mean 1234
|
||||||
if (obj3.cmd.indexOf('obj') === 0) {
|
if (obj3.cmd.startsWith('obj')) {
|
||||||
num = parseInt(obj3.cmd.substring(3), 10);
|
num = parseInt(obj3.cmd.substring(3), 10);
|
||||||
if (!Number.isNaN(num)) {
|
if (!Number.isNaN(num)) {
|
||||||
return num;
|
return num;
|
||||||
|
@ -253,7 +253,7 @@ var Type2Parser = function type2Parser(aFilePath) {
|
|||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', aFilePath, false);
|
xhr.open('GET', aFilePath, false);
|
||||||
xhr.responseType = 'arraybuffer';
|
xhr.responseType = 'arraybuffer';
|
||||||
xhr.expected = (document.URL.indexOf('file:') === 0) ? 0 : 200;
|
xhr.expected = document.URL.startsWith('file:') ? 0 : 200;
|
||||||
xhr.send(null);
|
xhr.send(null);
|
||||||
this.data = new Stream(xhr.response);
|
this.data = new Stream(xhr.response);
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* eslint-disable object-shorthand, mozilla/use-includes-instead-of-indexOf */
|
/* eslint-disable object-shorthand */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ function downloadFile(file, url, callback, redirects) {
|
|||||||
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (response.statusCode === 404 && url.indexOf('web.archive.org') < 0) {
|
if (response.statusCode === 404 && !url.includes('web.archive.org')) {
|
||||||
// trying waybackmachine
|
// trying waybackmachine
|
||||||
redirectTo = 'http://web.archive.org/web/' + url;
|
redirectTo = 'http://web.archive.org/web/' + url;
|
||||||
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||||
@ -84,7 +84,7 @@ function downloadFile(file, url, callback, redirects) {
|
|||||||
}).on('error', function (err) {
|
}).on('error', function (err) {
|
||||||
if (!completed) {
|
if (!completed) {
|
||||||
if (typeof err === 'object' && err.errno === 'ENOTFOUND' &&
|
if (typeof err === 'object' && err.errno === 'ENOTFOUND' &&
|
||||||
url.indexOf('web.archive.org') < 0) {
|
!url.includes('web.archive.org')) {
|
||||||
// trying waybackmachine
|
// trying waybackmachine
|
||||||
var redirectTo = 'http://web.archive.org/web/' + url;
|
var redirectTo = 'http://web.archive.org/web/' + url;
|
||||||
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/* eslint-disable mozilla/use-includes-instead-of-indexOf */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
@ -67,7 +65,7 @@ function flatten(stats) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Use only overall results if not grouped by 'stat'
|
// Use only overall results if not grouped by 'stat'
|
||||||
if (options.groupBy.indexOf('stat') < 0) {
|
if (!options.groupBy.includes('stat')) {
|
||||||
rows = rows.filter(function(s) {
|
rows = rows.filter(function(s) {
|
||||||
return s.stat === 'Overall';
|
return s.stat === 'Overall';
|
||||||
});
|
});
|
||||||
|
@ -320,7 +320,7 @@ function checkEq(task, results, browser, masterMode) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var testSnapshot = pageResults[page].snapshot;
|
var testSnapshot = pageResults[page].snapshot;
|
||||||
if (testSnapshot && testSnapshot.indexOf('data:image/png;base64,') === 0) {
|
if (testSnapshot && testSnapshot.startsWith('data:image/png;base64,')) {
|
||||||
testSnapshot = Buffer.from(testSnapshot.substring(22), 'base64');
|
testSnapshot = Buffer.from(testSnapshot.substring(22), 'base64');
|
||||||
} else {
|
} else {
|
||||||
console.error('Valid snapshot was not found.');
|
console.error('Valid snapshot was not found.');
|
||||||
|
@ -162,7 +162,7 @@ describe('ui_utils', function() {
|
|||||||
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
||||||
var blobUrl = createObjectURL(typedArray, 'application/pdf');
|
var blobUrl = createObjectURL(typedArray, 'application/pdf');
|
||||||
// Sanity check to ensure that a "blob:" URL was returned.
|
// Sanity check to ensure that a "blob:" URL was returned.
|
||||||
expect(blobUrl.indexOf('blob:') === 0).toEqual(true);
|
expect(blobUrl.startsWith('blob:')).toEqual(true);
|
||||||
|
|
||||||
expect(getPDFFileNameFromURL(blobUrl + '?file.pdf')).toEqual('file.pdf');
|
expect(getPDFFileNameFromURL(blobUrl + '?file.pdf')).toEqual('file.pdf');
|
||||||
});
|
});
|
||||||
@ -173,7 +173,7 @@ describe('ui_utils', function() {
|
|||||||
var dataUrl = createObjectURL(typedArray, 'application/pdf',
|
var dataUrl = createObjectURL(typedArray, 'application/pdf',
|
||||||
/* forceDataSchema = */ true);
|
/* forceDataSchema = */ true);
|
||||||
// Sanity check to ensure that a "data:" URL was returned.
|
// Sanity check to ensure that a "data:" URL was returned.
|
||||||
expect(dataUrl.indexOf('data:') === 0).toEqual(true);
|
expect(dataUrl.startsWith('data:')).toEqual(true);
|
||||||
|
|
||||||
expect(getPDFFileNameFromURL(dataUrl + '?file1.pdf')).
|
expect(getPDFFileNameFromURL(dataUrl + '?file1.pdf')).
|
||||||
toEqual('document.pdf');
|
toEqual('document.pdf');
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* eslint-disable object-shorthand, mozilla/use-includes-instead-of-indexOf */
|
/* eslint-disable object-shorthand */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ WebBrowser.prototype = {
|
|||||||
args: wmicPrefix.concat(['get', 'CommandLine']),
|
args: wmicPrefix.concat(['get', 'CommandLine']),
|
||||||
};
|
};
|
||||||
isAllKilled = function(exitCode, stdout) {
|
isAllKilled = function(exitCode, stdout) {
|
||||||
return stdout.indexOf(this.uniqStringId) === -1;
|
return !stdout.includes(this.uniqStringId);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
} else {
|
} else {
|
||||||
cmdKillAll = { file: 'pkill', args: ['-f', this.uniqStringId], };
|
cmdKillAll = { file: 'pkill', args: ['-f', this.uniqStringId], };
|
||||||
|
Loading…
Reference in New Issue
Block a user