From 17aa56a7d5c8d37dae2848c7526e4ad6a68dfe21 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sat, 25 Nov 2023 19:02:50 +1300 Subject: [PATCH 1/2] [readme]: document string positionals --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 74da323..933e300 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,8 @@ Return an argument object `argv` populated with the array arguments from `args`. them. Numeric-looking arguments will be returned as numbers unless `opts.string` or -`opts.boolean` is set for that argument name. +`opts.boolean` contains that argument name. To disable numeric conversion +for non-option arguments, add `'_'` to `opts.string`. Any arguments after `'--'` will not be parsed and will end up in `argv._`. From 5c1864e0a9ea9727d33effe96d94eea46e777953 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sat, 25 Nov 2023 19:47:32 +1300 Subject: [PATCH 2/2] [Tests]: extend string '_' test to include numeric --- test/parse.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/parse.js b/test/parse.js index 65d9d90..25456d8 100644 --- a/test/parse.js +++ b/test/parse.js @@ -93,12 +93,14 @@ test('strings', function (t) { }); test('stringArgs', function (t) { - var s = parse([' ', ' '], { string: '_' })._; - t.same(s.length, 2); + var s = parse([' ', ' ', '3'], { string: '_' })._; + t.same(s.length, 3); t.same(typeof s[0], 'string'); t.same(s[0], ' '); t.same(typeof s[1], 'string'); t.same(s[1], ' '); + t.same(typeof s[2], 'string'); + t.same(s[2], '3'); t.end(); });