Skip to content

Commit

Permalink
docs: add descriptions of parsing numbers (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkel committed Jan 4, 2021
1 parent 2d70e45 commit acff16d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 13 additions & 5 deletions docs/api.md
Expand Up @@ -73,7 +73,7 @@ value should be a string or an array of strings.

Get the arguments as a plain old object.

Arguments without a corresponding flag show up in the `argv._` array.
Arguments without a corresponding flag show up in the `argv._` array. Note that elements of `argv._` may be [converted to numbers](/docs/tricks.md#numbers) by default.

The script name or node command is available at `argv.$0` similarly to how `$0`
works in bash or perl.
Expand Down Expand Up @@ -1335,13 +1335,21 @@ for details of this object
------------
`parserConfiguration()` allows you to configure advanced yargs features.

`obj` accepts the following configuration options:
See [yargs-parser's configuration](https://github.com/yargs/yargs-parser#configuration) for valid configuration options. Yargs also supports the following options:

* `sort-commands` when set to `true` (boolean) will sort the commands added, the default is `false`.

For additional configuration options, see [yargs-parser's configuration](https://github.com/yargs/yargs-parser#configuration).

_Note: configuration should be top level keys on the `obj` passed to `parserConfiguration`, not populated under the configuration key, as in `yargs-parser`._
```js
yargs.parserConfiguration({
"short-option-groups": true,
"camel-case-expansion": true,
"dot-notation": true,
"parse-numbers": true,
"parse-positional-numbers": true,
"boolean-negation": true,
"deep-merge-config": false
})
```

<a name="pkg-conf"></a>
.pkgConf(key, [cwd])
Expand Down
3 changes: 3 additions & 0 deletions docs/tricks.md
Expand Up @@ -31,6 +31,9 @@ one. This way you can just `net.createConnection(argv.port)` and you can add
numbers out of `argv` with `+` without having that mean concatenation,
which is super frustrating.

You can change this behavior by calling [`parserConfiguration()`](/docs/api.md#parserConfiguration)
or by explicitly specifying [`string`](/docs/api.md/#string) for your flags.

<a name="arrays"></a>
Arrays
----------
Expand Down

0 comments on commit acff16d

Please sign in to comment.