{"id":23103926,"url":"https://github.com/moontaiworks/yargs-typebox","last_synced_at":"2025-07-19T13:11:52.402Z","repository":{"id":257815962,"uuid":"867484262","full_name":"moontaiworks/yargs-typebox","owner":"moontaiworks","description":"Use TypeBox to define your yargs arguments.","archived":false,"fork":false,"pushed_at":"2024-10-09T07:55:15.000Z","size":196,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-12T10:48:20.865Z","etag":null,"topics":["arguments","typebox","typescript","yargs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/yargs-typebox","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/moontaiworks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2024-10-04T06:45:02.000Z","updated_at":"2024-10-09T07:55:12.000Z","dependencies_parsed_at":"2024-10-12T00:15:36.210Z","dependency_job_id":null,"html_url":"https://github.com/moontaiworks/yargs-typebox","commit_stats":null,"previous_names":["moontaiworks/yargs-typebox"],"tags_count":3,"template":false,"template_full_name":"moontaiworks/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moontaiworks%2Fyargs-typebox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moontaiworks%2Fyargs-typebox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moontaiworks%2Fyargs-typebox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moontaiworks%2Fyargs-typebox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moontaiworks","download_url":"https://codeload.github.com/moontaiworks/yargs-typebox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230044008,"owners_count":18164103,"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":["arguments","typebox","typescript","yargs"],"created_at":"2024-12-17T00:29:52.369Z","updated_at":"2024-12-17T00:29:52.445Z","avatar_url":"https://github.com/moontaiworks.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yargs-typebox\n\n[![NPM Version](https://img.shields.io/npm/v/yargs-typebox)](https://www.npmjs.com/package/yargs-typebox)\n[![NPM Downloads](https://img.shields.io/npm/d18m/yargs-typebox)](https://www.npmjs.com/package/yargs-typebox)\n[![Codecov](https://codecov.io/gh/moontaiworks/yargs-typebox/graph/badge.svg)](https://codecov.io/gh/moontaiworks/yargs-typebox)\n\nUse [TypeBox](https://github.com/sinclairzx81/typebox) to define your [yargs](https://www.npmjs.com/package/yargs) arguments.\n\n## Install\n\n### NPM\n\n```bash\nnpm install yargs-typebox\n```\n\n### Yarn\n\n```bash\nyarn add yargs-typebox\n```\n\n### PNPM\n\n```bash\npnpm add yargs-typebox\n```\n\n## Usage\n\n### getOptions(TObject)\n\nTransform a whole TypeBox object into yargs options object.\n\n```typescript\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { getOptions } from \"yargs-typebox\";\n\nconst schema = Type.Object({\n  page: Type.Number({ description: \"page number\" }),\n  size: Type.Number({ description: \"page size\", default: 10 }),\n  query: Type.Optional(Type.String()),\n  sort: Type.Optional(\n    Type.Array(Type.Union([Type.Literal(\"id\"), Type.Literal(\"createdAt\")])),\n  ),\n  order: Type.Union([Type.Literal(\"asc\"), Type.Literal(\"desc\")], {\n    default: \"asc\",\n    implies: [\"sort\"],\n  }),\n  pretty: Type.Boolean({ description: \"pretty print\" }),\n  count: Type.Any({ description: \"count\", count: true }),\n});\n\nconst options = getOptions(schema);\n// {\n//   page: {\n//     type: \"number\",\n//     demandOption: true,\n//     describe: \"page number\",\n//   },\n//   size: {\n//     type: \"number\",\n//     default: 10,\n//     demandOption: false,\n//     describe: \"page size\",\n//   },\n//   query: {\n//     type: \"string\",\n//     demandOption: false,\n//   },\n//   sort: {\n//     type: \"array\",\n//     demandOption: false,\n//     choices: [\"id\", \"createdAt\"],\n//   },\n//   order: {\n//     type: \"string\",\n//     implies: [\"sort\"],\n//     default: \"asc\",\n//     demandOption: false,\n//     choices: [\"asc\", \"desc\"],\n//   },\n//   pretty: {\n//     type: \"boolean\",\n//     demandOption: true,\n//     describe: \"pretty print\",\n//   },\n//   count: {\n//     count: true,\n//     demandOption: true,\n//     describe: \"count\",\n//   },\n// }\n\nconst argv = yargs(hideBin(process.argv))\n  .options(options)\n  .help()\n  .parse() as Static\u003ctypeof schema\u003e;\n\nconsole.log(argv);\n```\n\n### getOption(TSchema)\n\nTransform a single TypeBox schema into yargs option.\n\n```typescript\nimport { Type } from \"@sinclair/typebox\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { getOption } from \"yargs-typebox\";\n\nconst prettyArgument = Type.Boolean({ description: \"pretty print\" });\nconst countArgument = Type.Any({ description: \"count\", count: true });\n\nconst prettyOption = getOption(prettyArgument);\n// {\n//   type: \"boolean\",\n//   demandOption: true,\n//   describe: \"pretty print\",\n// }\nconst countOption = getOption(countArgument);\n// {\n//   count: true,\n//   demandOption: true,\n//   describe: \"count\",\n// }\n\nconst argv = yargs(hideBin(process.argv))\n  .option(\"pretty\", prettyOption)\n  .option(\"count\", countOption)\n  .help()\n  .parse();\n\nconsole.log(argv);\n```\n\n## API Document\n\nFor more informations, see the [API documentation](https://moontaiworks.github.io/yargs-typebox/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoontaiworks%2Fyargs-typebox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoontaiworks%2Fyargs-typebox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoontaiworks%2Fyargs-typebox/lists"}