Skip to content

Commit

Permalink
Use String.indexOf() instead of RegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
aweebit committed Aug 8, 2023
1 parent 50d88de commit 7577e65
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class Option {
this.long = optionFlags.longFlag;
this.strictOptionalHelpTerm = null;
if (this.optional) {
const { 0: argument, index } = flags.match(/\[.*\]/);
const indexStart = flags.indexOf('[');
const indexEnd = indexStart + flags.slice(indexStart).indexOf(']') + 1;
const argument = flags.slice(indexStart, indexEnd);
this.strictOptionalHelpTerm = (
flags.slice(0, index) + flags.slice(index + argument.length)
flags.slice(0, indexStart) + flags.slice(indexEnd)
);
if (this.short) {
this.strictOptionalHelpTerm = this.strictOptionalHelpTerm
Expand Down

0 comments on commit 7577e65

Please sign in to comment.