{"id":20452834,"url":"https://github.com/axtk/args-json","last_synced_at":"2025-03-05T09:47:06.587Z","repository":{"id":240112892,"uuid":"801190568","full_name":"axtk/args-json","owner":"axtk","description":"Zero-dependency typed command-line argument parser","archived":false,"fork":false,"pushed_at":"2024-05-19T07:15:31.000Z","size":244,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T09:45:51.896Z","etag":null,"topics":["args","args-parser","argv","argv-parser","cli","cli-args"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/args-json","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/axtk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-15T19:08:07.000Z","updated_at":"2024-05-19T07:15:34.000Z","dependencies_parsed_at":"2024-05-16T20:26:29.676Z","dependency_job_id":"f314443d-89da-4c35-b4e6-74d530968cbb","html_url":"https://github.com/axtk/args-json","commit_stats":null,"previous_names":["axtk/args-json"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fargs-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fargs-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fargs-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fargs-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axtk","download_url":"https://codeload.github.com/axtk/args-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242005693,"owners_count":20056430,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["args","args-parser","argv","argv-parser","cli","cli-args"],"created_at":"2024-11-15T11:10:32.082Z","updated_at":"2025-03-05T09:47:06.566Z","avatar_url":"https://github.com/axtk.png","language":"TypeScript","readme":"# args-json\n\n*Zero-dependency typed command-line argument parser*\n\n## Installation\n\n```\nnpm i args-json\n```\n\n## Usage\n\n```js\nimport {parseArgs} from 'args-json';\n\nlet args = parseArgs('--config=./config.json -v 1.5.12 -d \"lorem ipsum\" -i -n=0 --test-value qwe --debug', {\n    v: 'version',\n    d: 'description',\n});\n// args = {\n//     config: './config.json',\n//     version: '1.5.12',\n//     description: 'lorem ipsum',\n//     i: true,\n//     n: 0,\n//     testValue: 'qwe',\n//     debug: true,\n// };\n```\n\nNote that keys and values can be separated from each other either with a space or an equals sign, and the value can be either quoted or not. These variants are equivalent. Also, keys are converted to *camelCase* (like `--test-value` \u0026rarr; `testValue` in the example above).\n\nThe second parameter is optional. It is a way to rename argument keys in the output. In the example above, `-d` and `-v` in the input string are renamed to `description` and `version` in the output object.\n\n### String input\n\n```js\nlet args = parseArgs('--config ./configs/default.json --debug');\n// {config: './configs/default.json', debug: true}\n\nif (args.debug)\n    console.log(args.config);\n```\n\nThe first line is also equivalent to:\n\n```js\nlet args = parseArgs('--config \"./configs/default.json\" --debug');\n```\n\nor\n\n```js\nlet args = parseArgs('--config=./configs/default.json --debug');\n```\n\nor\n\n```js\nlet args = parseArgs('--config=\"./configs/default.json\" --debug');\n```\n\n### String array input\n\n```js\nlet args = parseArgs(['--config', './configs/default.json', '--debug']);\n// {config: './configs/default.json', debug: true}\n\nif (args.debug)\n    console.log(args.config);\n```\n\n### Node process arguments\n\nIn a Node environment, `parseArgs()` without parameters parses the node process arguments.\n\n```js\nlet args = parseArgs();\n```\n\nis equivalent to\n\n```js\nlet args = parseArgs(process.argv);\n```\n\n### Key mapping\n\n```js\nlet args = parseArgs('-c ./configs/default.json --debug', {c: 'config'});\n// {config: './configs/default.json', debug: true}\n\nif (args.debug)\n    console.log(args.config);\n```\n\nAs specified with the second parameter of `parseArgs()`, `-c` is mapped to `config` in the output.\n\n### Value parsing\n\nValues are `JSON.parse`d if they are parsable.\n\n```js\nlet args = parseArgs('-d \\'{\"x\":10}\\' -i 0 -n=3 -c ./config.json');\n// {d: {x: 10}, i: 0, n: 3, c: './config.json'}\n```\n\n### Typing\n\nThe output type can be specified by providing a generic type to `parseArgs\u003cT\u003e()`.\n\n```ts\ntype CustomShape = {\n    level?: number;\n    debug?: boolean;\n};\n\nlet args = parseArgs\u003cCustomShape\u003e('--level=0 --debug');\n\nif (args.debug)\n    console.log(`Level: ${args.level}`);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Fargs-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxtk%2Fargs-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Fargs-json/lists"}