{"id":15313861,"url":"https://github.com/itsdouges/gotta-validate","last_synced_at":"2026-03-16T15:40:43.743Z","repository":{"id":57252642,"uuid":"41362293","full_name":"itsdouges/gotta-validate","owner":"itsdouges","description":"An async object validator for node.","archived":false,"fork":false,"pushed_at":"2016-12-15T01:49:11.000Z","size":25,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T09:51:15.639Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/itsdouges.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":"2015-08-25T12:34:38.000Z","updated_at":"2016-12-15T01:39:22.000Z","dependencies_parsed_at":"2022-08-31T22:21:07.751Z","dependency_job_id":null,"html_url":"https://github.com/itsdouges/gotta-validate","commit_stats":null,"previous_names":["madou/gotta-validate"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsdouges%2Fgotta-validate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsdouges%2Fgotta-validate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsdouges%2Fgotta-validate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsdouges%2Fgotta-validate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itsdouges","download_url":"https://codeload.github.com/itsdouges/gotta-validate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991539,"owners_count":21194894,"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-01T08:43:25.484Z","updated_at":"2026-03-16T15:40:43.688Z","avatar_url":"https://github.com/itsdouges.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gotta Validate!  [![Build Status](https://img.shields.io/travis/madou/gotta-validate.svg)](https://travis-ci.org/madou/gotta-validate) [![NPM Version](https://img.shields.io/npm/v/gotta-validate.svg)](https://www.npmjs.com/package/gotta-validate)\n\n\u003e An async object validator for node.\n\nMade for `api.gw2armory.com`. If you've stumbled upon this it's debatable if this is really worthwhile using. I'd advise using a more mature library.\n\nTo run tests use: `gulp test`.\n\n## 1. Examples\n### 1.1 General stuff\nNote: Take a look at `src/example.spec.js` for these tests.\n\nRequire it!\n\n```\nimport gottaValidate from 'gotta-validate';\n```\n\nAdd rules you need, you can chain them too.\n\n```\ngottaValidate.addRule({\n    name: 'required',\n    func: (property, object) =\u003e {\n        var item = object[property];\n        if (!item) {\n            return 'is required!';\n        }\n    }\n})\n.addRule(..);\n```\n\nAdd resources you need, you can chain it too. Add the name of any property you want to validate to the rules object. It can be a single rule (string) or many rules with an array (of strings).\n```\ngottaValidate.addResource({\n    name: 'Users',\n    mode: 'create',\n    rules: {\n        id: 'required',\n        email: ['required']\n    }\n})\n.addResource(..);\n```\n\nNow you gotta validate! Call the constructor function every time you want a different validator. The promise will resolve if validation was a success, and reject if any validators returned an error.\n\n```\nvar validator = gottaValidate({\n    resource: 'Users',\n    mode: 'create'\n});\n\nconst user = {};\n\nvalidator.validate(user)\n    .catch((e) =\u003e {\n        expect(e).toBe([\n            '[id] is required!', \n            '[email] is required!' \n        ]);\n    });\n    \nconst validUser = {\n    id: 'ayylmao',\n    email: 'coolemailthough'\n};\n\nvalidator.validate(validUser)\n    .then((e) =\u003e {\n        expect(e).not.toBeDefined();\n    });\n```\n\n### 1.2 Pre-defined Rules\nRules which you can use without needing to add yourself are as follows (after using the addDefaultRules method).\n\n```\ngottaValidate.addDefaultRules();\n\ngottaValidate.addResource({\n    name: 'cool-resource',\n    mode: 'mode',\n    rules: {\n        aCoolProperty: ['email', 'no-white-space', 'password', 'required']\n    }\n});\n```\n\n### 1.3 Extra stuff\n#### 1.3.1 Promise based rules\nYou can add promise based rules like the following. Just make sure you return a promise! If an error occurred return an object like in the example.\n\n```\nvar async = require('something-async');\n\ngottaValidate.addRule({\n    name: 'required',\n    func: (property, object) =\u003e {\n        if (0 === 1) {\n            return Promise.reject({\n                property: property,\n                message: 'was bad!'\n            });\n        }\n        \n        return async().then(function (e) {\n            // resolve or reject\n        });\n    }\n});\n```\n### 1.3.2 Rules with dependencies\nYou can also add rules that have dependencies. Promise based or synchronous!\n\n```\ngottaValidate.addRule({\n    name: 'depender',\n    func: (property, object, dependencies) =\u003e {\n        var error = dependencies.a();\n        if (error) {\n            return 'oh no error!';\n        }\n    },\n    dependencies: {\n        a: function () { return true; }\n    }\n});\n```\n\n### 1.3.3 Rules that inherit\n```\ngottaValidate.addRule({\n    name: 'rule-a',\n    func: function () {\n        return 'bad';\n    }\n});\n\ngottaValidate.addRule({\n    name: 'rule-b',\n    func: function () {\n        return 'naughty!';\n    },\n    inherits: ['rule-a'] // Array for multiple, string for single\n});\n\ngottaValidate.addResource({\n    name: 'inherit',\n    mode: 'deez',\n    rules: {\n        id: ['rule-b']\n    }\n});\n```\n\n## 2. Api\n### 2.1 Instantiating\nAdd some rules and resources and then call the consturctor method. No need for new! \n\nOptions properties:\nresource (required), mode (required)\n```\nconst validator = gottaValidate(options);\nvalidator.validate(object);\n```\n\n### 2.2 Static methods\n#### 2.2.1 addRule(options)\nAdds a rule. Returns this.\n\nOptions properties:\nname (required), func (required), inherits (optional)\n\n#### 2.2.2 addResource(options)\nAdd a resource. Returns this.\n\nOptions properties:\nname (required), mode (required), rules (optional)\n\n#### 2.2.3 addDefaultRules()\nAdds the default rules to the rule table.\n\n### 2.3 Instance methods\n#### 2.3.1 validate(object)\nValidates an object based on an instantiated validator. Returns a promise.\n\n## 3. License\n```\nCopyright (c) 2015 Michael Dougall\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsdouges%2Fgotta-validate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsdouges%2Fgotta-validate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsdouges%2Fgotta-validate/lists"}