{"id":27108248,"url":"https://github.com/deviltea/valchecker","last_synced_at":"2026-06-05T22:31:44.373Z","repository":{"id":234062289,"uuid":"788230571","full_name":"DevilTea/valchecker","owner":"DevilTea","description":"WIP: JS / TS Schema Validator","archived":false,"fork":false,"pushed_at":"2024-05-22T09:35:36.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-22T10:47:56.818Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/DevilTea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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-04-18T02:44:13.000Z","updated_at":"2024-05-27T11:54:44.594Z","dependencies_parsed_at":"2024-05-05T16:25:52.588Z","dependency_job_id":"6e68794f-39f3-4652-aea7-a47ad6a9cb23","html_url":"https://github.com/DevilTea/valchecker","commit_stats":null,"previous_names":["deviltea/valcheck"],"tags_count":0,"template":false,"template_full_name":"DevilTea/starter-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevilTea%2Fvalchecker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevilTea%2Fvalchecker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevilTea%2Fvalchecker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevilTea%2Fvalchecker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevilTea","download_url":"https://codeload.github.com/DevilTea/valchecker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557759,"owners_count":20958047,"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":[],"created_at":"2025-04-06T21:52:43.486Z","updated_at":"2026-06-05T22:31:44.336Z","avatar_url":"https://github.com/DevilTea.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# valchecker\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![License][license-src]][license-href]\n\n\u003e Runtime-first validation with zero guesswork\n\nA modular TypeScript validation library with composable steps, full type inference, and deterministic issue reporting. Compliant with [Standard Schema V1](https://github.com/standard-schema/standard-schema).\n\n## Features\n\n- **Composable Step Pipeline** - Chain validation, transformation, and error handling steps with a fluent API\n- **Full Type Inference** - TypeScript types flow through transforms, narrowing checks, and fallback chains automatically\n- **Deterministic Issue Reporting** - Structured errors with codes, payloads, and deep paths for precise debugging\n- **Tree-Shakable by Design** - Import all steps for prototyping or cherry-pick for minimal production bundles\n- **Async-Safe Pipelines** - Mix synchronous and asynchronous validation seamlessly in the same pipeline\n- **Batteries-Included Transforms** - Trim strings, parse JSON, filter arrays, and normalize data inline\n\n## Installation\n\n```bash\n# pnpm\npnpm add valchecker\n\n# npm\nnpm install valchecker\n\n# yarn\nyarn add valchecker\n\n# bun\nbun add valchecker\n```\n\n**Requirements:** Node.js 18+ (ESM and CommonJS supported)\n\n## Quick Start\n\n### Basic Usage\n\n```typescript\nimport { allSteps, createValchecker } from 'valchecker'\n\n// Create a valchecker instance with all available steps\nconst v = createValchecker({ steps: allSteps })\n\n// Define a schema\nconst userSchema = v.object({\n  name: v.string().toTrimmed(),\n  email: v.string().toLowercase(),\n  age: v.number().min(0),\n})\n\n// Validate data\nconst result = await userSchema.execute({\n  name: '  Alice  ',\n  email: 'ALICE@EXAMPLE.COM',\n  age: 25,\n})\n\nif (v.isSuccess(result)) {\n  console.log(result.value)\n  // { name: 'Alice', email: 'alice@example.com', age: 25 }\n} else {\n  console.error(result.issues)\n  // Array of structured validation issues\n}\n```\n\n### Tree-Shakable Imports (Production)\n\n```typescript\nimport { createValchecker, number, object, string, min, toTrimmed, toLowercase } from 'valchecker'\n\n// Import only the steps you need\nconst v = createValchecker({\n  steps: [string, number, object, min, toTrimmed, toLowercase]\n})\n```\n\n### Optional Properties\n\n```typescript\nconst schema = v.object({\n  name: v.string(),\n  nickname: [v.string()], // Wrap in [] for optional\n})\n\nschema.execute({ name: 'Alice' })\n// { value: { name: 'Alice', nickname: undefined } }\n```\n\n### Async Validation\n\n```typescript\nconst usernameSchema = v.string()\n  .toTrimmed()\n  .toLowercase()\n  .min(3, 'Username must be at least 3 characters')\n  .check(async (value) =\u003e {\n    const exists = await db.users.exists({ username: value })\n    return exists ? 'Username already taken' : true\n  })\n\nconst result = await usernameSchema.execute('Alice')\n```\n\n### Transforms and Fallbacks\n\n```typescript\nconst configSchema = v.unknown()\n  .parseJSON('Invalid JSON')\n  .fallback(() =\u003e ({ port: 3000 }))\n  .use(\n    v.object({\n      port: v.number().integer().min(1).max(65535),\n    })\n  )\n\nconst result = await configSchema.execute('{\"port\": 8080}')\n// { value: { port: 8080 } }\n\nconst fallbackResult = await configSchema.execute('invalid json')\n// { value: { port: 3000 } }\n```\n\n### Custom Error Messages\n\n```typescript\n// Per-step messages\nconst schema = v.number()\n  .min(1, 'Quantity must be at least 1')\n  .max(100, ({ payload }) =\u003e `Maximum is 100, got ${payload.value}`)\n\n// Global message handler\nconst v = createValchecker({\n  steps: allSteps,\n  message: ({ code, payload }) =\u003e {\n    const messages = {\n      'string:expected_string': 'Please enter text',\n      'number:expected_number': 'Please enter a number',\n      'min:expected_min': `Minimum value is ${payload.expected}`,\n    }\n    return messages[code] ?? 'Validation failed'\n  },\n})\n```\n\n## API Reference\n\n### Primitives\n\n| Step | Description | Issue Code |\n|------|-------------|------------|\n| `string(message?)` | Validates string values | `string:expected_string` |\n| `number(message?)` | Validates finite numbers | `number:expected_number` |\n| `boolean(message?)` | Validates boolean values | `boolean:expected_boolean` |\n| `bigint(message?)` | Validates bigint values | `bigint:expected_bigint` |\n| `symbol(message?)` | Validates symbol values | `symbol:expected_symbol` |\n| `literal(value, message?)` | Matches exact literal value | `literal:expected_literal` |\n| `null_(message?)` | Accepts only null | `null:expected_null` |\n| `undefined_(message?)` | Accepts only undefined | `undefined:expected_undefined` |\n| `unknown()` | Accepts any value | - |\n| `never(message?)` | Always fails | `never:unexpected_value` |\n| `any()` | Accepts any value (typed as any) | - |\n\n### Structures\n\n| Step | Description | Issue Code |\n|------|-------------|------------|\n| `object(shape, message?)` | Validates object with schema | `object:expected_object` |\n| `strictObject(shape, message?)` | Rejects unknown keys | `object:unknown_key` |\n| `looseObject(shape, message?)` | Allows unknown keys (alias for object) | `object:expected_object` |\n| `array(schema, message?)` | Validates array elements | `array:expected_array` |\n| `union(schemas)` | First matching schema wins | (from branches) |\n| `intersection(schemas)` | Merges all schema results | (from schemas) |\n| `instance(constructor, message?)` | Validates class instances | `instance:expected_instance` |\n\n### Constraints\n\n| Step | Description | Issue Code |\n|------|-------------|------------|\n| `min(value, message?)` | Minimum value/length | `min:expected_min` |\n| `max(value, message?)` | Maximum value/length | `max:expected_max` |\n| `integer(message?)` | Validates integer numbers | `integer:expected_integer` |\n| `empty(message?)` | Validates empty string/array | `empty:expected_empty` |\n| `startsWith(prefix, message?)` | String starts with prefix | `startsWith:expected_starts_with` |\n| `endsWith(suffix, message?)` | String ends with suffix | `endsWith:expected_ends_with` |\n\n### Transforms\n\n| Step | Description |\n|------|-------------|\n| `toTrimmed()` | Trim whitespace from both ends |\n| `toTrimmedStart()` | Trim whitespace from start |\n| `toTrimmedEnd()` | Trim whitespace from end |\n| `toUppercase()` | Convert to uppercase |\n| `toLowercase()` | Convert to lowercase |\n| `toFiltered(predicate)` | Filter array elements |\n| `toSorted(compareFn?)` | Sort array |\n| `toSliced(start, end?)` | Slice array |\n| `toSplitted(separator)` | Split string into array |\n| `toLength()` | Get string/array length |\n| `toString()` | Convert number to string |\n| `parseJSON(message?)` | Parse JSON string |\n| `stringifyJSON(message?)` | Stringify to JSON |\n\n### Flow Control\n\n| Step | Description | Issue Code |\n|------|-------------|------------|\n| `check(predicate, message?)` | Custom validation logic | `check:failed` |\n| `transform(fn, message?)` | Transform value | `transform:failed` |\n| `fallback(getValue)` | Provide fallback on failure | `fallback:failed` |\n| `use(schema)` | Delegate to another schema | (from target) |\n| `as\u003cT\u003e()` | Type assertion (no runtime check) | - |\n| `generic\u003cT\u003e(factory)` | Recursive schema support | - |\n| `toAsync()` | Force async execution | - |\n\n## Comparison with Other Libraries\n\n| Feature | valchecker | Zod | Yup | Valibot |\n|---------|------------|-----|-----|---------|\n| Bundle Size (min+gzip) | ~3KB* | ~14KB | ~15KB | ~1KB |\n| Tree-Shakable | Yes | Partial | No | Yes |\n| Full Type Inference | Yes | Yes | Partial | Yes |\n| Async Validation | Yes | Yes | Yes | Yes |\n| Standard Schema V1 | Yes | Yes | No | Yes |\n| Transform Pipeline | Yes | Yes | Yes | Yes |\n| Custom Plugins | Yes | No | No | No |\n| Deterministic Errors | Yes | Partial | Partial | Yes |\n\n*With selective imports; ~8KB with allSteps\n\n## FAQ\n\n### How do I handle optional fields?\n\nWrap the schema in an array `[]`:\n\n```typescript\nconst schema = v.object({\n  required: v.string(),\n  optional: [v.string()], // undefined is allowed\n})\n```\n\n### How do I validate discriminated unions?\n\nUse `union` with `literal` for the discriminant:\n\n```typescript\nconst eventSchema = v.union([\n  v.object({\n    type: v.literal('click'),\n    x: v.number(),\n    y: v.number(),\n  }),\n  v.object({\n    type: v.literal('keypress'),\n    key: v.string(),\n  }),\n])\n```\n\n### How do I create recursive schemas?\n\nUse `generic` for self-referential types:\n\n```typescript\ninterface TreeNode {\n  value: number\n  children?: TreeNode[]\n}\n\nconst nodeSchema = v.object({\n  value: v.number(),\n  children: [v.array(\n    v.generic\u003c{ output: TreeNode }\u003e(() =\u003e nodeSchema as any)\n  )],\n})\n```\n\n### How do I get the inferred type from a schema?\n\nUse TypeScript's `Awaited` and `ReturnType`:\n\n```typescript\nconst schema = v.object({ name: v.string() })\n\ntype SchemaOutput = Awaited\u003cReturnType\u003ctypeof schema.execute\u003e\u003e extends { value: infer T } ? T : never\n// { name: string }\n```\n\n### Why use `execute()` instead of `parse()`?\n\nValchecker returns a discriminated union result instead of throwing errors:\n\n```typescript\nconst result = await schema.execute(input)\n\nif (v.isSuccess(result)) {\n  // result.value is typed\n} else {\n  // result.issues contains structured errors\n}\n```\n\nThis pattern enables:\n- Type-safe error handling without try/catch\n- Collecting multiple validation errors\n- Deterministic behavior without exceptions\n\n### How do I integrate with form libraries?\n\nMap the issues array to your form's error format:\n\n```typescript\nconst result = await schema.execute(formData)\n\nif (v.isFailure(result)) {\n  const errors = Object.fromEntries(\n    result.issues.map(issue =\u003e [\n      issue.path.join('.'),\n      issue.message\n    ])\n  )\n  // { 'user.email': 'Invalid email format' }\n}\n```\n\n## Contributing\n\nContributions are welcome! Please read our contributing guidelines:\n\n1. Fork the repository\n2. Create a feature branch: `git checkout -b feat/my-feature`\n3. Make your changes following the code style in `AGENTS.md`\n4. Run verification: `pnpm lint \u0026\u0026 pnpm typecheck \u0026\u0026 pnpm test`\n5. Commit with conventional commits: `git commit -m \"feat: add new feature\"`\n6. Push and create a Pull Request\n\n### Development Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/DevilTea/valchecker.git\ncd valchecker\n\n# Install dependencies\npnpm install\n\n# Build all packages\npnpm build\n\n# Run tests\npnpm test\n\n# Start docs dev server\npnpm docs:dev\n```\n\n## Documentation\n\nFull documentation is available at [https://deviltea.github.io/valchecker/](https://deviltea.github.io/valchecker/)\n\n- [Quick Start Guide](https://deviltea.github.io/valchecker/guide/quick-start)\n- [Core Philosophy](https://deviltea.github.io/valchecker/guide/core-philosophy)\n- [API Reference](https://deviltea.github.io/valchecker/api/overview)\n- [Examples](https://deviltea.github.io/valchecker/examples/async-validation)\n\n## License\n\n[MIT](./LICENSE) License © 2025-PRESENT [DevilTea](https://github.com/DevilTea)\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/valchecker?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[npm-version-href]: https://npmjs.com/package/valchecker\n[npm-downloads-src]: https://img.shields.io/npm/dm/valchecker?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[npm-downloads-href]: https://npmjs.com/package/valchecker\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/valchecker?style=flat\u0026colorA=080f12\u0026colorB=1fa669\u0026label=minzip\n[bundle-href]: https://bundlephobia.com/result?p=valchecker\n[license-src]: https://img.shields.io/github/license/DevilTea/valchecker.svg?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[license-href]: https://github.com/DevilTea/valchecker/blob/main/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeviltea%2Fvalchecker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeviltea%2Fvalchecker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeviltea%2Fvalchecker/lists"}