{"id":20170239,"url":"https://github.com/marcodpt/validator","last_synced_at":"2025-03-03T04:15:54.027Z","repository":{"id":111253371,"uuid":"379684138","full_name":"marcodpt/validator","owner":"marcodpt","description":"An es6 module javascript object validator focused on error handling","archived":false,"fork":false,"pushed_at":"2022-04-04T13:40:06.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-13T15:27:09.807Z","etag":null,"topics":["es6-modules","form-validation","i18n","json-schema","languages"],"latest_commit_sha":null,"homepage":"https://marcodpt.github.io/validator/","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/marcodpt.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":"2021-06-23T17:40:01.000Z","updated_at":"2022-04-04T13:32:16.000Z","dependencies_parsed_at":"2023-07-20T04:30:58.047Z","dependency_job_id":null,"html_url":"https://github.com/marcodpt/validator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcodpt%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcodpt%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcodpt%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcodpt%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcodpt","download_url":"https://codeload.github.com/marcodpt/validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241605820,"owners_count":19989612,"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":["es6-modules","form-validation","i18n","json-schema","languages"],"created_at":"2024-11-14T01:17:47.634Z","updated_at":"2025-03-03T04:15:54.021Z","avatar_url":"https://github.com/marcodpt.png","language":"JavaScript","readme":"# validator\n\u003e An es6 module javascript object validator focused on error handling\n\nThis module is a subset of json schema, focused on objects for form validation!\n\nIt has support for multiple languages! And great error feedback!\n\n## Usage\n```js\nimport {validate} from 'https://cdn.jsdelivr.net/gh/marcodpt/validator/index.js'\n\nconst schema = {\n  type: \"object\",\n  properties: {\n    foo: {\n      type: \"integer\",\n      minimum: 7,\n      maximum: 19,\n      multipleOf: 1.5\n    },\n    bar: {\n      type: \"number\",\n      minimum: 7,\n      maximum: 19,\n      multipleOf: 1.5\n    },\n    baz: {\n      type: \"string\",\n      minLength: 3,\n      maxLength: 10,\n      pattern: 'a+'\n    }\n  },\n  required: ['foo', 'bar', 'baz'],\n  additionalProperties: false\n}\n\nvar res = validate(schema, {\n  foo: '15',\n  bar: 13.5,\n  baz: 'cccarr',\n  qux: 'xxx'\n})\nconsole.log(res)\n/*\n   {\n     foo: 15,\n     bar: 13.5,\n     baz: 'cccarr'\n   }\n*/\n\nconst onError = (key, msg) =\u003e console.log(`${key} ${msg}`)\nvar res = validate(schema, {\n  foo: 2,\n  baz: 'bb'\n}, onError)\n/*\n  foo Must be at least: 7\n  foo Must be multiple of: 1.5\n  bar Is required!\n  baz Must have at least 3 characters\n  baz Must be of specified type!\n*/\n\nconsole.log(res)\n//null\n```\n\n## API\n\nThe current available translations are:\n - `validate`: english\n - `validate_pt`: portuguese (português)\n\n### validate (schema, data, onError)\n - object `schema`: A json schema of the data, it must be an object because\nthe current implementation only support objects.\n - object `data`: Your data model\n - function `onError` (key, message): Every error will be called\n   - string `key`: The property that heappens the error\n   - string `message`: The error message\n - returns:\n   - object: In case validation pass with modified `data` that passed validation \n   - null: In case that the `data` do not pass validation\n\n### loader (schema, data)\n - object `schema`: A json schema of the data, it must be an object because\nthe current implementation only support objects.\n - object `data`: Your data model\n - returns:\n   An object to be used on your inputs with loaded data based on `format` info\n\n## Tests\nCheck if work in your [broser](https://marcodpt.github.io/validator/)\n\n## Contributing\nThis project was done very quickly with minimal compatibility with json-schema\njust for my personal needs!\n\nBy no means this project is complete!\n\nI will accept any contributions that:\n - get closer to json-schema spec\n - fix a bug\n - improve tests\n - add translations\n - improve the API\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcodpt%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcodpt%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcodpt%2Fvalidator/lists"}