{"id":21297887,"url":"https://github.com/vriskaserket51/typescript-type-checker","last_synced_at":"2025-08-28T16:40:18.334Z","repository":{"id":214803938,"uuid":"734948521","full_name":"VriskaSerket51/typescript-type-checker","owner":"VriskaSerket51","description":"Runtime Type Checker for Typescript","archived":false,"fork":false,"pushed_at":"2024-01-08T02:52:30.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T14:37:06.566Z","etag":null,"topics":["runtime-typechecking","type-checker","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/typescript-type-checker","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/VriskaSerket51.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}},"created_at":"2023-12-23T05:51:17.000Z","updated_at":"2024-01-07T00:02:47.000Z","dependencies_parsed_at":"2024-01-08T03:49:09.588Z","dependency_job_id":null,"html_url":"https://github.com/VriskaSerket51/typescript-type-checker","commit_stats":null,"previous_names":["vriskaserket51/typescript-type-checker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VriskaSerket51%2Ftypescript-type-checker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VriskaSerket51%2Ftypescript-type-checker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VriskaSerket51%2Ftypescript-type-checker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VriskaSerket51%2Ftypescript-type-checker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VriskaSerket51","download_url":"https://codeload.github.com/VriskaSerket51/typescript-type-checker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243769946,"owners_count":20345215,"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":["runtime-typechecking","type-checker","typescript"],"created_at":"2024-11-21T14:42:23.198Z","updated_at":"2025-03-15T17:41:54.321Z","avatar_url":"https://github.com/VriskaSerket51.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typescript-type-checker\n\ntypescript-type-checker is Runtime Type Checker for Typescript.\n\nIt generates runtime type checking sanitizer script for Typescript.\n\ntypescript-type-checker supports all default types, arrays, and custom types.\n\n## How to install\n\n`npm install typescript-type-checker`\n\n## How to use\n\nYou can use typescript-type-checker both commandline and script.\n\n### Script usage\n\n```typescript\nimport { buildScript } from \"typescript-type-checker\";\n\nconst srcDir = \"./src/lib\";\nconst outputPath = \"./out.ts\";\nconst strictMode = false;\n\nbuildScript(srcDir, outputPath, strictMode);\n```\n\n### Commandline usage\n\n\u003e args:\n\u003e * --src: Input directory which contains .ts files\n\u003e * --out: Output directory which sanitizer script will be saved to\n\u003e * --strict: Whether use strict mode. In strict mode, script does not check string value can be converted to number or boolean\n\u003e\n\u003e example: \u003cbr /\u003e\n\u003e $ npx typescript-type-checker --src \"./src/lib\" --out \"./out/sanitizer.ts\" --strict\n\nThen you can get sanitizer script at \"./out/sanitizer.ts\".\n\n## Example\n\n`./src/lib/example.ts`\n```typescript\nexport interface Foo {\n    number: number;\n    boolean: boolean;\n    maybeString?: string;\n    bar: Bar;\n}\n\ninterface Bar {\n    numbers: number[];\n}\n```\n\n### With strict mode\n\n```typescript\nfunction sanitizeFoo(checker: any) {\n    if (\n        typeof checker.number != \"number\" ||\n        typeof checker.boolean != \"boolean\" ||\n        (checker.maybeString != undefined \u0026\u0026\n            typeof checker.maybeString != \"string\") ||\n        !sanitizeBar(checker.bar)\n    ) {\n        return false;\n    }\n    return true;\n}\n\nfunction sanitizeBar(checker: any) {\n    if (!sanitizenumberArray(checker.numbers)) {\n        return false;\n    }\n    return true;\n}\n\nfunction sanitizenumberArray(checker: any) {\n    if (!Array.isArray(checker)) {\n        return false;\n    }\n\n    for (let i = 0; i \u003c checker.length; i++) {\n        if (typeof checker[i] != \"number\") {\n            return false;\n        }\n    }\n    return true;\n}\n```\n\n### Without strict mode\n\n```typescript\nfunction sanitizeFoo(checker: any) {\n    if (\n        typeof checker.number == \"string\" \u0026\u0026\n        Boolean(checker.number.trim()) \u0026\u0026\n        !Number.isNaN(Number(checker.number))\n    ) {\n        checker.number = Number(checker.number);\n    }\n\n    if (\n        typeof checker.boolean == \"string\" \u0026\u0026\n        (checker.boolean == \"true\" || checker.boolean == \"false\")\n    ) {\n        checker.boolean = checker.boolean == \"true\";\n    }\n\n    if (\n        typeof checker.number != \"number\" ||\n        typeof checker.boolean != \"boolean\" ||\n        (checker.maybeString != undefined \u0026\u0026\n            typeof checker.maybeString != \"string\") ||\n        !sanitizeBar(checker.bar)\n    ) {\n        return false;\n    }\n    return true;\n}\n\nfunction sanitizeBar(checker: any) {\n    if (!sanitizenumberArray(checker.numbers)) {\n        return false;\n    }\n    return true;\n}\n\nfunction sanitizenumberArray(checker: any) {\n    if (!Array.isArray(checker)) {\n        return false;\n    }\n\n    for (let i = 0; i \u003c checker.length; i++) {\n        if (typeof checker[i] != \"number\") {\n            return false;\n        }\n    }\n    return true;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvriskaserket51%2Ftypescript-type-checker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvriskaserket51%2Ftypescript-type-checker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvriskaserket51%2Ftypescript-type-checker/lists"}