Skip to content

Commit cc76f3f

Browse files
starkwangtargos
authored andcommittedMar 27, 2019
lib: use Array#includes instead of Array#indexOf
PR-URL: #26732 Refs: #26568 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3ab438a commit cc76f3f

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed
 

‎lib/_http_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function ClientRequest(input, options, cb) {
215215
// https://tools.ietf.org/html/rfc3986#section-3.2.2
216216
var posColon = hostHeader.indexOf(':');
217217
if (posColon !== -1 &&
218-
hostHeader.indexOf(':', posColon + 1) !== -1 &&
218+
hostHeader.includes(':', posColon + 1) &&
219219
hostHeader.charCodeAt(0) !== 91/* '[' */) {
220220
hostHeader = `[${hostHeader}]`;
221221
}

‎lib/_stream_readable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
709709
// also returned false.
710710
// => Check whether `dest` is still a piping destination.
711711
if (((state.pipesCount === 1 && state.pipes === dest) ||
712-
(state.pipesCount > 1 && state.pipes.indexOf(dest) !== -1)) &&
712+
(state.pipesCount > 1 && state.pipes.includes(dest))) &&
713713
!cleanedUp) {
714714
debug('false write response, pause', state.awaitDrain);
715715
state.awaitDrain++;

‎lib/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function getErrMessage(message, fn) {
284284
// Flush unfinished multi byte characters.
285285
decoder.end();
286286
// Always normalize indentation, otherwise the message could look weird.
287-
if (message.indexOf('\n') !== -1) {
287+
if (message.includes('\n')) {
288288
if (EOL === '\r\n') {
289289
message = message.replace(/\r\n/g, '\n');
290290
}

‎lib/child_process.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ exports.fork = function fork(modulePath /* , args, options */) {
103103
// and stderr from the parent if silent isn't set.
104104
options.stdio = options.silent ? stdioStringToArray('pipe') :
105105
stdioStringToArray('inherit');
106-
} else if (options.stdio.indexOf('ipc') === -1) {
106+
} else if (!options.stdio.includes('ipc')) {
107107
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
108108
}
109109

‎lib/internal/cluster/shared_handle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function SharedHandle(key, address, port, addressType, fd, flags) {
2424
}
2525

2626
SharedHandle.prototype.add = function(worker, send) {
27-
assert(this.workers.indexOf(worker) === -1);
27+
assert(!this.workers.includes(worker));
2828
this.workers.push(worker);
2929
send(this.errno, null, this.handle);
3030
};

‎lib/internal/console/constructor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Console.prototype[kWriteToConsole] = function(streamSymbol, string) {
220220
this._stdoutErrorHandler : this._stderrErrorHandler;
221221

222222
if (groupIndent.length !== 0) {
223-
if (string.indexOf('\n') !== -1) {
223+
if (string.includes('\n')) {
224224
string = string.replace(/\n/g, `\n${groupIndent}`);
225225
}
226226
string = groupIndent + string;

‎lib/internal/fs/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ function nullCheck(path, propName, throwError = true) {
191191

192192
// We can only perform meaningful checks on strings and Uint8Arrays.
193193
if (!pathIsString && !pathIsUint8Array ||
194-
pathIsString && path.indexOf('\u0000') === -1 ||
195-
pathIsUint8Array && path.indexOf(0) === -1) {
194+
pathIsString && !path.includes('\u0000') ||
195+
pathIsUint8Array && !path.includes(0)) {
196196
return;
197197
}
198198

‎lib/internal/util/inspect.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ function strEscape(str) {
265265
// instead wrap the text in double quotes. If double quotes exist, check for
266266
// backticks. If they do not exist, use those as fallback instead of the
267267
// double quotes.
268-
if (str.indexOf("'") !== -1) {
268+
if (str.includes("'")) {
269269
// This invalidates the charCode and therefore can not be matched for
270270
// anymore.
271-
if (str.indexOf('"') === -1) {
271+
if (!str.includes('"')) {
272272
singleQuote = -1;
273-
} else if (str.indexOf('`') === -1 && str.indexOf('${') === -1) {
273+
} else if (!str.includes('`') && !str.includes('${')) {
274274
singleQuote = -2;
275275
}
276276
if (singleQuote !== 39) {
@@ -534,7 +534,7 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
534534

535535
// Using an array here is actually better for the average case than using
536536
// a Set. `seen` will only check for the depth and will never grow too large.
537-
if (ctx.seen.indexOf(value) !== -1)
537+
if (ctx.seen.includes(value))
538538
return ctx.stylize('[Circular]', 'special');
539539

540540
return formatRaw(ctx, value, recurseTimes, typedArray);

‎lib/url.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,9 @@ Url.prototype.format = function format() {
581581
host = auth + this.host;
582582
} else if (this.hostname) {
583583
host = auth + (
584-
this.hostname.indexOf(':') === -1 ?
585-
this.hostname :
586-
'[' + this.hostname + ']'
584+
this.hostname.includes(':') ?
585+
'[' + this.hostname + ']' :
586+
this.hostname
587587
);
588588
if (this.port) {
589589
host += ':' + this.port;

0 commit comments

Comments
 (0)