{"name":"getopts","description":"Node.js CLI options parser.","version":"2.1.0","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":{"ts":"tsc test/ts/index.ts","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":"e455e4bff2132efa453deb1ac3d02681487a9e18","bugs":{"url":"https://github.com/jorgebucaran/getopts/issues"},"homepage":"https://github.com/jorgebucaran/getopts#readme","_id":"getopts@2.1.0","_npmVersion":"6.1.0","_nodeVersion":"10.0.0","_npmUser":{"name":"jorgebucaran","email":"mail@jorgebucaran.com"},"dist":{"integrity":"sha512-CvCP49JBIcTYU6qy8u+wwqNKf6zxTNvs4Jmj+w3L1MralGvQ+hEQX0hSqXI/Khr5b2oFBJ57kEfeIWVM6jKgfw==","shasum":"ce9f1acd3c888bce04d8afee7a5c9724f1228b72","tarball":"http://registry-npm.ywwl.com/getopts/download/getopts-2.1.0.tgz","fileCount":5,"unpackedSize":9116,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbTa+KCRA9TVsSAnZWagAA4Z4P/0pIOkJxin+bqKhvnArA\njY1VTFrnajLw/aD12MyZIZuROWrVkWJRS5EF1iBxf8bo+rJVVW3HIY+gHUFJ\nJ5UHPzMVLbm2Edn8DHlq6avt+ghZkjY4Q2e1RT5jFbEkV4Bkh7sffAhdyiA3\n17jrUqwoUcPdJeb5iqUN+7xAlZ1jOluA9gdJw05ctI6B+bYmsxvJhZ461w0D\nyuOx2t/eHxNi96z6LiNx9Iy+9A/cY+aQxttLyy3necuAcRLIAUBL3s/xg6UW\n9O20t1xTjGrZqGDp9RW/wIxxoh3b3nIQDLtRPFmGhhiYZnLP3RrlmmCAE7/q\nv5FFc4gv6Um6OQ5ajsZ91Z81G4BHuYA6w7n8TxwE0lO3qtOcYmmVj7MQcUpg\n8sTg+sKLz22tswkhsdHKfqDSpJproUtRkisbTLjYEO/3Eo/XSpTLI5hX9YZX\nWbR6gruXfsSrRXOoTyZ/VKtC5disf/7OFu5IOEakElsJM7OewpomqEK76FfU\nlNeAvZt2rUOHgRMglNkSdW0bnj9Loy1l1NIwoify2NnqtjCmhrF6pNgopxQg\np8dUG8qCVfQE8NFv27oo0pSHQ4G/Wv6ykL17h40Pi8nsfRjc+23aeUeWLywq\ntuAaR6rklpyrmxi5Wk3IqCscTBGicAy4jYJz5accqLWuB45Mn+gjBT15xnd/\nuurW\r\n=UXGN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC7Aermf23ZkabHov+FitNTQAo9JAVtkghf1e1laUukjgIgLFjPWCQzfZu5XFYWvfEBHfAieYY0FfXnfWve2aLRBwk="}],"size":3651,"noattachment":false,"key":"/getopts/-/getopts-2.1.0.tgz"},"maintainers":[{"email":"mail@jorgebucaran.com","name":"jorgebucaran"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/getopts_2.1.0_1531817866077_0.6448064853484341"},"_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":1531817866160,"_cnpm_publish_time":1531817866160,"dist-tags":{"latest":"2.3.0"}}