mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +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
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable object-shorthand, mozilla/use-includes-instead-of-indexOf */
|
||||
/* eslint-disable object-shorthand */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -52,7 +52,7 @@ function downloadFile(file, url, callback, redirects) {
|
|||
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||
return;
|
||||
}
|
||||
if (response.statusCode === 404 && url.indexOf('web.archive.org') < 0) {
|
||||
if (response.statusCode === 404 && !url.includes('web.archive.org')) {
|
||||
// trying waybackmachine
|
||||
redirectTo = 'http://web.archive.org/web/' + url;
|
||||
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||
|
@ -84,7 +84,7 @@ function downloadFile(file, url, callback, redirects) {
|
|||
}).on('error', function (err) {
|
||||
if (!completed) {
|
||||
if (typeof err === 'object' && err.errno === 'ENOTFOUND' &&
|
||||
url.indexOf('web.archive.org') < 0) {
|
||||
!url.includes('web.archive.org')) {
|
||||
// trying waybackmachine
|
||||
var redirectTo = 'http://web.archive.org/web/' + url;
|
||||
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/* eslint-disable mozilla/use-includes-instead-of-indexOf */
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
|
@ -67,7 +65,7 @@ function flatten(stats) {
|
|||
});
|
||||
});
|
||||
// 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) {
|
||||
return s.stat === 'Overall';
|
||||
});
|
||||
|
|
|
@ -320,7 +320,7 @@ function checkEq(task, results, browser, masterMode) {
|
|||
continue;
|
||||
}
|
||||
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');
|
||||
} else {
|
||||
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 blobUrl = createObjectURL(typedArray, 'application/pdf');
|
||||
// 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');
|
||||
});
|
||||
|
@ -173,7 +173,7 @@ describe('ui_utils', function() {
|
|||
var dataUrl = createObjectURL(typedArray, 'application/pdf',
|
||||
/* forceDataSchema = */ true);
|
||||
// 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')).
|
||||
toEqual('document.pdf');
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable object-shorthand, mozilla/use-includes-instead-of-indexOf */
|
||||
/* eslint-disable object-shorthand */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -157,7 +157,7 @@ WebBrowser.prototype = {
|
|||
args: wmicPrefix.concat(['get', 'CommandLine']),
|
||||
};
|
||||
isAllKilled = function(exitCode, stdout) {
|
||||
return stdout.indexOf(this.uniqStringId) === -1;
|
||||
return !stdout.includes(this.uniqStringId);
|
||||
}.bind(this);
|
||||
} else {
|
||||
cmdKillAll = { file: 'pkill', args: ['-f', this.uniqStringId], };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue