{"name":"getopts","version":"2.3.0","type":"module","main":"index.cjs","types":"index.d.ts","description":"Parse CLI arguments.","repository":{"type":"git","url":"git+https://github.com/jorgebucaran/getopts.git"},"license":"MIT","exports":{"./package.json":"./package.json",".":{"require":"./index.cjs","import":"./index.js"}},"author":{"name":"Jorge Bucaran"},"keywords":["cli","argv","flags","parse","getopts","minimist","cli-parser"],"scripts":{"test":"c8 twist tests/*.js","build":"node -e \"fs.writeFileSync('index.cjs',fs.readFileSync('index.js','utf8').replace(/export default/,'module.exports ='),'utf8')\"","deploy":"npm test && git commit --all --message $tag && git tag --sign $tag --message $tag && git push && git push --tags","release":"tag=$npm_package_version npm run deploy && npm publish --access public","prepare":"npm run build"},"devDependencies":{"c8":"*","twist":"*"},"gitHead":"35dfad8997697051234aca992eb90c7abd7a5465","bugs":{"url":"https://github.com/jorgebucaran/getopts/issues"},"homepage":"https://github.com/jorgebucaran/getopts#readme","_id":"getopts@2.3.0","_nodeVersion":"15.6.0","_npmVersion":"7.4.0","dist":{"integrity":"sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==","shasum":"71e5593284807e03e2427449d4f6712a268666f4","tarball":"http://registry-npm.ywwl.com/getopts/download/getopts-2.3.0.tgz","fileCount":6,"unpackedSize":18169,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgKsaWCRA9TVsSAnZWagAA15YQAJcUpN8EpI+yFSz2lRt5\nsuqHoiRTW8oU123h7wMhmVNo19bGH46dAUJ2iEjh3JOchshJg7P74QApLO/a\nY66eWhoE+vA8G+6uRKDrTQde1//WuwEob2PkRPDmU1WVOQiTysjWacBPBOtX\nT7jVYTfWsxf1AKk0Xtsk2fxS8RZyG4XsSkL1zDhxBR4ZAziPvn7CCLtaNfAV\nPrTk0yuMUpoRWz8emr6f9Ds9SGbivN1BnZusv6qQnB2o/OBbiBho1Sx7D2/5\n3hzxRdtpV8SrpDhk60dCVcZG+rmv7DpENB1gosdZZ9S795vpK43/XEgtxeW/\nF92SbvK3VO0ju+C2euoqef2stORe2tuSjHAXydOl/Q/UF6bSdldhdIFvKm95\nnSmLBvIHpFpFuqVOHU5+dyZed9WlRhynFGhY9dyuMX4/jJj5gpf7918KxKCZ\nu2oR+xLzf+AFaz7qjLMDgrlC70MNjWVGoPgay7qKbgpCSiwg5TuMcoGtCxpz\nHzja5Q4tu0vLuG5uAa+JTlQPKUT+G9dqmw1e2RxAKR+WpgvWj4BatKD3u6Wp\ndFi9O0tPz70tnVQhMl/u9JqXHTBpK0lDPZh2BLdMyrf7mwwlIBmshbHOnpAS\n7zClznMMCJ8ixJi0274gCDK5wS1AfYKmrI0F3qeXIFMbzRobP5kB7lY3oDKY\nG/Wr\r\n=Mkug\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFiIVduXhu1JRWe0vVbfyqBqa0sC8CDIquqi44lPwtP/AiEAtm2/jrqCZ4dK+KOB0do9ueU8MtbEPETwdAqbh8HKhDg="}],"size":5045,"noattachment":false,"key":"/getopts/-/getopts-2.3.0.tgz"},"_npmUser":{"name":"jorgebucaran","email":"mail@jorgebucaran.com"},"directories":{},"maintainers":[{"name":"jorgebucaran","email":"mail@jorgebucaran.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/getopts_2.3.0_1613416085998_0.3745811421644454"},"_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":1613416086140,"_cnpm_publish_time":1613416086140,"dist-tags":{"latest":"2.3.0"}}