{"id":23410419,"url":"https://github.com/jadkhoury1/simple-body-validator","last_synced_at":"2025-04-07T10:20:17.988Z","repository":{"id":36996849,"uuid":"412386110","full_name":"jadKhoury1/simple-body-validator","owner":"jadKhoury1","description":"This package is inspired by Laravel validation mechanism, and aims to make body validation easier for Javascript developers","archived":false,"fork":false,"pushed_at":"2025-01-20T12:26:26.000Z","size":258,"stargazers_count":32,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-07T10:20:05.219Z","etag":null,"topics":["javascript","javascript-library","nodejs","validation"],"latest_commit_sha":null,"homepage":"https://simple-body-validator.com","language":"JavaScript","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/jadKhoury1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2021-10-01T08:21:27.000Z","updated_at":"2025-03-08T12:35:40.000Z","dependencies_parsed_at":"2024-06-12T17:23:51.136Z","dependency_job_id":"f6cf9679-3d79-4152-b688-b0baf1dcba32","html_url":"https://github.com/jadKhoury1/simple-body-validator","commit_stats":{"total_commits":214,"total_committers":6,"mean_commits":"35.666666666666664","dds":0.09813084112149528,"last_synced_commit":"b8340d06e35cb12c0e5ec68602740946ac16f4c4"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadKhoury1%2Fsimple-body-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadKhoury1%2Fsimple-body-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadKhoury1%2Fsimple-body-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadKhoury1%2Fsimple-body-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jadKhoury1","download_url":"https://codeload.github.com/jadKhoury1/simple-body-validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247631833,"owners_count":20970069,"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":["javascript","javascript-library","nodejs","validation"],"created_at":"2024-12-22T17:23:36.998Z","updated_at":"2025-04-07T10:20:17.964Z","avatar_url":"https://github.com/jadKhoury1.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Body Validator\nSimple Body Validator is an open source validation library inspired by the [Laravel](https://laravel.com/docs/validation) validation mechanism. The library's goal is to make data validation as easy as possible for Javascript developers on both client and server side.\n\nThe validation mechanism can be used with any popular framework like [Angular](https://angular.io/), [React](https://reactjs.org/), and [Vue](https://vuejs.org/).\n\nYou can learn more about simple body validator by reading the full documentation in our [docs](https://simple-body-validator.com)\n\n## Installing Simple Body Validator\n\n```bash\nnpm i simple-body-validator\n```\n\n### Install with Yarn\n\n```bash\nyarn add simple-body-validator\n```\n\n## Advantages\n\n### Simple \n\nThe main purpose of Simple Body Validator is to make the life of Javascript developers easier when it comes to validating simple and complex data. The methods are very declarative and can be understood easily by developers.\n\n### Built in Translation Mechanism\n\nSimple Body Validator comes with a built-in translation mechanism that makes it convenient to retrieve error messages in multiple languages, thus allowing you to support multiple languages for your validation without the need of external libraries. You can follow the [documentation](https://simple-body-validator.com/error-messages/translating-error-messages) to know more on how to implement translation for your error messages.\n\n### No Dependencies \n\nThe whole validation mechanism does not depend on any external package. There is no need to download several packages each time you want to use Simple Body Validator or to be linked to any third party library.\n\n### Flexible\n\nSimple Body Validator is built in a way that gives the developer max flexibility. Rules can be registered easily, thus giving the developers the ability to register as many custom rules as needed. While at the same time taking advantage of the built-in localization mechanism.\n\n\n## Validation Quick Start\n\nThe easiest way to continue validation quick start, is to follow the [validation quick start](https://simple-body-validator.com/validation-quickstart) section in our docs.\n\nTo learn more about Simple Body Validator's validation feature, let's look at a complete example of validating a data object and displaying the error messages back to the user.\n\nBy reading the following examples, you will be able to gain a good understanding of the main validation features.\n\n### Create a new validation instance\n\nTo create a new validation instance you need to import the \u003ccode\u003emake\u003c/code\u003e method.\n\n\n```js\n    import { make } from 'simple-body-validator';\n```\n\n```js\n    const { make } = require('simple-body-validator');\n```\n\nThe first argument passed to the \u003ccode\u003e make\u003c/code\u003e method is the data under validation. The second argument is an object of the validation rules that should be applied to the data.\n\n```js\n    const data = {\n        name: 'John',\n        email: 'John@gmail.com',\n        age: 28\n    };\n\n    const rules = {\n        name: 'required|string|min:3',\n        email: 'required|email',\n        age: 'min:18'\n    };\n\n    const validator = make(data, rules);\n```\n\nAs you can see the validation rules are passed as the second argument to the \u003ccode\u003emake\u003c/code\u003e method. All available validation rules are documented [here](https://simple-body-validator.com/available-validation-rules).\n\nAlternatively, validation rules may be specified as arrays of rules instead of a single \u003ccode\u003e|\u003c/code\u003e delimited string.\n\n```js\n    const rules = {\n        name: ['required', 'string', 'min:3'],\n        email: ['required', 'email'],\n        age: ['min:18']\n    };\n```\n\nIf you want a more expressive way to set your data and rules, you can chain the methods as shown below.\n\n```js\n    const validator = make().setData(data).setRules(rules);\n```\n\n\n### Run Validation\n\nTo run the validation against the defined rules you need to invoke the \u003ccode\u003evalidate\u003c/code\u003e method, which will return \u003ccode\u003efalse\u003c/code\u003e in case of failure and \u003ccode\u003etrue\u003c/code\u003e in case of success.\n\nIn case of validation failure, an error object will be returned based on the failed rules. You can find out more about [validation errors](https://simple-body-validator.com/error-messages/working-with-error-messages)\n\n```js\n    if (! validator.validate()) {\n        console.log('Errors: ', validator.errors().all());\n    }\n```\n\n### Stopping On First Validation Failure\n\nThe \u003ccode\u003estopOnFirstFailure\u003c/code\u003e method will inform the validator that it should stop validating all attributes once a single validation failure has occurred\n\n\n```js\n    if (! validator.stopOnFirstFailure().validate()) {\n        console.log('Error: ', validator.errors().first());\n    }\n```\n\nSometimes you may wish to stop running validation rules on an attribute after the first validation failure. To do so, assign the \u003ccode\u003ebail\u003c/code\u003e rule to the attribute.\n\n```js\n    validator.setRules({\n        name: 'bail|required|string|min:3',\n        email: 'bail|required|email',\n        age: 'min:18'\n    });\n```\n\nWhile the \u003ccode\u003ebail\u003c/code\u003e rule only stops a specific field when it encounters a validation failure, the \u003ccode\u003estopOnFirstFailure\u003c/code\u003e method will inform the validator that it should stop validating all attributes once a single validation failure has occurred.\n\n### A Note On Nested Attributes\n\nIf the upcoming HTTP request contains \"nested\" field data, you may specify these fields in your validation rule using the \"dot\" syntax.\n\n```js\n     validator.setRules({\n        title: 'required|max:255',\n        'author.name': 'required',\n        'author.description': 'required',\n    });\n```\n\nYou can learn more on nested and wildcard validations using this [link](https://simple-body-validator.com/nested-and-wildcard-rules)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjadkhoury1%2Fsimple-body-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjadkhoury1%2Fsimple-body-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjadkhoury1%2Fsimple-body-validator/lists"}