Comparing version 2.2.1 to 2.2.2
@@ -1,13 +0,1 @@ | ||
interface ParsedOptions { | ||
_: string[] | ||
[key: string]: any | ||
} | ||
interface Options { | ||
alias?: { [key: string]: string | string[] } | ||
boolean?: string[] | ||
default?: { [key: string]: any } | ||
unknown?: (optionName: string) => boolean | ||
} | ||
/** | ||
@@ -18,4 +6,21 @@ * @param argv Arguments to parse. | ||
*/ | ||
declare function getopts(argv: string[], options?: Options): ParsedOptions | ||
declare function getopts( | ||
argv: string[], | ||
options?: getopts.Options | ||
): getopts.ParsedOptions | ||
export = getopts | ||
declare namespace getopts { | ||
export interface ParsedOptions { | ||
_: string[] | ||
[key: string]: any | ||
} | ||
export interface Options { | ||
alias?: { [key: string]: string | string[] } | ||
boolean?: string[] | ||
default?: { [key: string]: any } | ||
unknown?: (optionName: string) => boolean | ||
} | ||
} |
{ | ||
"name": "getopts", | ||
"description": "Node.js CLI options parser.", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"main": "index.js", | ||
@@ -27,4 +27,4 @@ "types": "getopts.d.ts", | ||
"testmatrix": "^0.1.2", | ||
"typescript": "^3.0.1" | ||
"typescript": "^3.1.3" | ||
} | ||
} |
@@ -19,6 +19,4 @@ # Getopts | ||
Use getopts to parse the [command-line arguments](https://en.wikipedia.org/wiki/Command-line_interface#Arguments) passed to your program. | ||
Use the [`getopts`](#getoptsargv-opts) function to parse the [command-line arguments](https://en.wikipedia.org/wiki/Command-line_interface#Arguments) passed to your program. | ||
You can find the arguments in the [`process.argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) array. The first element will be the path to the node executable, followed by the path to the file being executed. The remaining elements will be the command line arguments. We don't need the first two elements, so we'll extract everything after. | ||
<pre> | ||
@@ -28,2 +26,4 @@ $ <a href="./example/demo">example/demo</a> --turbo -xw10 -- alpha beta | ||
You can find the command-line arguments in the [`process.argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv) array. The first element will be the path to the node executable, followed by the path to the file being executed. We don't need the first two elements, so we'll extract everything after and pass it to `getopts`. | ||
```js | ||
@@ -40,4 +40,6 @@ const getopts = require("getopts") | ||
Getopts takes an array of arguments (and optional options object) and returns an object that maps argument names to values. This object can be used to look up the value of an option by its name. The underscore `_` is reserved for [operands](#operands). Operands include standalone arguments (non-options), the single dash `-` and every argument after a double-dash `--`. | ||
Getopts takes an array of arguments (and optional options object) and returns an object that maps argument names to values. Use this object to look up the value of an option by its name. | ||
The underscore `_` is reserved for [operands](#operands). Operands include standalone arguments (non-options), the single dash `-` and every argument after a double-dash `--`. | ||
```js | ||
@@ -72,3 +74,3 @@ { | ||
- Only the last character in a cluster of options can be parsed as boolean, string or number depending on the argument that follows it. Any characters preceding it will be `true`. You can use [opts.string](#optstring) to indicate if one of these options should be parsed as a string instead. | ||
- Only the last character in a cluster of options can be parsed as boolean, string or number depending on the argument that follows it. Any characters preceding it will be `true`. You can use [`opts.string`](#optstring) to indicate if one of these options should be parsed as a string instead. | ||
@@ -81,3 +83,3 @@ ```js | ||
- The argument immediately following a short or long option which is not an option itself will be used as a value. You can use [opts.boolean](#optsboolean) to indicate the option should be parsed as boolean and treat the value as an operand. | ||
- The argument immediately following a short or long option which is not an option itself will be used as a value. You can use [`opts.boolean`](#optsboolean) to indicate the option should be parsed as boolean and treat the value as an operand. | ||
@@ -153,3 +155,3 @@ ```js | ||
* The string _false_ is always cast to boolean. | ||
* The string `"false"` is always cast to boolean. | ||
@@ -229,3 +231,3 @@ ```js | ||
A function to be run for every unknown option. Return `false` to dismiss the option. Unknown options are those that appear in the arguments array but are not present in opts.string, opts.boolean, opts.default or opts.alias. | ||
A function to be run for every unknown option. Return `false` to dismiss the option. Unknown options are those that appear in the arguments array but are not present in `opts.string`, `opts.boolean`, `opts.default` or `opts.alias`. | ||
@@ -247,6 +249,6 @@ ```js | ||
<pre> | ||
mri × 378,898 ops/sec | ||
yargs × 32,993 ops/sec | ||
<b>getopts × 1,290,267 ops/sec</b> | ||
minimist × 289,048 ops/sec | ||
mri × 363,444 ops/sec | ||
yargs × 31,734 ops/sec | ||
minimist × 270,504 ops/sec | ||
getopts × 1,252,164 ops/sec | ||
</pre> | ||
@@ -256,2 +258,2 @@ | ||
Getopts is MIT licensed. See [LICENSE](LICENSE.md). | ||
Getopts is MIT licensed. See the [LICENSE](LICENSE.md) for details. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14716
201
251