{"id":21707888,"url":"https://github.com/thanhhoajs/validator","last_synced_at":"2026-02-12T10:32:28.336Z","repository":{"id":248147580,"uuid":"827849040","full_name":"thanhhoajs/validator","owner":"thanhhoajs","description":"A powerful and flexible validation library for the @thanhhoajs ecosystem, optimized for high performance with Bun and TypeScript","archived":false,"fork":false,"pushed_at":"2024-10-30T09:16:19.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-08T23:16:20.071Z","etag":null,"topics":["bun","thanhhoa","thanhhoajs","validator"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@thanhhoajs/validator","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/thanhhoajs.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}},"created_at":"2024-07-12T14:06:02.000Z","updated_at":"2024-10-30T09:16:23.000Z","dependencies_parsed_at":"2025-04-12T16:17:19.697Z","dependency_job_id":"7e38a4b4-6f51-4a58-8449-6fe059af97b6","html_url":"https://github.com/thanhhoajs/validator","commit_stats":null,"previous_names":["thanhhoajs/validator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thanhhoajs/validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanhhoajs%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanhhoajs%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanhhoajs%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanhhoajs%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thanhhoajs","download_url":"https://codeload.github.com/thanhhoajs/validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thanhhoajs%2Fvalidator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29363153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"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":["bun","thanhhoa","thanhhoajs","validator"],"created_at":"2024-11-25T22:19:42.251Z","updated_at":"2026-02-12T10:32:28.318Z","avatar_url":"https://github.com/thanhhoajs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://drive.google.com/uc?export=view\u0026id=1_M5tYoaKfXpqsOAPQl3WVWs9u5NWrG76\" alt=\"ThanhHoa Logo\" width=\"300\"/\u003e\n\u003c/p\u003e\n\n# @thanhhoajs/validator\n\nA powerful and flexible validation library for the @thanhhoajs ecosystem, optimized for high performance with Bun and TypeScript.\n\n## Features\n\n- 🚀 High Performance: Optimized to work blazingly fast with the Bun runtime.\n- 🔍 TypeScript Ready: Fully written in TypeScript, providing complete type definitions.\n- 🔧 Easily Customizable: Flexible configuration with two methods - field-by-field and configuration object.\n- 🧪 Thoroughly Tested: Includes a comprehensive test suite to ensure reliability.\n- 🔗 Chainable API: Intuitive and easy-to-use chainable methods for defining validation rules.\n- 🌐 Extensible: Easily add custom validation rules to suit your specific needs.\n\n## Installation\n\n```bash\nbun add @thanhhoajs/validator\n```\n\n## Usage\n\n@thanhhoajs/validator provides two main methods for defining validation rules: the field method and the configuration method.\n\n### Using the Field Method\n\nThe field method allows you to define validation rules for each field individually.\n\n```typescript\nimport { createValidator } from '@thanhhoajs/validator';\n\nconst validator = createValidator();\n\nvalidator.field('username').required().string().min(3).max(20);\nvalidator.field('email').required().email();\nvalidator.field('age').number().min(18);\n\nconst data = {\n  username: 'khanhnguyen',\n  email: 'khanh@example.com',\n  age: 22,\n};\n\nconst errors = validator.validate(data);\nconsole.log(errors); // [] (empty array if validation passes)\n```\n\n### Using the Configuration Method\n\nThe configuration method allows you to define all validation rules in a single configuration object.\n\n```typescript\nimport { createValidator } from '@thanhhoajs/validator';\n\nconst validator = createValidator();\n\nvalidator.configure({\n  username: (field) =\u003e field.required().string()min(3).max(20),\n  email: (field) =\u003e field.required().email(),\n  age: (field) =\u003efield.number().min(18),\n});\n\nconst data = {\n  username: 'hanhthan',\n  email: 'hanh@example.com',\n  age: 22,\n};\n\nconst errors = validator.validate(data);\nconsole.log(errors); // [] (empty array if validation passes)\n```\n\n## API Overview\n\n### Validator Methods\n\n- `field(name: string)`: Starts the definition of validation rules for a specific field.\n- `configure(config: Record\u003cstring, (field: FieldValidator) =\u003e void\u003e)`: Configures validation rules using an object.\n- `validate(data: Record\u003cstring, any\u003e)`: Validates the provided data against the defined rules.\n\n### Field Validator Methods\n\n- `required(message?: string)`: Marks the field as required.\n- `string(message?: string)`: Validates that the field is a string.\n- `number(message?: string)`: Validates that the field is a number.\n- `boolean(message?: string)`: Validates that the field is a boolean.\n- `email(message?: string)`: Validates that the field is a valid email address.\n- `min(limit: number, message?: string)`: Validates the minimum value or length.\n- `max(limit: number, message?: string)`: Validates the maximum value or length.\n- `enum(allowedValues: string[], message?: string)`: Validates that the value is one of the allowed values.\n- `custom(validate: (value: any) =\u003e boolean | string, message?: string)`: Adds a custom validation rule.\n- `lowercase(message?: string)`: Validates that the field is in lowercase.\n- `uppercase(message?: string)`: Validates that the field is in uppercase.\n- `alphanumeric(message?: string)`: Validates that the field contains only letters and numbers.\n- `length(min: number, max?: number, message?: string)`: Validates that the string length is within a certain range.\n- `pattern(regex: RegExp, message?: string)`: Validates that the field matches a specific regex pattern.\n- `date(message?: string)`: Validates that the field is a valid date.\n- `url(message?: string)`: Validates that the field is a valid URL.\n- `trim(message?: string)`: Validates that the field has no leading or trailing whitespace.\n- `noWhitespace(message?: string)`: Validates that the field contains no whitespace.\n\n## Advanced Usage\n\n### Custom Validation Rules\n\nYou can easily add custom validation rules to suit your specific needs:\n\n```typescript\nvalidator\n  .field('password')\n  .required('Password is required')\n  .min(8, 'Password must be at least 8 characters long')\n  .custom(\n    (value) =\u003e /[A-Z]/.test(value) \u0026\u0026 /[0-9]/.test(value),\n    'Password must contain at least one uppercase letter and one number',\n  );\n```\n\n## Author\n\nNguyen Nhu Khanh \u003ckwalker.nnk@gmail.com\u003e\n\n## License\n\n[MIT License](https://github.com/thanhhoajs/validator?tab=MIT-1-ov-file)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthanhhoajs%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthanhhoajs%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthanhhoajs%2Fvalidator/lists"}