{"id":15995264,"url":"https://github.com/hoodie/guardgen","last_synced_at":"2025-09-12T20:31:49.984Z","repository":{"id":40796506,"uuid":"141941050","full_name":"hoodie/guardgen","owner":"hoodie","description":"💂🏻‍♂️ generate type guards from interface files","archived":false,"fork":false,"pushed_at":"2023-01-06T02:11:47.000Z","size":626,"stargazers_count":5,"open_issues_count":14,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T11:49:00.436Z","etag":null,"topics":["codegen","typeguard","typescript","typescript-generator"],"latest_commit_sha":null,"homepage":"","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/hoodie.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}},"created_at":"2018-07-23T00:12:34.000Z","updated_at":"2023-07-25T14:18:40.000Z","dependencies_parsed_at":"2023-02-05T02:31:18.390Z","dependency_job_id":null,"html_url":"https://github.com/hoodie/guardgen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hoodie/guardgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoodie%2Fguardgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoodie%2Fguardgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoodie%2Fguardgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoodie%2Fguardgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoodie","download_url":"https://codeload.github.com/hoodie/guardgen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoodie%2Fguardgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274873241,"owners_count":25365823,"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","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"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":["codegen","typeguard","typescript","typescript-generator"],"created_at":"2024-10-08T07:12:31.955Z","updated_at":"2025-09-12T20:31:49.687Z","avatar_url":"https://github.com/hoodie.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GuardGen\n\nGuardGen generates typescript [type guard](https://www.typescriptlang.org/docs/handbook/advanced-types.html)s from interface definitions so you don't have to write them and the don't get outdated.\n\nSo far it can understand something like this:\n\n```typescript\nexport interface Foo {\n    name: 'foo';\n    value: string;\n    amount: number;\n}\n\nexport interface Bar {\n    name: 'bar';\n    list?: number[];\n}\n\nexport interface Foobar {\n    foo: Foo;\n    bar: Bar;\n}\n```\n\nand produce something like this:\n\n```typescript\nimport {Foo, Bar, Foobar} from './test/example-types'\n\n// generated typeguard for Foo\nexport const isFoo = (maybeFoo: Foo): maybeFoo is Foo =\u003e {\n    const {name, value, amount} = maybeFoo;\n\n    return name === 'foo' /*name: 'foo'*/ \u0026\u0026\n    typeof value === 'string' /*value: string*/ \u0026\u0026\n    typeof amount === 'number' /*amount: number*/;\n}\n\n\n\n// generated typeguard for Bar\nexport const isBar = (maybeBar: Bar): maybeBar is Bar =\u003e {\n    const {name, list} = maybeBar;\n\n    return name === 'bar' /*name: 'bar'*/ \u0026\u0026\n    !(list) || (Array.isArray(list) \u0026\u0026 list.every((x) =\u003e typeof x === 'number')) /*list: Array\u003cnumber\u003e?*/;\n}\n\n\n\n// generated typeguard for Foobar\nexport const isFoobar = (maybeFoobar: Foobar): maybeFoobar is Foobar =\u003e {\n    const {foo, bar} = maybeFoobar;\n\n    return isFoo(foo) /*foo: Foo*/ \u0026\u0026\n    isBar(bar) /*bar: Bar*/;\n}\n```\n\n## Why?\n\nType guards are required to move some of the guarantees of the typesystem from compiletime to runtime. Unfortunately generating runtime code is not part of typescripts philosophy.\nHowever their compiler API makes it rather easy to generate them.\nThis is currently only a toy project, if you have more experience with TypeScripts Compiler API and great ambitions please pick it up :D\n\n## Usage\n\n### Cli\n\n`\u003e guardgen`\n\n```\n  Usage: guardgen [options] [command]\n\n  Options:\n\n    -V, --version                  output the version number\n    -h, --help                     output usage information\n\n  Commands:\n\n    generate|gen [options] [FILE]  generate guards from given ts file\n```\n\n`\u003e guardgen generate --help`\n\n```\n  Usage: generate|gen [options] [FILE]\n\n  generate guards from given ts file\n\n  Options:\n\n    -w, --warners         embed code that produces warnings\n    -g, --guardsfile      put a .guards.ts file next to your input\n    -o, --outfile [FILE]  path to file to generate\n    -h, --help            output usage information\n```\n\n### Output file\n\n`guardgen some-types.ts`\nprints to stdout.\n\n`guardgen some-types.ts -o src/someguards.ts `\ngenerates\n`src/someguards.ts`.\n\n`guardgen some-types.ts -o src/ `\ngenerates\n`src/some-types.guards.ts`.\n\n## Contribution\n\n\n### I found an issue\nOMG, I'm so sorry - please don't be mad! Thanks for reporting it in a kind manner and perhaps even helping me fix it quickly.\n\n### I want a feature X\n1. Ya! That sounds like a cool idea, now I want that too. Oh you already started implementing it? Even better, let me have a look and perhaps we just merge it.\n2. Hmm sounds like that is a different use case for a code generator - so let's not put it in guardgen and instead let's kick of an alternate generator for your special usecase. I can perhaps help you navigate Typescripts Compiler API or you just use guardgen as a template.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoodie%2Fguardgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoodie%2Fguardgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoodie%2Fguardgen/lists"}