{"id":16110057,"url":"https://github.com/calbabreaker/validation-chainer","last_synced_at":"2025-04-06T05:25:43.715Z","repository":{"id":57390321,"uuid":"328317119","full_name":"Calbabreaker/validation-chainer","owner":"Calbabreaker","description":"A tool to validate your inputs in a visualy pleasing and flexible way.","archived":false,"fork":false,"pushed_at":"2021-11-03T11:34:42.000Z","size":351,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-24T14:08:58.351Z","etag":null,"topics":[],"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/Calbabreaker.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}},"created_at":"2021-01-10T06:17:34.000Z","updated_at":"2022-11-03T02:45:13.000Z","dependencies_parsed_at":"2022-09-12T22:53:45.239Z","dependency_job_id":null,"html_url":"https://github.com/Calbabreaker/validation-chainer","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Calbabreaker%2Fvalidation-chainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Calbabreaker%2Fvalidation-chainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Calbabreaker%2Fvalidation-chainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Calbabreaker%2Fvalidation-chainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Calbabreaker","download_url":"https://codeload.github.com/Calbabreaker/validation-chainer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247439885,"owners_count":20939183,"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":"2024-10-09T19:35:20.719Z","updated_at":"2025-04-06T05:25:43.694Z","avatar_url":"https://github.com/Calbabreaker.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Validation Chainer\n\nA tool to validate your inputs in a visualy pleasing and flexible way.\n\n[![npm](https://img.shields.io/npm/v/validation-chainer.svg)](https://www.npmjs.com/package/validation-chainer)\n\n## Install\n\nWith npm:\n\n```sh\nnpm install validation-chainer\n```\n\nWith yarn:\n\n```sh\nyarn add validation-chainer\n```\n\n## Usage\n\nBasic Usage:\n\n```js\nimport { startChain } from \"validation-chainer\";\n\nconst data = {\n    foo: \"yes\",\n    bar: \"PLEASE\",\n};\n\n// starts the chain with the data\n// await is used here because pack returns a promise\nconst errors = await startChain(data)\n    // starts check on foo\n    .check(\"foo\")\n    // does some validation with the property foo (foo's value is used as an argument)\n    .validate((foo) =\u003e foo typeof \"string\", \"Foo is not a string\")\n    .validate((foo) =\u003e foo.length \u003e= 8, \"Foo must be at least 8 characters\")\n\n    .check(\"bar\")\n    // makes bar lower case (modifies the object getting passed in) so bar is now please\n    .sanitize((bar) =\u003e bar.toLowerCase())\n    .validate((bar) =\u003e bar == \"please\")\n\n    // make sure to call this!\n    .pack();\n\n// check to see if there are any errors\nif (errors.length \u003e 0)\n    // there should only be one error\n    console.error(errors);\n```\n\nLogs in console:\n\n```js\n[\n    {\n        property: \"foo\",\n        message: \"Foo must be at least 8 characters\",\n    },\n];\n```\n\n---\n\nLogin verify example:\n\n```js\nimport { startChain } from \"validation-chainer\";\nimport argon2 from \"argon2\";\n\nconst data = {\n    username: \"bob\",\n    password: \"very strong password\",\n};\n\nconst user = await database.findOne({ username: data.username });\n\nconst errors = await startChain(data)\n    .check(\"username\")\n    .validate(() =\u003e user != null, \"Username doesn't exist\")\n\n    .check(\"password\")\n    // makes sure username is valid first\n    .ensure(\"username\", \"Username is invalid\")\n    // checks password using asynchronous hashing algorithm\n    .validate(\n        async (storedPass) =\u003e await argon2.verify(storedPass, user.password),\n        \"Password is incorrect\"\n    )\n\n    .pack();\n```\n\n---\n\nUsing the [validator](https://www.npmjs.com/package/validator) library:\n\n```js\nimport { startChain } from \"validation-chainer\";\nimport validator from \"validator\";\n\nconst data = {\n    name: \"                 💩      \",\n};\n\nconst errors = await startChain(data)\n    .check(\"name\")\n    // removes whitespace at the beggining and end of name so it's now just \"💩\"\n    .sanitize(validator.stripLow)\n    .sanitize(validator.trim)\n    // property fails here because of the 💩\n    .validate(validator.isAlphaNumeric, \"Name must contain valid alpha-numeric characters\")\n\n    .pack();\n```\n\n---\n\nUsing TypeScript:\n\n```ts\nimport { startChain } from \"validation-chainer\";\n\nconst data = {\n    status: \"sad\",\n};\n\n// starts chain that's specialized with data\nconst errors = await startChain(data)\n    // intilisense info on object\n    .check(\"status\")\n    // optional type generics on function (default is any)\n    .validate\u003cstring\u003e((status) =\u003e status === \"happy\", \"Why are you not happy\")\n    .sanitize\u003cstring\u003e((status) =\u003e status.toUpperCase())\n\n    .pack();\n```\n\n### Documentation\n\nThe documentation is in the source code written in jsdoc (with typescript).\nIDE's like vscode will be able to show it while developing.\nThere might be plans to convert it into markdown or html in the future.\n\n## Development\n\nInstall packages first: (using yarn)\n\n```sh\npnpm install\n```\n\nChange Code.\n\nDo tests:\n\n```sh\npnpm test\n```\n\nDo linting:\n\n```sh\npnpm lint\n```\n\nBuild:\n\n```sh\npnpm build\n```\n\nProfit! All of this will also be automatically ran with github actions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalbabreaker%2Fvalidation-chainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalbabreaker%2Fvalidation-chainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalbabreaker%2Fvalidation-chainer/lists"}