Skip to content

Commit 7577e65

Browse files
committed
Use String.indexOf() instead of RegExp
1 parent 50d88de commit 7577e65

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/option.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ class Option {
2424
this.long = optionFlags.longFlag;
2525
this.strictOptionalHelpTerm = null;
2626
if (this.optional) {
27-
const { 0: argument, index } = flags.match(/\[.*\]/);
27+
const indexStart = flags.indexOf('[');
28+
const indexEnd = indexStart + flags.slice(indexStart).indexOf(']') + 1;
29+
const argument = flags.slice(indexStart, indexEnd);
2830
this.strictOptionalHelpTerm = (
29-
flags.slice(0, index) + flags.slice(index + argument.length)
31+
flags.slice(0, indexStart) + flags.slice(indexEnd)
3032
);
3133
if (this.short) {
3234
this.strictOptionalHelpTerm = this.strictOptionalHelpTerm

0 commit comments

Comments
 (0)