{"id":14155544,"url":"https://github.com/joiful-ts/joiful","last_synced_at":"2025-04-04T14:09:59.367Z","repository":{"id":8395895,"uuid":"58247556","full_name":"joiful-ts/joiful","owner":"joiful-ts","description":"TypeScript Declarative Validation for Joi","archived":false,"fork":false,"pushed_at":"2023-03-07T20:37:43.000Z","size":2699,"stargazers_count":237,"open_issues_count":35,"forks_count":18,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T13:11:07.716Z","etag":null,"topics":["constraints","declarative-validation","decorators","javascript","joi","joi-constraints","nodejs","schema","typescript","validation","validator"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joiful-ts.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/package.ts","governance":null,"roadmap":null,"authors":null}},"created_at":"2016-05-07T03:34:01.000Z","updated_at":"2025-01-03T12:39:06.000Z","dependencies_parsed_at":"2024-01-14T04:44:09.345Z","dependency_job_id":"17326589-9cd1-42ca-bec7-525b8e11f1f6","html_url":"https://github.com/joiful-ts/joiful","commit_stats":{"total_commits":281,"total_committers":10,"mean_commits":28.1,"dds":0.5693950177935942,"last_synced_commit":"f0c977ba09b66bb0368b436c8fb478dda7040153"},"previous_names":["laurence-myers/tsdv-joi"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joiful-ts%2Fjoiful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joiful-ts%2Fjoiful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joiful-ts%2Fjoiful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joiful-ts%2Fjoiful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joiful-ts","download_url":"https://codeload.github.com/joiful-ts/joiful/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190255,"owners_count":20898702,"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":["constraints","declarative-validation","decorators","javascript","joi","joi-constraints","nodejs","schema","typescript","validation","validator"],"created_at":"2024-08-17T08:03:49.494Z","updated_at":"2025-04-04T14:09:59.351Z","avatar_url":"https://github.com/joiful-ts.png","language":"TypeScript","readme":"\u003cbr /\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=\"500\" src=\"https://raw.githubusercontent.com/joiful-ts/joiful/master/img/logo-icon-with-text-800x245.png\"\u003e\n    \u003ch3 align=\"center\" style=\"margin-top: 0px; padding-top: 0\"\u003eTypeScript Declarative Validation for Joi\u003c/h3\u003e\n\u003c/p\u003e\n\n\u003cbr /\u003e\n\n[![npm version](https://badge.fury.io/js/joiful.svg)](https://badge.fury.io/js/joiful)\n[![GitHub Actions Build Status](https://github.com/joiful-ts/joiful/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/joiful-ts/joiful/actions/workflows/build.yml)\n[![codecov](https://codecov.io/gh/joiful-ts/joiful/branch/master/graph/badge.svg)](https://codecov.io/gh/joiful-ts/joiful)\n[![Dependabot Status](https://api.dependabot.com/badges/status?host=github\u0026repo=joiful-ts/joiful)](https://dependabot.com)\n\n[API Docs](https://joiful-ts.github.io/joiful/)\n\n## Why Joiful?\n\nThis lib allows you to apply Joi validation constraints on class properties, by using decorators.\n\nThis means you can combine your type schema and your validation schema in one go!\n\nCalling `Validator.validateAsClass()` allows you to validate any object as if it were an instance of a given class.\n\n## Installation\n\n`npm add joiful reflect-metadata`\n\nOr\n\n`yarn add joiful reflect-metadata`.\n\nYou must enable experimental decorators and metadata in your TypeScript configuration.\n\n`tsconfig.json`\n\n```json\n{\n  \"compilerOptions\": {\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true\n  }\n}\n```\n\n## Basic Usage\n\nEnsure you import `reflect-metadata` as the first import in your application's entry point.\n\n`index.ts`\n\n```typescript\nimport 'reflect-metadata';\n\n...\n```\n\nThen you can start using joiful like this.\n\n```typescript\nimport * as jf from 'joiful';\n\nclass SignUp {\n  @jf.string().required()\n  username: string;\n\n  @jf\n    .string()\n    .required()\n    .min(8)\n  password: string;\n\n  @jf.date()\n  dateOfBirth: Date;\n\n  @jf.boolean().required()\n  subscribedToNewsletter: boolean;\n}\n\nconst signUp = new SignUp();\nsignUp.username = 'rick.sanchez';\nsignUp.password = 'wubbalubbadubdub';\n\nconst { error } = jf.validate(signUp);\n\nconsole.log(error); // Error will either be undefined or a standard joi validation error\n```\n\n## Validate plain old javascript objects\n\nDon't like creating instances of classes? Don't worry, you don't have to. You can validate a plain old javascript object as if it were an instance of a class.\n\n```typescript\nconst signUp = {\n  username: 'rick.sanchez',\n  password: 'wubbalubbadubdub',\n};\n\nconst result = jf.validateAsClass(signUp, SignUp);\n```\n\n## Custom decorator constraints\n\nWant to create your own shorthand versions of decorators? Simply create a function like below.\n\n`customDecorators.ts`\n\n```typescript\nimport * as jf from 'joiful';\n\nconst password = () =\u003e\n  jf\n    .string()\n    .min(8)\n    .regex(/[a-z]/)\n    .regex(/[A-Z]/)\n    .regex(/[0-9]/)\n    .required();\n```\n\n`changePassword.ts`\n\n```typescript\nimport { password } from './customDecorators';\n\nclass ChangePassword {\n  @password()\n  newPassword: string;\n}\n```\n\n## Validating array properties\n\n```typescript\nclass SimpleTodoList {\n  @jf.array().items(joi =\u003e joi.string())\n  todos?: string[];\n}\n```\n\nTo validate an array of objects that have their own joiful validation:\n\n```typescript\nclass Actor {\n  @string().required()\n  name!: string;\n}\n\nclass Movie {\n  @string().required()\n  name!: string;\n\n  @array({ elementClass: Actor }).required()\n  actors!: Actor[];\n}\n```\n\n## Validating object properties\n\nTo validate an object subproperty that has its own joiful validation:\n\n```typescript\nclass Address {\n  @string()\n  line1?: string;\n\n  @string()\n  line2?: string;\n\n  @string().required()\n  city!: string;\n\n  @string().required()\n  state!: string;\n\n  @string().required()\n  country!: string;\n}\n\nclass Contact {\n  @string().required()\n  name!: string;\n\n  @object().optional()\n  address?: Address;\n}\n```\n\n## API Docs\n\njoiful has extensive JSDoc / TSDoc comments.\n\n[You can browse the generated API docs online.](https://joiful-ts.github.io/joiful/)\n\n## Got a question?\n\nThe joiful API is designed to closely match the joi API. One exception is validating the length of a `string`, `array`, etc, which is performed using `.exactLength(n)` rather than `.length(n)`. If you're familiar with the joi API, you should find joiful very easy to pickup.\n\nIf there's something you're not sure of you can see how it's done by looking at the unit tests. There is 100% coverage so most likely you'll find your scenario there. Otherwise feel free to [open an issue](https://github.com/joiful-ts/joiful/issues).\n\n## Contributing\n\nGot an issue or a feature request? [Log it](https://github.com/joiful-ts/joiful/issues).\n\n[Pull-requests](https://github.com/joiful-ts/joiful/pulls) are also very welcome.\n\n## Alternatives\n\n- [class-validator](https://github.com/typestack/class-validator): usable in both Node.js and the browser. Mostly designed for validating string values. Can't validate plain objects, only class instances.\n- [joi-extract-type](https://github.com/TCMiranda/joi-extract-type): provides native type extraction from Joi Schemas. Augments the Joi type definitions.\n- [typesafe-joi](https://github.com/hjkcai/typesafe-joi): automatically infers type information of validated objects, via the standard Joi schema API.\n","funding_links":[],"categories":["typescript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoiful-ts%2Fjoiful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoiful-ts%2Fjoiful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoiful-ts%2Fjoiful/lists"}