diff --git a/src/_parser.ts b/src/_parser.ts index 2a53a0f..ea06b99 100644 --- a/src/_parser.ts +++ b/src/_parser.ts @@ -24,13 +24,13 @@ function toArr(any: any) { function toVal(out, key, val, opts) { let x; const old = out[key]; - const nxt = ~opts.string.indexOf(key) + const nxt = opts.string.includes(key) ? val == undefined || val === true - ? "" + ? undefined : String(val) : typeof val === "boolean" ? val - : ~opts.boolean.indexOf(key) + : opts.boolean.includes(key) ? val === "false" ? false : val === "true" || @@ -121,7 +121,7 @@ export function parseRawArgs( out._.push(arg); } else if (arg.substring(j, j + 3) === "no-") { name = arg.slice(Math.max(0, j + 3)); - if (strict && !~keys.indexOf(name)) { + if (strict && !keys.includes(name)) { return opts.unknown(arg); } out[name] = false; @@ -142,7 +142,7 @@ export function parseRawArgs( for (idx = 0; idx < arr.length; idx++) { name = arr[idx]; - if (strict && !~keys.indexOf(name)) { + if (strict && !keys.includes(name)) { return opts.unknown("-".repeat(j) + name); } toVal(out, name, idx + 1 < arr.length || val, opts); diff --git a/src/args.ts b/src/args.ts index 3d86757..2c4586f 100644 --- a/src/args.ts +++ b/src/args.ts @@ -10,7 +10,6 @@ export function parseArgs( const parseOptions = { boolean: [] as string[], string: [] as string[], - number: [] as string[], enum: [] as (number | string)[], mixed: [] as string[], alias: {} as Record, diff --git a/test/parser.test.ts b/test/parser.test.ts index ae70c6e..6464dd3 100644 --- a/test/parser.test.ts +++ b/test/parser.test.ts @@ -88,4 +88,18 @@ describe("parseRawArgs", () => { _: [], }); }); + + it("handles arguments with no values", () => { + const args = ["--name", "--specified", "--any"]; + const opts = { string: ["name"], boolean: ["specified"] }; + const result = parseRawArgs(args, opts); + + expect("name" in result).toBeTruthy(); + expect("specified" in result).toBeTruthy(); + expect("any" in result).toBeTruthy(); + + expect(result.name).toBeUndefined(); + expect(result.specified).toBeTruthy(); + expect(result.any).toBeTruthy(); + }); });