{"id":24091426,"url":"https://github.com/unkn0wn-root/ts-validator","last_synced_at":"2025-05-07T00:41:25.566Z","repository":{"id":268391832,"uuid":"904201828","full_name":"unkn0wn-root/ts-validator","owner":"unkn0wn-root","description":"A lightweight, type-safe runtime validation library for TypeScript.","archived":false,"fork":false,"pushed_at":"2024-12-19T09:20:32.000Z","size":75,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T19:06:46.219Z","etag":null,"topics":["deno","nodejs","typescript","validation-library","validator","validator-node"],"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/unkn0wn-root.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":"2024-12-16T12:46:28.000Z","updated_at":"2025-01-13T09:50:29.000Z","dependencies_parsed_at":"2024-12-16T13:55:57.504Z","dependency_job_id":"c1c7b20a-c468-4139-98a2-3d7010d58758","html_url":"https://github.com/unkn0wn-root/ts-validator","commit_stats":null,"previous_names":["unkn0wn-root/ts-validator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unkn0wn-root%2Fts-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unkn0wn-root%2Fts-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unkn0wn-root%2Fts-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unkn0wn-root%2Fts-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unkn0wn-root","download_url":"https://codeload.github.com/unkn0wn-root/ts-validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252793544,"owners_count":21805053,"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":["deno","nodejs","typescript","validation-library","validator","validator-node"],"created_at":"2025-01-10T07:44:04.866Z","updated_at":"2025-05-07T00:41:25.546Z","avatar_url":"https://github.com/unkn0wn-root.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript Validator\n\nA lightweight, type-safe runtime validation library for TypeScript.\n\n## Features\n\n- Full TypeScript support with type inference\n- Runtime validation\n- Composable schemas\n- Automatic removal of unknown properties\n- Zero dependencies\n- Small bundle size\n\n## Installation\n\n```bash\nnpm install @unkn0wn-root/ts-validator\n# or\nyarn add @unkn0wn-root/ts-validator\n```\n\n## Usage\n\n```typescript\nimport { validator } from '@unkn0wn-root/ts-validator';\n\nenum Status {\n  Active = 'active',\n  Inactive = 'inactive',\n  Pending = 'pending'\n}\n\n// Define your schema\nconst userSchema = validator.object({\n  id: validator.number(),\n  username: validator.string().refine((s) =\u003e s.length \u003e= 3, 'Username must be at least 3 characters'), // add custom validation\n  name: validator.string(),\n  email: validator.string().optional(),\n  status: validator.enum(Status),\n  metadata: validator.object({\n    lastLogin: validator.date().nullable(),\n    preferences: validator.object({\n      theme: validator.string()\n    }).optional()\n  })\n});\n\n// Type inference\ntype User = typeof userSchema._type;\n\n// Parse data (throws on invalid data)\ntry {\n  const user = userSchema.parse({\n    id: 123,\n    username: \"jobo\"\n    name: \"John\",\n    email: \"john@example.com\",\n    status: Status.Active, // Must be one of \"active\", \"inactive\", or \"pending\"\n    metadata: {\n      lastLogin: new Date(),\n      preferences: {\n        theme: \"dark\"\n      }\n    }\n  });\n  console.log(\"Valid user:\", user);\n} catch (error) {\n  if (error instanceof validator.ValidationError) {\n    console.error(\"Validation errors:\", error.issues);\n  }\n}\n\n// Safe parsing (returns result object)\nconst result = userSchema.safeParse(data);\nif (result.success) {\n  console.log(\"Valid data:\", result.data);\n} else {\n  console.error(\"Validation errors:\", result.error.issues);\n}\n```\n\n## API Reference\n\n### Basic Types\n\n- `validator.string()`\n- `validator.number()`\n- `validator.boolean()`\n- `validator.date()`\n\n### Complex Types\n\n- `validator.array(schema)`\n- `validator.object(shape)`\n- `validator.literal(value)`\n- `validator.union(schemas)`\n- `validator.enum(EnumType)`\n\n### Modifiers\n\n- `.optional()` - Makes a field optional\n- `.nullable()` - Allows null values\n- `.refine(check, message)` - Adds custom validation logic\n\n## Error Handling\n\nThe library throws `ValidationError` instances which contain detailed information about validation failures:\n\n```typescript\ntry {\n  const data = schema.parse(invalidData);\n} catch (error) {\n  if (error instanceof validator.ValidationError) {\n    error.issues.forEach(issue =\u003e {\n      console.log(`Error at ${issue.path.join('.')}: ${issue.message}`);\n    });\n  }\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funkn0wn-root%2Fts-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funkn0wn-root%2Fts-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funkn0wn-root%2Fts-validator/lists"}