{"id":20452834,"url":"https://github.com/axtk/args-json","last_synced_at":"2026-06-01T08:32:24.680Z","repository":{"id":240112892,"uuid":"801190568","full_name":"axtk/args-json","owner":"axtk","description":"Zero-dependency descriptively typed command-line argument parser","archived":false,"fork":false,"pushed_at":"2026-04-10T12:05:06.000Z","size":329,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-10T12:16:31.389Z","etag":null,"topics":["args","args-parser","argv","argv-parser","cli","cli-args"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/args-json","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","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":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-05-15T19:08:07.000Z","updated_at":"2026-04-10T12:05:13.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":31,"template":false,"template_full_name":null,"purl":"pkg:github/axtk/args-json","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","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fargs-json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33767435,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2026-06-01T08:32:24.672Z","avatar_url":"https://github.com/axtk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# args-json\n\nZero-dependency descriptively typed command-line argument parser\n\nContents: [parseArgs](#parseargs) · [Args](#args) · [isOn / isOff / isExplicitlyOff](#ison--isoff--isexplicitlyoff)\n\n## parseArgs\n\n### String input\n\n```js\nimport { parseArgs } from \"args-json\";\n\nconst args = parseArgs(\n  \"--config=./config.json -v 1.0.0 -d \\\"lorem ipsum\\\" -i -n=0 --test-value abc --debug\",\n  {\n    v: \"version\",\n    d: \"description\",\n  }\n);\n// args = {\n//   config: \"./config.json\",\n//   version: \"1.0.0\",\n//   description: \"lorem ipsum\",\n//   i: true,\n//   n: 0,\n//   testValue: \"abc\",\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\nOther examples:\n\n```js\nconst args = parseArgs(\"--config ./configs/default.json --debug\");\n// { config: \"./configs/default.json\", debug: true }\n\nif (args.debug) console.log(args.config);\n```\n\nThe first line is also equivalent to:\n\n```js\nconst args = parseArgs(\"--config \\\"./configs/default.json\\\" --debug\");\n```\n\nor\n\n```js\nconst args = parseArgs(\"--config=./configs/default.json --debug\");\n```\n\nor\n\n```js\nconst args = parseArgs(\"--config=\\\"./configs/default.json\\\" --debug\");\n```\n\n### String array input\n\n```js\nconst args = parseArgs([\"--config\", \"./configs/default.json\", \"--debug\"]);\n// { config: \"./configs/default.json\", debug: true }\n\nif (args.debug) 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\nconst args = parseArgs();\n```\n\nis equivalent to\n\n```js\nconst args = parseArgs(process.argv);\n```\n\nIf the `process` object is unavailable in the current environment, `parseArgs()` is equivalent to `parseArgs([])`.\n\n### Key mapping\n\n```js\nconst args = parseArgs(\"-c ./configs/default.json --debug\", { c: \"config\" });\n// { config: \"./configs/default.json\", debug: true }\n\nif (args.debug) 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\nconst 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### Unkeyed values\n\nValues that aren't preceded by a dashed key (like `-x` or `--xxx`) are collected in an array under an empty key entry.\n\n```js\nconst args = parseArgs(\"unkeyed args --debug -x 0 -y 1\");\n// { \"\": [\"unkeyed\", \"args\"], debug: true, x: 0, y: 1 }\n```\n\n### Descriptive typing\n\nThe output type can be descriptively specified, without validation, by providing a generic type to `parseArgs\u003cT\u003e()`.\n\n```ts\ntype CustomShape = {\n  level?: number;\n  debug?: boolean;\n};\n\nconst args = parseArgs\u003cCustomShape\u003e(\"--level=0 --debug\");\n\nif (args.debug) console.log(`Level: ${args.level}`);\n```\n\n## Args\n\nUse an `Args` class instance to facilitate access to named command line arguments:\n\n```js\nimport { Args } from \"args-json\";\n\nconst args = new Args([\"--key\", \"value\", \"--paths\", \"./x\", \"./y\"]);\n\nargs.hasKey(\"--key\") // true\nargs.hasKey(\"--arg\") // false\nargs.getValue(\"--key\") // \"value\"\nargs.getValues(\"--paths\") // [\"./x\", \"./y\"]\n```\n\nWithout an argument array, `new Args()` is equivalent to `new Args(process.argv)` (or `new Args([])` if the `process` object is unavailable in the current environment). An `Args` object initialized without arguments can also be directly imported with `import { args } from \"args-json\";`.\n\n## isOn / isOff / isExplicitlyOff\n\nUse `isOn(x)` and `isOff(x)` to check whether a parameter value is `true`, `1`, `\"on\"` or `false`, `0`, `\"off\"`, `null`, `undefined`.\n\n```js\nimport { parseArgs, isOn, isOff } from \"args-json\";\n\n// isOn\nisOn(parseArgs(\"--debug\").debug) // true\nisOn(parseArgs(\"--debug=1\").debug) // true\nisOn(parseArgs(\"--debug=on\").debug) // true\n\nisOn(parseArgs(\"\").debug) // false\nisOn(parseArgs(\"--debug=0\").debug) // false\nisOn(parseArgs(\"--debug=off\").debug) // false\n\nnew Args([\"--debug\"]).isOn(\"--debug\") // true\nnew Args([\"--debug\", \"1\"]).isOn(\"--debug\") // true\nnew Args([\"--debug\", \"on\"]).isOn(\"--debug\") // true\n\n// isOff\nisOff(parseArgs(\"\").debug) // true\nisOff(parseArgs(\"--debug=0\").debug) // true\nisOff(parseArgs(\"--debug=off\").debug) // true\n\nnew Args([\"\"]).isOff(\"--debug\") // true\nnew Args([\"--debug\", \"0\"]).isOff(\"--debug\") // true\nnew Args([\"--debug\", \"off\"]).isOff(\"--debug\") // true\n```\n\nNote the difference between `isOff(x)` and `isExplicitlyOff(x)`: `isExplicitlyOff(x)` results in `true` if `x` is present and it's explicitly a turn-off value, while `isOff(x)` returns `true` if `x` is omitted, too.\n\n```js\nimport { parseArgs, isOff, isExplicitlyOff } from \"args-json\";\n\nisOff(parseArgs(\"--debug=off\").debug) // true\nisOff(parseArgs(\"--debug=0\").debug) // true\nisOff(parseArgs(\"\").debug) // true\n\nisExplicitlyOff(parseArgs(\"--debug=off\").debug) // true\nisExplicitlyOff(parseArgs(\"--debug=0\").debug) // true\nisExplicitlyOff(parseArgs(\"\").debug) // false\n```\n\nUse the utility types `On` and `Off` (or `ExplicitlyOff`) to define a switch parameter type:\n\n```ts\nimport { parseArgs, type On, type Off } from \"args-json\";\n\ntype Params = {\n  debug?: On | Off;\n};\n\nconst args = parseArgs\u003cParams\u003e(\"--debug=on\");\n```\n","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"}