{"id":15416265,"url":"https://github.com/ooade/yooda","last_synced_at":"2025-04-13T09:07:08.245Z","repository":{"id":42825548,"uuid":"236551011","full_name":"ooade/yooda","owner":"ooade","description":"🧘‍♂️600b validation library with support for custom handlers and messages.","archived":false,"fork":false,"pushed_at":"2024-09-25T07:27:43.000Z","size":185,"stargazers_count":33,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T09:07:06.146Z","etag":null,"topics":["validation","validation-library","validator"],"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/ooade.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":"2020-01-27T17:35:41.000Z","updated_at":"2024-09-25T07:27:44.000Z","dependencies_parsed_at":"2023-02-04T06:46:27.170Z","dependency_job_id":"d14d43cc-2bb7-4313-b0a8-4a68432e6a3b","html_url":"https://github.com/ooade/yooda","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":"0.46153846153846156","last_synced_commit":"2d143f63547791132c16734c9bafc6860c5c1c7f"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ooade%2Fyooda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ooade%2Fyooda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ooade%2Fyooda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ooade%2Fyooda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ooade","download_url":"https://codeload.github.com/ooade/yooda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688569,"owners_count":21145766,"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":["validation","validation-library","validator"],"created_at":"2024-10-01T17:11:22.236Z","updated_at":"2025-04-13T09:07:08.215Z","avatar_url":"https://github.com/ooade.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003eYooda\u003c/h1\u003e\n  \u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/ooade/yooda/master/yoda.svg?sanitize=true\" alt=\"\" width=\"200px\" /\u003e\u003c/p\u003e\n  \u003cp align=\"center\"\u003e\"Do or do not. There is no try.\" - Yoda\u003c/p\u003e\n  \u003cp align=\"center\"\u003e🧘‍♂️600b validation library with custom handlers and messages.\u003c/p\u003e\n  \u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.org/package/yooda\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/yooda.svg?style=flat-square\" alt=\"npm\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/ooade/yooda\"\u003e\u003cimg src=\"https://img.shields.io/travis/ooade/yooda.svg?style=flat-square\" alt=\"travis\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ooade/yooda\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/yooda.svg?style=flat-square\" alt=\"downloads/month\"\u003e\u003c/a\u003e\n  \u003ca href=\"http://makeapullrequest.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/PR(s)-welcome-brightgreen.svg?style=flat-square\" alt=\"pullrequest\"\u003e\u003c/a\u003e\n  \u003ca href=\"http://www.firsttimersonly.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/first--timers--only-friendly-blue.svg?style=flat-square\" alt=\"firsttimersonly\"\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n## Contents\n\n- [Installation](#installation)\n- [Basic Usage](#basic-usage)\n- [Extras](#extras)\n  - [Domain](#domain)\n  - [Custom Error Messages](#custom-error-messages)\n\n### Installation\n\n```sh\nnpm add yooda\n```\n\n### Basic Usage\n\n```js\nimport validator from \"yooda\";\n\nconst requestBodySchema = {\n\tname: {\n\t\ttype: \"string\",\n\t\trequired: true\n\t},\n\tage: {\n\t\ttype: \"number\",\n\t\trequired: true\n\t}\n};\n\nconst requestBody = {\n\tname: \"Ademola Adegbuyi\",\n\tage: 23\n};\n\ntry {\n\tconst validate = validator(requestBodySchema);\n\tvalidate(requestBody);\n} catch (err) {\n\tres.status(500).send(err);\n}\n```\n\nThat's it, really. If the value doesn't meet the requirement, it throws an error and you can handle it as you want.\n\n### Extras\n\n#### Domain\n\nThis is more like a plugin, to ensure some other personal requirements are met asides from the regular \"required\" and \"type\". We definitely cannot offer a way to solve all kinds of edge-cases so we're giving you a buffet; Be your own boss, control the nature of the validation.\n\nHere's how to use it:\n\n```js\nconst shouldStartWithA = value =\u003e value.startsWith(\"a\");\n// attach it to your schema\nconst requestBodySchema = {\n\tname: {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tdomain: [shouldStartWithA]\n\t}\n};\nconst validate = validator(requestBodySchema);\nvalidate(requestBody);\n```\n\nThe convention you decide to pick is up to you. The one used in the example above is a function that is used on the fly. You could just create an object of domains as done in the test file. You could also have them in a separate file and import only the ones needed.\n\n#### Custom Error Messages\n\nYou could define how errors will be thrown based on the supported error types (requiredError, typeError, and domainError), and it's very easy to use! A short example:\n\n```ts\nconst schema: Schema = {\n\tage: {\n\t\ttype: \"number\",\n\t\trequired: true,\n\t\tdomain: [domains.IS_POSITIVE]\n\t}\n};\n\nconst customErrorHandlers: CustomErrorHandlers = {\n\tdomainError: ({ value, domain }) =\u003e\n\t\t`${value} doesn't satify the ${domain} requirement`\n};\n\nconst validate = validator(schema, customErrorHandlers);\n```\n\n**Props available to the error types:**\n\nNote that: only the props required will be suggested to you via intellisense 🙏\n\n```ts\ntype RequiredErrorProps = {\n\tkey: string;\n};\n\ntype TypeErrorProps = {\n\tkey: string;\n\ttype: string;\n\tvalue: any;\n};\n\ntype DomainErrorProps = {\n\tkey: string;\n\ttype: string;\n\tvalue: any;\n\tdomain: string;\n};\n```\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fooade%2Fyooda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fooade%2Fyooda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fooade%2Fyooda/lists"}