Skip to content

Commit

Permalink
Replace indexOf with includes (#1264)
Browse files Browse the repository at this point in the history
* Replace indexOf with includes

Changed the relevant if statement to an early return.

* Modify to "StartsWith" to correspond to "indexOf === 0"
  • Loading branch information
abetomo committed May 14, 2020
1 parent 790553d commit 168ff5b
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions index.js
Expand Up @@ -20,10 +20,10 @@ class Option {

constructor(flags, description) {
this.flags = flags;
this.required = flags.indexOf('<') >= 0; // A value must be supplied when the option is specified.
this.optional = flags.indexOf('[') >= 0; // A value is optional when the option is specified.
this.required = flags.includes('<'); // A value must be supplied when the option is specified.
this.optional = flags.includes('['); // A value is optional when the option is specified.
this.mandatory = false; // The option must have a value after parsing, which usually means it must be specified on command line.
this.negate = flags.indexOf('-no-') !== -1;
this.negate = flags.includes('-no-');
const flagParts = flags.split(/[ ,|]+/);
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1])) this.short = flagParts.shift();
this.long = flagParts.shift();
Expand Down Expand Up @@ -1722,35 +1722,35 @@ function incrementNodeInspectorPort(args) {
// --inspect-brk[=[host:]port]
// --inspect-port=[host:]port
return args.map((arg) => {
let result = arg;
if (arg.indexOf('--inspect') === 0) {
let debugOption;
let debugHost = '127.0.0.1';
let debugPort = '9229';
let match;
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
// e.g. --inspect
debugOption = match[1];
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
debugOption = match[1];
if (/^\d+$/.test(match[3])) {
// e.g. --inspect=1234
debugPort = match[3];
} else {
// e.g. --inspect=localhost
debugHost = match[3];
}
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
// e.g. --inspect=localhost:1234
debugOption = match[1];
if (!arg.startsWith('--inspect')) {
return arg;
}
let debugOption;
let debugHost = '127.0.0.1';
let debugPort = '9229';
let match;
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
// e.g. --inspect
debugOption = match[1];
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
debugOption = match[1];
if (/^\d+$/.test(match[3])) {
// e.g. --inspect=1234
debugPort = match[3];
} else {
// e.g. --inspect=localhost
debugHost = match[3];
debugPort = match[4];
}
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
// e.g. --inspect=localhost:1234
debugOption = match[1];
debugHost = match[3];
debugPort = match[4];
}

if (debugOption && debugPort !== '0') {
result = `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
}
if (debugOption && debugPort !== '0') {
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
}
return result;
return arg;
});
}

0 comments on commit 168ff5b

Please sign in to comment.