{"id":35267676,"url":"https://github.com/asheswook/valdex","last_synced_at":"2026-01-13T21:47:45.440Z","repository":{"id":328766411,"uuid":"1086150162","full_name":"asheswook/valdex","owner":"asheswook","description":"Runtime type validation with TypeScript type inference","archived":false,"fork":false,"pushed_at":"2025-12-30T05:37:25.000Z","size":174,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-13T02:50:07.378Z","etag":null,"topics":["typescript"],"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/asheswook.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":"2025-10-30T02:40:23.000Z","updated_at":"2025-12-30T05:34:10.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/asheswook/valdex","commit_stats":null,"previous_names":["asheswook/valdex"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/asheswook/valdex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asheswook%2Fvaldex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asheswook%2Fvaldex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asheswook%2Fvaldex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asheswook%2Fvaldex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asheswook","download_url":"https://codeload.github.com/asheswook/valdex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asheswook%2Fvaldex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28401077,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["typescript"],"created_at":"2025-12-30T11:06:12.225Z","updated_at":"2026-01-13T21:47:45.435Z","avatar_url":"https://github.com/asheswook.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# valdex\n\n**Runtime type validation with TypeScript type inference**\n\nValidate unknown data at runtime and get automatic TypeScript type narrowing—without separate schema objects or class instances.\n\n## Why valdex?\n\nRuntime validation libraries typically require you to define schemas separately and instantiate them before use. This creates distance between where you validate and where you consume the data.\n\nValdex takes a different approach: validate inline, exactly where you need it. No jumping between schema definitions and usage points. No maintaining separate DTO classes or validator instances.\n\n```typescript\n// Traditional approach - schema defined elsewhere\nconst userSchema = z.object({ name: z.string(), age: z.number() });\nconst user = userSchema.parse(data);\n\n// valdex - validate at point of use\nvalidate(data, { name: String, age: Number });\n// data is now typed as { name: string, age: number }\n```\n\nThis is particularly useful when working with:\n- Database query results (mysql2, pg, etc.)\n- External API responses (axios, fetch)\n- Message queue payloads\n- Any `unknown` or `any` typed data that needs runtime verification\n\n## Installation\n\n```bash\nnpm install valdex\n```\n\n## Features\n\n- **Zero dependencies**: No external dependencies\n- **Type inference**: Automatic TypeScript type narrowing after validation\n- **Inline validation**: Validate where you use, not where you define\n- **Nested structures**: Full support for nested objects and arrays\n- **Optional/Nullable**: Flexible handling of optional and nullable fields\n\n## Usage\n\n### Basic Validation\n\n```typescript\nimport { validate } from 'valdex';\n\nconst data: unknown = await fetchData();\n\nvalidate(data, {\n  name: String,\n  age: Number,\n  active: Boolean\n});\n\n// TypeScript now knows the exact type of data\ndata.name   // string\ndata.age    // number\ndata.active // boolean\n```\n\n### Nested Objects\n\n```typescript\nvalidate(data, {\n  user: {\n    id: Number,\n    profile: {\n      name: String,\n      email: String\n    }\n  }\n});\n\ndata.user.profile.name // string\n```\n\n### Arrays\n\n```typescript\nvalidate(data, {\n  tags: [String],  // string[]\n  items: [{        // { id: number, name: string }[]\n    id: Number,\n    name: String\n  }]\n});\n\ndata.tags[0]       // string\ndata.items[0].id   // number\n```\n\n### Optional Fields\n\nUse `Optional()` to allow `undefined` values:\n\n```typescript\nimport { validate, Optional } from 'valdex';\n\nvalidate(data, {\n  required: String,\n  optional: Optional(String),  // string | undefined\n  optionalObject: Optional({   // { id: number } | undefined\n    id: Number\n  }),\n  optionalArray: Optional([Number]) // number[] | undefined\n});\n```\n\n### Nullable Fields\n\nUse `Nullable()` to allow `null` values:\n\n```typescript\nimport { validate, Nullable } from 'valdex';\n\nvalidate(data, {\n  required: String,\n  nullable: Nullable(String),  // string | null\n  nullableObject: Nullable({   // { id: number } | null\n    id: Number\n  })\n});\n```\n\n### Combining Optional and Nullable\n\n```typescript\nimport { validate, Optional, Nullable } from 'valdex';\n\nvalidate(data, {\n  field: Optional(Nullable(String)) // string | undefined | null\n});\n```\n\n## Supported Types\n\n| Constructor | TypeScript Type |\n|-------------|-----------------|\n| `String`    | `string`        |\n| `Number`    | `number`        |\n| `Boolean`   | `boolean`       |\n| `Array`     | `any[]`         |\n| `Object`    | `object`        |\n| `Date`      | `Date`          |\n\n## Error Handling\n\nWhen validation fails, a `RuntimeTypeError` is thrown:\n\n```typescript\nimport { validate, RuntimeTypeError } from 'valdex';\n\ntry {\n  validate(data, { count: Number });\n} catch (error) {\n  if (error instanceof RuntimeTypeError) {\n    console.error(error.message);\n    // \"count must be Number, but got String. Actual value: hello\"\n  }\n}\n```\n\n## How It Works\n\n- Fields not declared in the schema but present in data are ignored\n- All declared fields are required by default (no `undefined` or `null`)\n- Use `Optional()` to allow `undefined`\n- Use `Nullable()` to allow `null`\n- `NaN` is not considered a valid `Number`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasheswook%2Fvaldex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasheswook%2Fvaldex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasheswook%2Fvaldex/lists"}