lib: use Array#includes instead of Array#indexOf
PR-URL: https://github.com/nodejs/node/pull/26732 Refs: https://github.com/nodejs/node/issues/26568 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
1935625df4
commit
c8d3a73c8b
@ -220,7 +220,7 @@ function ClientRequest(input, options, cb) {
|
|||||||
// https://tools.ietf.org/html/rfc3986#section-3.2.2
|
// https://tools.ietf.org/html/rfc3986#section-3.2.2
|
||||||
var posColon = hostHeader.indexOf(':');
|
var posColon = hostHeader.indexOf(':');
|
||||||
if (posColon !== -1 &&
|
if (posColon !== -1 &&
|
||||||
hostHeader.indexOf(':', posColon + 1) !== -1 &&
|
hostHeader.includes(':', posColon + 1) &&
|
||||||
hostHeader.charCodeAt(0) !== 91/* '[' */) {
|
hostHeader.charCodeAt(0) !== 91/* '[' */) {
|
||||||
hostHeader = `[${hostHeader}]`;
|
hostHeader = `[${hostHeader}]`;
|
||||||
}
|
}
|
||||||
|
@ -713,7 +713,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
|
|||||||
// also returned false.
|
// also returned false.
|
||||||
// => Check whether `dest` is still a piping destination.
|
// => Check whether `dest` is still a piping destination.
|
||||||
if (((state.pipesCount === 1 && state.pipes === dest) ||
|
if (((state.pipesCount === 1 && state.pipes === dest) ||
|
||||||
(state.pipesCount > 1 && state.pipes.indexOf(dest) !== -1)) &&
|
(state.pipesCount > 1 && state.pipes.includes(dest))) &&
|
||||||
!cleanedUp) {
|
!cleanedUp) {
|
||||||
debug('false write response, pause', state.awaitDrain);
|
debug('false write response, pause', state.awaitDrain);
|
||||||
state.awaitDrain++;
|
state.awaitDrain++;
|
||||||
|
@ -284,7 +284,7 @@ function getErrMessage(message, fn) {
|
|||||||
// Flush unfinished multi byte characters.
|
// Flush unfinished multi byte characters.
|
||||||
decoder.end();
|
decoder.end();
|
||||||
// Always normalize indentation, otherwise the message could look weird.
|
// Always normalize indentation, otherwise the message could look weird.
|
||||||
if (message.indexOf('\n') !== -1) {
|
if (message.includes('\n')) {
|
||||||
if (EOL === '\r\n') {
|
if (EOL === '\r\n') {
|
||||||
message = message.replace(/\r\n/g, '\n');
|
message = message.replace(/\r\n/g, '\n');
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ exports.fork = function fork(modulePath /* , args, options */) {
|
|||||||
// and stderr from the parent if silent isn't set.
|
// and stderr from the parent if silent isn't set.
|
||||||
options.stdio = options.silent ? stdioStringToArray('pipe') :
|
options.stdio = options.silent ? stdioStringToArray('pipe') :
|
||||||
stdioStringToArray('inherit');
|
stdioStringToArray('inherit');
|
||||||
} else if (options.stdio.indexOf('ipc') === -1) {
|
} else if (!options.stdio.includes('ipc')) {
|
||||||
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
|
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ function SharedHandle(key, address, port, addressType, fd, flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SharedHandle.prototype.add = function(worker, send) {
|
SharedHandle.prototype.add = function(worker, send) {
|
||||||
assert(this.workers.indexOf(worker) === -1);
|
assert(!this.workers.includes(worker));
|
||||||
this.workers.push(worker);
|
this.workers.push(worker);
|
||||||
send(this.errno, null, this.handle);
|
send(this.errno, null, this.handle);
|
||||||
};
|
};
|
||||||
|
@ -220,7 +220,7 @@ Console.prototype[kWriteToConsole] = function(streamSymbol, string) {
|
|||||||
this._stdoutErrorHandler : this._stderrErrorHandler;
|
this._stdoutErrorHandler : this._stderrErrorHandler;
|
||||||
|
|
||||||
if (groupIndent.length !== 0) {
|
if (groupIndent.length !== 0) {
|
||||||
if (string.indexOf('\n') !== -1) {
|
if (string.includes('\n')) {
|
||||||
string = string.replace(/\n/g, `\n${groupIndent}`);
|
string = string.replace(/\n/g, `\n${groupIndent}`);
|
||||||
}
|
}
|
||||||
string = groupIndent + string;
|
string = groupIndent + string;
|
||||||
|
@ -191,8 +191,8 @@ function nullCheck(path, propName, throwError = true) {
|
|||||||
|
|
||||||
// We can only perform meaningful checks on strings and Uint8Arrays.
|
// We can only perform meaningful checks on strings and Uint8Arrays.
|
||||||
if (!pathIsString && !pathIsUint8Array ||
|
if (!pathIsString && !pathIsUint8Array ||
|
||||||
pathIsString && path.indexOf('\u0000') === -1 ||
|
pathIsString && !path.includes('\u0000') ||
|
||||||
pathIsUint8Array && path.indexOf(0) === -1) {
|
pathIsUint8Array && !path.includes(0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,12 +288,12 @@ function strEscape(str) {
|
|||||||
// instead wrap the text in double quotes. If double quotes exist, check for
|
// instead wrap the text in double quotes. If double quotes exist, check for
|
||||||
// backticks. If they do not exist, use those as fallback instead of the
|
// backticks. If they do not exist, use those as fallback instead of the
|
||||||
// double quotes.
|
// double quotes.
|
||||||
if (str.indexOf("'") !== -1) {
|
if (str.includes("'")) {
|
||||||
// This invalidates the charCode and therefore can not be matched for
|
// This invalidates the charCode and therefore can not be matched for
|
||||||
// anymore.
|
// anymore.
|
||||||
if (str.indexOf('"') === -1) {
|
if (!str.includes('"')) {
|
||||||
singleQuote = -1;
|
singleQuote = -1;
|
||||||
} else if (str.indexOf('`') === -1 && str.indexOf('${') === -1) {
|
} else if (!str.includes('`') && !str.includes('${')) {
|
||||||
singleQuote = -2;
|
singleQuote = -2;
|
||||||
}
|
}
|
||||||
if (singleQuote !== 39) {
|
if (singleQuote !== 39) {
|
||||||
@ -557,7 +557,7 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
|
|||||||
|
|
||||||
// Using an array here is actually better for the average case than using
|
// Using an array here is actually better for the average case than using
|
||||||
// a Set. `seen` will only check for the depth and will never grow too large.
|
// a Set. `seen` will only check for the depth and will never grow too large.
|
||||||
if (ctx.seen.indexOf(value) !== -1)
|
if (ctx.seen.includes(value))
|
||||||
return ctx.stylize('[Circular]', 'special');
|
return ctx.stylize('[Circular]', 'special');
|
||||||
|
|
||||||
return formatRaw(ctx, value, recurseTimes, typedArray);
|
return formatRaw(ctx, value, recurseTimes, typedArray);
|
||||||
|
@ -581,9 +581,9 @@ Url.prototype.format = function format() {
|
|||||||
host = auth + this.host;
|
host = auth + this.host;
|
||||||
} else if (this.hostname) {
|
} else if (this.hostname) {
|
||||||
host = auth + (
|
host = auth + (
|
||||||
this.hostname.indexOf(':') === -1 ?
|
this.hostname.includes(':') ?
|
||||||
this.hostname :
|
'[' + this.hostname + ']' :
|
||||||
'[' + this.hostname + ']'
|
this.hostname
|
||||||
);
|
);
|
||||||
if (this.port) {
|
if (this.port) {
|
||||||
host += ':' + this.port;
|
host += ':' + this.port;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user