{"name":"getopts","description":"High performance Node.js CLI options parser.","version":"2.2.3","main":"index.js","types":"getopts.d.ts","license":"MIT","repository":{"type":"git","url":"git+https://github.com/jorgebucaran/getopts.git"},"author":{"name":"Jorge Bucaran"},"keywords":["getopts","cli","argv","cli-parser"],"scripts":{"test":"nyc -r lcov testmatrix test/*.test.js && nyc report && tsc -p test/ts","release":"npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push origin master && git push --tags && npm publish"},"devDependencies":{"nyc":"^12.0.2","testmatrix":"^0.1.2","typescript":"^3.1.3"},"gitHead":"c0fde8bb9c602dcef3363fdcb8b6efb2dd3b7da0","bugs":{"url":"https://github.com/jorgebucaran/getopts/issues"},"homepage":"https://github.com/jorgebucaran/getopts#readme","_id":"getopts@2.2.3","_npmVersion":"5.0.1","_nodeVersion":"7.2.0","_npmUser":{"name":"jorgebucaran","email":"mail@jorgebucaran.com"},"dist":{"integrity":"sha512-viEcb8TpgeG05+Nqo5EzZ8QR0hxdyrYDp6ZSTZqe2M/h53Bk036NmqG38Vhf5RGirC/Of9Xql+v66B2gp256SQ==","shasum":"11d229775e2ec2067ed8be6fcc39d9b4bf39cf7d","tarball":"http://registry-npm.ywwl.com/getopts/download/getopts-2.2.3.tgz","fileCount":5,"unpackedSize":15816,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb3GI/CRA9TVsSAnZWagAAEMYP/1S3bk42Bf8D1zuYyJ2/\n2240O1flq2WxOE+CdPay2HOjmGmvxF9OBOgJPJo1U8vkkCY800/AnlIfQLDH\nbN1C+NGIWwsnQqTglePEL4OrOIHBS0xP12SOswRBS8LR38lPHCdTybDqRGWR\nefge9OEtYIFxS6SkPj5yrWVxGh53brIRmMwFKD8NiBCJknZGinvRZkHG6eX0\nFm2/v5CDWwcrhVpgtR4D7JZnlaMXTqJsRC9oLJJymDEm6nFAapCDceC1lTD1\nV40O1wFy5vguTc+nYZTEY8dkjtwiYRUBqXp6q7lqMjmmUICM2JY02gM/Vlev\neBH9TrCBt/SiGRmoqPsIKBQF9XULkLH/qViy1nQWevHyhRCaulpgb26oGhy3\nhuozVWlX91KtHh3HrKRE3sCVK7urVfemfCyrvEq8v4HbrET90tpw54hw18Wq\n8YMlUvIahLaRLEeQax9HH6zoQT9C9kcIBNAsYmIN8yp0//Bpykxx3V9loPTV\nHa0yGKB2lcbBpTL1cGYT+Co9zZHLcU/fMBP9NNxgRhx+kb77mqpTfoQGGmim\ndBLbXR5J39QS8Nw1lhqefMtkDfWbXkopFWRANL2NYaj+1oUsp02MolazWGyF\nAVHyehTcb3RT66tuhDDpui22NI2Z0xp0rrjVsr1sjc7QOA26umm1B563UBy+\nE7W5\r\n=sP2Z\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGY4ahOHPWrjTWihYa4w+WS0PZXJfod7xpm2XmY2N19JAiEA6fWLSTUhbD/fAleVcmEH6cXgmKPrr5rvzZx57h+Eh+I="}],"size":5690,"noattachment":false,"key":"/getopts/-/getopts-2.2.3.tgz"},"maintainers":[{"email":"mail@jorgebucaran.com","name":"jorgebucaran"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/getopts_2.2.3_1541169726579_0.31453730383087386"},"_hasShrinkwrap":false,"readme":"# Getopts\n\n> Parse CLI arguments.\n\n- Lightweight drop-in replacement for `minimist` and clones.\n- Small (180 LOC), focused, no dependencies.\n- Up to [6x faster](#benchmarks) than alternatives!\n\nBreak up command-line arguments into key-value pairs for easy look-up and retrieval. Built upon [utility conventions](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02) that have been used for decades, Getopts sane defaults help you write CLI tools that look and feel like the real deal.\n\n```console\n$ example --type=module -o main.js *.{js,json}\n```\n\n```js\nimport getopts from \"getopts\"\n\nconst options = getopts(process.argv.slice(2), {\n  alias: {\n    output: [\"o\", \"f\"],\n    type: \"t\",\n  },\n})\n```\n\nThe result is an object populated with all the parsed arguments.\n\n```js\n{\n  _: [\"index.js\", \"package.json\"],\n  output: \"main.js\",\n  type: \"module\",\n  o: \"main.js\",\n  f: \"main.js\",\n  t: \"module\",\n}\n```\n\n## Installation\n\n```console\nnpm install getopts\n```\n\n## Parsing rules\n\n### Short options\n\nA short option consists of a `-` followed by a single alphabetic character. Multiple options can be grouped together without spaces. Short options are boolean by default unless followed by an [operand](#operand) (non-option) or if adjacent to any non-alphabetic characters:\n\n```js\ngetopts([\"-ab\", \"-c\"]) //=> { _: [], a:true, b:true, c:true }\n```\n\n```js\ngetopts([\"-a\", \"alpha\"]) //=> { _: [], a:\"alpha\" }\n```\n\n```js\ngetopts([\"-abc1\"]) //=> { _: [], a:true, b:true, c:1 }\n```\n\nUse [`opts.string`](#optsstring) to parse an option as a string regardless.\n\n```js\ngetopts([\"-kF12\"], {\n  string: [\"k\"],\n}) //=> { _: [], k:\"F12\" }\n```\n\nThe first operand following an option will be used as its value. Use [`opts.boolean`](#optsboolean) to specify that an option should be parsed as a boolean regardless, causing the following argument to be treated as an operand instead.\n\n```js\ngetopts([\"-a\", \"alpha\"], {\n  boolean: [\"a\"],\n}) //=> { _: [\"alpha\"], a:true }\n```\n\nAny character listed in the ASCII table can be used as a short option if it's the first character after the dash.\n\n```js\ngetopts([\"-9\", \"-#10\", \"-%0.01\"]) //=> { _:[], 9:true, #:10, %:0.01 }\n```\n\n### Long options\n\nA long option consists of a `--` followed by a name and a value separated by an `=`. Long options without a value are boolean by default.\n\n```js\ngetopts([\"--turbo\", \"--warp=10\"]) //=> { _: [], turbo:true, warp:10 }\n```\n\n```js\ngetopts([\"--warp=e=mc^2\"]) //=> { _: [], warp:\"e=mc^2\" }\n```\n\n```js\ngetopts([\"--@\", \"alpha\"]) //=> { _: [], @:\"alpha\" }\n```\n\nNegated options start with `--no-` and are always `false`.\n\n```js\ngetopts([\"--no-turbo\"]) //=> { _: [], turbo:false }\n```\n\n### Operands\n\nEvery non-option argument is an operand. Operands are saved to the `result._` operands array.\n\n```js\ngetopts([\"alpha\", \"-w9\", \"bravo\"]) //=> { _: [\"alpha\", \"bravo\"], w:9 }\n```\n\n```js\ngetopts([\"--code=alpha\", \"bravo\"]) //=> { _: [\"bravo\"], code:\"alpha\" }\n```\n\nEverything after a standalone `--` is an operand.\n\n```js\ngetopts([\"--alpha\", \"--\", \"--bravo\", \"--turbo\"]) //=> { _:[\"--bravo\", \"--turbo\"], alpha:true }\n```\n\nA single `-` is also treated as an operand.\n\n```js\ngetopts([\"--turbo\", \"-\"]) //=> { _:[\"-\"], turbo:true }\n```\n\n### Other\n\nOptions specified as boolean or string will be added to the result object as `false` or `\"\"` (even if missing from the arguments array).\n\n```js\ngetopts([], {\n  string: [\"a\"],\n  boolean: [\"b\"],\n}) //=> { _:[], a:\"\", b:false }\n```\n\nRepeated options are stored as arrays with every value in order of appearance.\n\n```js\ngetopts([\"-x?alpha=bravo\", \"-x3.14\", \"-x\"] //=> { _:[], a:[\"?alpha=bravo\", 3.14, true] }\n```\n\nA value may contain newlines or other control characters.\n\n```js\ngetopts([\"--text=top\\n\\tbottom\"]) //=> { _:[], text:\"top\\n\\tbottom\" }\n```\n\n`=\"false\"` is converted to boolean by default.\n\n```js\ngetopts([\"--turbo=false\"]) //=> { _:[], turbo:false }\n```\n\n## API\n\n### `getopts(argv, opts)`\n\nParse command-line arguments. Returns an object mapping argument names to their values.\n\n### `argv[]`\n\nAn array of arguments, usually [`process.argv`](https://nodejs.org/docs/latest/api/process.html#process_process_argv).\n\n### `opts.alias`\n\nAn object of option aliases. An alias can be a string or an array of strings. Aliases let you declare substitute names for an option, e.g., the short (abbreviated) and long (canonical) variations.\n\n```js\ngetopts([\"-t\"], {\n  alias: {\n    turbo: [\"t\", \"T\"],\n  },\n}) //=> { _:[], t:true, T:true, turbo:true }\n```\n\n### `opts.boolean`\n\nAn array of options to parse as boolean. In the example below, `t` is parsed as a boolean, causing the following argument to be treated as an operand.\n\n```js\ngetopts([\"-t\", \"alpha\"], {\n  boolean: [\"t\"],\n}) //=> { _:[\"alpha\"], t:true }\n```\n\n### `opts.string`\n\nAn array of flags to parse as strings. In the example below, `t` is parsed as a string, causing all adjacent characters to be treated as a single value and not as individual options.\n\n```js\ngetopts([\"-atabc\"], {\n  string: [\"t\"],\n}) //=> { _:[], a:true, t:\"abc\" }\n```\n\n### `opts.default`\n\nAn object of default values for options not present in the arguments array.\n\n```js\ngetopts([\"--warp=10\"], {\n  default: {\n    warp: 15,\n    turbo: true,\n  },\n}) //=> { _:[], warp:10, turbo:true }\n```\n\n### `opts.unknown()`\n\nWe call this function for each unknown option. Return `false` to discard the option. Unknown options are those that appear in the arguments array, but are not in `opts.string`, `opts.boolean`, `opts.default`, or `opts.alias`.\n\n```js\ngetopts([\"-abc\"], {\n  unknown: (option) => \"a\" === option,\n}) //=> { _:[], a:true }\n```\n\n### `opts.stopEarly`\n\nA boolean property. If `true`, the operands array `_` will be populated with all the arguments after the first operand.\n\n```js\ngetopts([\"-w9\", \"alpha\", \"--turbo\", \"bravo\"], {\n  stopEarly: true,\n}) //=> { _:[\"alpha\", \"--turbo\", \"bravo\"], w:9 }\n```\n\nThis property is useful when implementing sub-commands in a CLI.\n\n```js\nimport getopts from \"getopts\"\nimport { install, update, uninstall } from \"./commands.js\"\n\nconst options = getopts(process.argv.slice(2), {\n  stopEarly: true,\n})\n\nconst [command, subargv] = options._\n\nif (command === \"install\") {\n  install(subargv)\n} else if (command === \"update\") {\n  update(subargv)\n} else if (command === \"uninstall\") {\n  uninstall(subargv)\n}\n```\n\n## Benchmarks\n\n```console\nnpm --prefix bench start\n```\n\n## License\n\n[MIT](LICENSE.md)\n","publish_time":1541169726703,"_cnpm_publish_time":1541169726703,"dist-tags":{"latest":"2.3.0"}}