{"id":23167312,"url":"https://github.com/hoonapps/kr-validators","last_synced_at":"2025-04-04T22:14:25.584Z","repository":{"id":264623588,"uuid":"893879614","full_name":"hoonapps/kr-validators","owner":"hoonapps","description":"Custom validation decorators for Korean-specific data such as resident IDs, phone numbers, business numbers, card numbers, emails, and postal codes.   This library is designed to work seamlessly with NestJS and `class-validator` for a clean, reusable validation process.","archived":false,"fork":false,"pushed_at":"2024-11-25T13:31:29.000Z","size":94,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T06:43:39.645Z","etag":null,"topics":["class-validator","korea","nestjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/kr-validators","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/hoonapps.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-11-25T11:19:39.000Z","updated_at":"2024-11-26T05:55:14.000Z","dependencies_parsed_at":"2024-11-25T12:40:50.975Z","dependency_job_id":null,"html_url":"https://github.com/hoonapps/kr-validators","commit_stats":null,"previous_names":["hoonapps/kr-validators"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoonapps%2Fkr-validators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoonapps%2Fkr-validators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoonapps%2Fkr-validators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoonapps%2Fkr-validators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoonapps","download_url":"https://codeload.github.com/hoonapps/kr-validators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256110,"owners_count":20909240,"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":["class-validator","korea","nestjs"],"created_at":"2024-12-18T02:27:29.651Z","updated_at":"2025-04-04T22:14:25.561Z","avatar_url":"https://github.com/hoonapps.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo-small.svg\" width=\"120\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456\n[circleci-url]: https://circleci.com/gh/nestjs/nest\n\n  \u003cp align=\"center\"\u003eA progressive \u003ca href=\"http://nodejs.org\" target=\"_blank\"\u003eNode.js\u003c/a\u003e framework for building efficient and scalable server-side applications.\u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@nestjs/core.svg\" alt=\"NPM Version\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@nestjs/core.svg\" alt=\"Package License\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@nestjs/common.svg\" alt=\"NPM Downloads\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://circleci.com/gh/nestjs/nest\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/circleci/build/github/nestjs/nest/master\" alt=\"CircleCI\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/nestjs/nest?branch=master\" target=\"_blank\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9\" alt=\"Coverage\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://discord.gg/G7Qnnhy\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/discord-online-brightgreen.svg\" alt=\"Discord\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/nest#backer\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/nest/backers/badge.svg\" alt=\"Backers on Open Collective\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/nest#sponsor\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/nest/sponsors/badge.svg\" alt=\"Sponsors on Open Collective\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://paypal.me/kamilmysliwiec\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/Donate-PayPal-ff3f59.svg\" alt=\"Donate us\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://opencollective.com/nest#sponsor\"  target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg\" alt=\"Support us\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://twitter.com/nestframework\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/nestframework.svg?style=social\u0026label=Follow\" alt=\"Follow us on Twitter\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n  \u003c!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)\n  [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)--\u003e\n\n# kr-validators\n\nCustom validation decorators for Korean-specific data such as **resident IDs, phone numbers, business numbers, card numbers, emails, and postal codes**.  \nThis library is designed to work seamlessly with NestJS and `class-validator` for a clean, reusable validation process.\n\n---\n\n## Features\n\n- **Resident ID Validator**: Validate Korean resident identification numbers.\n- **Phone Number Validator**: Validate Korean phone numbers.\n- **Business Number Validator**: Validate Korean business registration numbers.\n- **Email Validator**: Validate email addresses.\n- **Postal Code Validator**: Validate Korean postal codes.\n- Lightweight and optimized for **NestJS** applications.\n- Fully compatible with **class-validator**.\n\n---\n\n## Installation\n\nInstall the package via NPM:\n\n```bash\nnpm install kr-validators\n```\n\n---\n\n## Usage\n\n### NestJS Integration Example\n\n#### 1. Import and apply the decorators in your DTO\n\n```typescript\nimport {\n  IsEmail,\n  IsPhoneNumber,\n  IsResidentIDNumber,\n  IsBusinessNumber,\n  IsPostalCode,\n} from 'kr-validators';\n\nexport class CreateUserDto {\n  @IsEmail({ message: '유효한 이메일 주소를 입력해주세요.' })\n  email: string;\n\n  @IsPhoneNumber({ message: '유효하지 않은 전화번호입니다.' })\n  phone: string;\n\n  @IsResidentIDNumber({ message: '유효하지 않은 주민등록번호입니다.' })\n  residentId: string;\n\n  @IsBusinessNumber({ message: '유효하지 않은 사업자등록번호입니다.' })\n  businessNumber: string;\n\n  @IsPostalCode({ message: '유효하지 않은 우편번호입니다.' })\n  postalCode: string;\n}\n```\n\n#### 2. Apply the DTO in your controller\n\nUse the `CreateUserDto` in your NestJS controller to validate incoming request data automatically.\n\n```typescript\nimport { Body, Controller, Post } from '@nestjs/common';\nimport { CreateUserDto } from './dto/create-user.dto';\n\n@Controller('users')\nexport class UserController {\n  @Post()\n  createUser(@Body() createUserDto: CreateUserDto) {\n    // The validation is automatically triggered when the request data is bound to the DTO.\n    return { message: 'User created successfully', data: createUserDto };\n  }\n}\n```\n\nIn this example:\n\n- **Automatic Validation**: The `CreateUserDto` class is automatically validated when the request body is bound to it.  \n  NestJS's built-in `ValidationPipe` triggers the validation process without requiring manual checks.\n- **Error Handling**: If the incoming data fails validation, a `400 Bad Request` response is returned automatically with detailed error messages.\n\n- **Successful Requests**: If the data passes validation, the `createUser` method is executed, and the validated data is returned in the response.\n\n---\n\n### Example Scenarios\n\n#### **Invalid Request Body**\n\n```json\n{\n  \"email\": \"not-an-email\",\n  \"phone\": \"123\",\n  \"residentId\": \"123456\",\n  \"businessNumber\": \"12345\",\n  \"postalCode\": \"123\"\n}\n```\n\n#### **Invalid Response**\n\nIf the incoming data fails validation, the API will return a **400 Bad Request** response with detailed error messages for each invalid field.\n\n```json\n{\n  \"statusCode\": 400,\n  \"message\": [\n    \"유효한 이메일 주소를 입력해주세요.\",\n    \"유효하지 않은 전화번호입니다.\",\n    \"유효하지 않은 주민등록번호입니다.\",\n    \"유효하지 않은 사업자등록번호입니다.\",\n    \"유효하지 않은 우편번호입니다.\"\n  ],\n  \"error\": \"Bad Request\"\n}\n```\n\nEach error message corresponds to the field that failed validation, making it easy to identify and correct issues in the request payload.\n\n---\n\n#### **Valid Request Body**\n\n```json\n{\n  \"email\": \"example@example.com\",\n  \"phone\": \"010-1234-5678\",\n  \"residentId\": \"9201011234567\",\n  \"businessNumber\": \"1234567890\",\n  \"postalCode\": \"06236\"\n}\n```\n\n#### **Successful Response**\n\n```json\n{\n  \"message\": \"User created successfully\",\n  \"data\": {\n    \"email\": \"example@example.com\",\n    \"phone\": \"010-1234-5678\",\n    \"residentId\": \"9201011234567\",\n    \"businessNumber\": \"1234567890\",\n    \"postalCode\": \"06236\"\n  }\n}\n```\n\nThis shows how custom validators integrate seamlessly into a NestJS controller. By defining validations in DTOs, you ensure that incoming data is always consistent and secure before reaching your application logic.\n\n---\n\n## Validation Rules\n\n1. **Resident ID Validator**:\n\n   - Must be 13 digits.\n   - Luhn algorithm-based checksum validation.\n\n2. **Phone Number Validator**:\n\n   - Formats: `010-1234-5678`, `01012345678`.\n\n3. **Business Number Validator**:\n\n   - 10-digit Korean business registration number.\n\n4. **Email Validator**:\n\n   - Standard email format validation.\n\n5. **Postal Code Validator**:\n   - Validates Korean postal codes (5-digit).\n\n---\n\n## API Reference\n\n### 1. **`@IsEmail(validationOptions?: ValidationOptions)`**\n\nValidates the email address.\n\n### 2. **`@IsPhoneNumber(validationOptions?: ValidationOptions)`**\n\nValidates the phone number in Korean formats.\n\n### 3. **`@IsResidentIdNumber(validationOptions?: ValidationOptions)`**\n\nValidates a Korean resident ID number.\n\n### 4. **`@IsBusinessNumber(validationOptions?: ValidationOptions)`**\n\nValidates a Korean business registration number.\n\n### 5. **`@IsPostalCode(validationOptions?: ValidationOptions)`**\n\nValidates a Korean postal code.\n\n---\n\n## Contributing\n\nWe welcome contributions! Please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch (`git checkout -b feature/my-feature`).\n3. Commit your changes (`git commit -m 'Add my feature'`).\n4. Push to the branch (`git push origin feature/my-feature`).\n5. Open a pull request.\n\n---\n\n## License\n\nThis project is licensed under the **MIT License**. See the [LICENSE](./LICENSE) file for details.\n\n---\n\n## Author\n\nCreated by **hoonapps**.  \nVisit the [GitHub Repository](https://github.com/hoonapps) for more projects.\n\n---\n\n### Need help?\n\nFeel free to reach out at **didgns10@gmali.com** or create an issue in the repository!\n","funding_links":["https://opencollective.com/nest","https://paypal.me/kamilmysliwiec"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoonapps%2Fkr-validators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoonapps%2Fkr-validators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoonapps%2Fkr-validators/lists"}