{"id":13493224,"url":"https://github.com/trapcodeio/object-validator-pro","last_synced_at":"2025-07-22T12:32:20.527Z","repository":{"id":47364942,"uuid":"176117048","full_name":"trapcodeio/object-validator-pro","owner":"trapcodeio","description":"More than just an object validator.","archived":false,"fork":false,"pushed_at":"2021-09-02T05:03:08.000Z","size":75,"stargazers_count":10,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-29T08:42:19.240Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/trapcodeio.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-17T14:59:37.000Z","updated_at":"2023-01-14T13:05:18.000Z","dependencies_parsed_at":"2022-09-08T08:03:32.903Z","dependency_job_id":null,"html_url":"https://github.com/trapcodeio/object-validator-pro","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Fobject-validator-pro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Fobject-validator-pro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Fobject-validator-pro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Fobject-validator-pro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trapcodeio","download_url":"https://codeload.github.com/trapcodeio/object-validator-pro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227096597,"owners_count":17730377,"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-07-31T19:01:13.309Z","updated_at":"2024-11-29T10:19:17.532Z","avatar_url":"https://github.com/trapcodeio.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"## Object Validator Pro (OVP)\n\n#### What is OVP?\nObject-Validator-Pro provides a very simple API for developers to make both **Sync** and **Async** validations on any javascript object.\n\nTo Use OVP efficiently, you need to understand how it validates each key in any given object against its rules.\nUnlike other validation libraries, OVP is best for your **custom validation rules**.\n\nYou can create your own validation library out of OVP and use them in as many projects as you want.\n\n**You set your rules just the way you understand them.**\n\n#### Get Started.\nSee [Full Documentation](https://trapcodeio.github.io/object-validator-pro/) for more details.\n\n#### After Installation\n```javascript\nconst ObjectValidator = require('object-validator-pro');\nconst ovp = new ObjectValidator();\n\n// log errors when they occur.\novp.setEventHandler('onEachError', (path, message) =\u003e {\n    console.log([path, message])\n})\n```\n\n#### Simple Form Data Validation\n```javascript\n// Object to validate\nlet data = {\n    username: 'NodeJs',\n    password: '123456'\n};\n\n// \"*\" sets validation for all data keys, more like a wildcard.\nlet rules = {\n    \"*\": {\n        typeOf: 'string',\n        must: true\n    },\n    password: {minLength: 10}\n};\n\n\nlet check = ovp.validate(data, rules);\n\nif (!check) {\n    // do something\n}\n\n// returns: false\n// log: [ 'password', 'Password is too short. (Min. 10 characters)' ]\n\n// if rules has an Async validator use\n\novp.validateAsync(data, rules).then((isValid) =\u003e {\n    // isValid holds the result: boolean;\n    // returns: false\n    // log: [ 'password', 'Password is too short. (Min. 10 characters)' ]\n});\n```\n\n`check` and `isValid` returned false,\n\n`validate` and `validateAsync` function logs an array `onEachError`,\n\n `Array[0]`: Failed Object key, `Array[1]`: Error message.\n \nTo check if `*` (wildcard) rules affected `data.username`, it should return an error when username is not a `string`\n \n```javascript\ndata.username = ['an array instead of a string'];\n\ncheck = ovp.validate(data, rules);\n\n// returns: false\n// log: [ 'username', 'Username is not typeOf string' ]\n```\n\n\n#### Simple validateAsync Example\n```javascript\nconst axios = require('axios');\n\nlet asyncTestData = {\n    url: 'https://google.com',\n};\n    \nlet asyncTestRules = {\n    url: {urlIsOnline: true}\n};\n\n// lets add urlIsOnline Async validator.\novp.addValidator('urlIsOnline', async (url) =\u003e {\n    try{\n        await axios.get(url);\n        return true;\n    }catch(e){\n        return false;\n    }\n}, 'Url is not online!');\n\n\n// if any of your rules contain an async validator,\n// You use the validateAsync function instead of validate, returns Promise\u003cboolean\u003e\n// You can use await or Promise.then((result){})\n\nlet first = await ovp.validateAsync(asyncTestData, asyncTestRules);\nconsole.log(first);\n// logs: true\n\nasyncTestData.url = 'https://some-website-that-does-not-exists-2019.com';\n\nlet second = await ovp.validateAsync(asyncTestData, asyncTestRules);\nconsole.log(second);\n// log: [\"url\", \"Url is not online!\"]\n// log: false\n```\n\n#### Super Rules Example\n```javascript\n// assuming we have an object:\nwildcardData = {\n    name: 'wildcard',\n    address: 'Drive 6, Astro world!',\n    mobile: '+1336d373'\n};\n\n// With rules set with both wildcards:\nwildcardTestRules = {\n    '*': {typeOf: 'string'},\n    '**': {must: true},\n\n    address: {minLength: 10},\n};\n\n// the above will be transformed to this using wildcards\nwildcardTestRules = { \n    address: { typeOf: 'string', must: true, minLength: 10 },\n    name: { typeOf: 'string' },\n    mobile: { typeOf: 'string' } \n};\n\n// name and mobile was automatically added because * wildcard exists.\n// If * is removed and ** still exists, will result to:\n\nwildcardTestRules = { \n    address: { must: true, minLength: 10 } \n}\n```\n\nvalue of `*` is added to all **object keys**, while value of `**` is added to all **defined** rules.\n\nNotice that `wildcardTestRules.address` rules comes first when transformed before the other keys of the object.\nThis is because **defined** rules runs before `*` wildcard added rules.\n\n\n \n#### Contributing\nPull requests are VERY welcomed. For major changes, please open an issue first to discuss what you would like to change.\nPlease make sure to update tests as appropriate.\n\n#### License\n[MIT](https://choosealicense.com/licenses/mit/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrapcodeio%2Fobject-validator-pro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrapcodeio%2Fobject-validator-pro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrapcodeio%2Fobject-validator-pro/lists"}