{"name":"getopts","description":"Node.js CLI options parser.","version":"2.1.2","main":"index.js","types":"getopts.d.ts","license":"MIT","repository":{"type":"git","url":"git+https://github.com/jorgebucaran/getopts.git"},"author":{"name":"Jorge Bucaran"},"files":["index.js","getopts.d.ts"],"keywords":["getopts","cli","argv","cli-parser"],"scripts":{"test":"nyc -r lcov tape 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","tape":"^4.9.1","typescript":"^2.9.2"},"gitHead":"f8b4b8e7e454167ffeaa72c8ad5722b7661c3fb2","bugs":{"url":"https://github.com/jorgebucaran/getopts/issues"},"homepage":"https://github.com/jorgebucaran/getopts#readme","_id":"getopts@2.1.2","_npmVersion":"5.5.1","_nodeVersion":"9.0.0","_npmUser":{"name":"jorgebucaran","email":"mail@jorgebucaran.com"},"dist":{"integrity":"sha512-MrHtLn3JX1E6FR5BL8oVksMlser38k4+s5IaPz2Nx//5InLBUf4Yp8EhYiQeolassOjAU5TzkURud3M7mQSJrA==","shasum":"ecbd171ff3099ac06e8162d58ab605ecd6f4feef","tarball":"http://registry-npm.ywwl.com/getopts/download/getopts-2.1.2.tgz","fileCount":5,"unpackedSize":8721,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbT1Z8CRA9TVsSAnZWagAAcmMP/3gfvNlMl9ABprsYHs42\nUIKGBa5k3jM8wbouGE/CmI62M1NHy1mN2SZPlGDqmI9g17Zw2yClhdyTBm3x\nmsuodgU91kY0uZ+EAit8WVQbDv9Zd5pu3fQ+Jx6wDBvWU82X7iACbeDMcDah\n0Soz2/1TL02d5m16WaycDGgncJ4i1xkoT/6Ys5sg5FL8vbhVGc6Z3jl3rED9\nRnzok89PofCto6reyPNgHwYCxOQKYkcx+OwppQacLOwkqBBedXvEYk/KFqpE\nGOGadiRyP/SsY6y9AUus3BbUo11IPk7D6dZgoY7Uz9UYifvRpXRysw3+2VT4\n4SjdxIOwiCfwi2GF/GPSQk8EQeJR1lPYPvBsyiF0773+iHvticaAqGA0qSPG\nUJM4SA1+qyB33RAyag7YDlBTvrwA9r5vb1EqQSf9ZcKuVsEvFpBsOihItBOM\n5EW+9n7Akhy2gwJKyKBTlLVccQcN2Ewpqbz9Ht442HLh2JJ9y6oqwSVii8dO\n15PbXhM5G4UISYsnGbKL53xHeIsd7zDex/EqeHF5LgN8Sx9QHJGIBX1OHjjn\nbUgp+5aeQGmRSxoAfoDeYXWnuvByGHx5CMZjq2LFE9DLxhl7KFF1C6cJ0P8l\nj9hTkV6AZmNqreDq9NMNssp3D9rVtWt1ZDk2spYZtDpPZKSY6v66mzd/YbfG\nYNF5\r\n=ggM+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC5ETyIS76+ZdE48LzKQqNwFdcdeJD0XoJyGY0BNuDTWQIhAMWxnC6G79enPJpK7qKZBQjI2/TDzfeRxEc2TXZouzJY"}],"size":3599,"noattachment":false,"key":"/getopts/-/getopts-2.1.2.tgz"},"maintainers":[{"email":"mail@jorgebucaran.com","name":"jorgebucaran"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/getopts_2.1.2_1531926140158_0.026647870239417504"},"_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":1531926140214,"_cnpm_publish_time":1531926140214,"dist-tags":{"latest":"2.3.0"}}