Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "getopts", | ||
"description": "Node.js CLI options parser.", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"main": "index.js", | ||
@@ -23,5 +23,5 @@ "license": "MIT", | ||
"devDependencies": { | ||
"nyc": "^11.4.1", | ||
"tape": "^4.8.0" | ||
"nyc": "^11.6.0", | ||
"tape": "^4.9.0" | ||
} | ||
} |
# Getopts | ||
[![Travis CI](https://img.shields.io/travis/jorgebucaran/getopts/master.svg)](https://travis-ci.org/jorgebucaran/getopts) | ||
@@ -6,12 +7,8 @@ [![Codecov](https://img.shields.io/codecov/c/github/jorgebucaran/getopts/master.svg)](https://codecov.io/gh/jorgebucaran/getopts) | ||
Getopts is a Node.js CLI options parser. | ||
Getopts is a Node.js CLI options parser. It's designed according to the [Utility Conventions](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html) so that your programs behave like typical UNIX utilities effortlessly — without sacrificing developer experience. | ||
* **Swift**: Getopts is 10 to 20 times faster than the alternatives. See the [benchmarks](./bench/README.md). | ||
* **Familiar**: Getopts works similarly to other CLI parsers like [mri](https://github.com/lukeed/mri), [yargs](https://github.com/yargs/yargs) and [minimist](https://github.com/substack/minimist). | ||
* **Standard**: Getopts is designed according to the [Utility Syntax Guidelines](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html). | ||
Need for speed? Getopts is optimized for runtime performance and runs 10 to 20 times faster than alternatives according to our [benchmarks](/bench). | ||
## Installation | ||
Using npm or Yarn. | ||
<pre> | ||
@@ -26,10 +23,12 @@ npm i <a href="https://www.npmjs.com/package/getopts">getopts</a> | ||
<pre> | ||
$ <a href="./example/demo">example/demo</a> --super=sonic -jb9000 -- game over | ||
$ <a href="./example/demo">example/demo</a> --super=sonic -xU9000 -- game over | ||
</pre> | ||
```js | ||
const getopts = require("getopts") | ||
const options = getopts(process.argv.slice(2), { | ||
alias: { | ||
s: "super", | ||
b: "blitz" | ||
U: "ultra" | ||
}, | ||
@@ -44,10 +43,10 @@ default: { | ||
``` | ||
```json | ||
{ | ||
_: ["game", "over"], | ||
j: true, | ||
x: true, | ||
s: "sonic", | ||
b: "9000", | ||
U: "9000", | ||
super: "sonic", | ||
blitz: "9000", | ||
ultra: "9000", | ||
turbo: true | ||
@@ -60,2 +59,3 @@ } | ||
### getopts(argv, options) | ||
#### argv | ||
@@ -72,7 +72,7 @@ | ||
```js | ||
getopts(["-b"], { | ||
getopts(["-U"], { | ||
alias: { | ||
b: ["B", "turbo"] | ||
U: ["u", "ultra"] | ||
} | ||
}) //=> { _:[], b:true, B:true, turbo:true } | ||
}) //=> { _:[], u:true, U:true, ultra:true } | ||
``` | ||
@@ -82,8 +82,8 @@ | ||
An array of options that should be parsed as booleans. | ||
An array of options that should be parsed as booleans. In the example, by indicating <samp>U</samp> to be a boolean option, <samp>1</samp> is parsed as an operand. | ||
```js | ||
getopts(["-b", 1], { | ||
boolean: ["b"] | ||
}) //=> { _:[1], b:true } | ||
getopts(["-U", 1], { | ||
boolean: ["U"] | ||
}) //=> { _:[1], U:true } | ||
``` | ||
@@ -96,7 +96,7 @@ | ||
```js | ||
getopts(["-b"], { | ||
getopts(["-U"], { | ||
default: { | ||
turbo: true | ||
} | ||
}) //=> { _:[], b:true, turbo:true } | ||
}) //=> { _:[], U:true, turbo:true } | ||
``` | ||
@@ -110,3 +110,3 @@ | ||
getopts(["-abc"], { | ||
unknown: option => option === "a" | ||
unknown: option => "a" === option | ||
}) // => { _:[], a:true } | ||
@@ -113,0 +113,0 @@ ``` |
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
8098