{"id":13681391,"url":"https://github.com/jfairbank/revalidate","last_synced_at":"2025-04-04T07:05:45.727Z","repository":{"id":60775145,"uuid":"52567811","full_name":"jfairbank/revalidate","owner":"jfairbank","description":"Elegant and composable validations","archived":false,"fork":false,"pushed_at":"2018-12-08T18:54:24.000Z","size":5231,"stargazers_count":362,"open_issues_count":19,"forks_count":20,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T06:07:19.119Z","etag":null,"topics":["composition","functional","javascript","javascript-validation","redux-form","validation"],"latest_commit_sha":null,"homepage":"http://revalidate.jeremyfairbank.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/jfairbank.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-02-26T00:49:37.000Z","updated_at":"2025-01-13T09:02:39.000Z","dependencies_parsed_at":"2022-10-04T16:36:44.728Z","dependency_job_id":null,"html_url":"https://github.com/jfairbank/revalidate","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/jfairbank%2Frevalidate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfairbank%2Frevalidate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfairbank%2Frevalidate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfairbank%2Frevalidate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jfairbank","download_url":"https://codeload.github.com/jfairbank/revalidate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135142,"owners_count":20889420,"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":["composition","functional","javascript","javascript-validation","redux-form","validation"],"created_at":"2024-08-02T13:01:30.204Z","updated_at":"2025-04-04T07:05:45.709Z","avatar_url":"https://github.com/jfairbank.png","language":"JavaScript","readme":"# \u003cimg src=\"https://raw.githubusercontent.com/jfairbank/revalidate/master/logo/logo.png\" width=\"350\" alt=\"revalidate\"\u003e\n\n[![npm](https://img.shields.io/npm/v/revalidate.svg?style=flat-square)](https://www.npmjs.com/package/revalidate)\n[![Travis branch](https://img.shields.io/travis/jfairbank/revalidate/master.svg?style=flat-square)](https://travis-ci.org/jfairbank/revalidate)\n[![Codecov](https://img.shields.io/codecov/c/github/jfairbank/revalidate.svg?style=flat-square)](https://codecov.io/gh/jfairbank/revalidate)\n\n#### Elegant and composable validations.\n\nRevalidate is a library for creating and composing together small validation\nfunctions to create complex, robust validations. There is no need for awkward\nconfiguration rules to define validations. Just use functions.\n\nAll right. No more upselling. Just look at an example :heart:.\n\n```js\n// ES2015\nimport {\n  createValidator,\n  composeValidators,\n  combineValidators,\n  isRequired,\n  isAlphabetic,\n  isNumeric\n} from 'revalidate';\n\n// Or ES5\nvar r = require('revalidate');\nvar createValidator = r.createValidator;\nvar composeValidators = r.composeValidators;\nvar combineValidators = r.combineValidators;\nvar isRequired = r.isRequired;\nvar isAlphabetic = r.isAlphabetic;\nvar isNumeric = r.isNumeric;\n\n// Usage\nconst dogValidator = combineValidators({\n  name: composeValidators(\n    isRequired,\n    isAlphabetic\n  )('Name'),\n\n  age: isNumeric('Age')\n});\n\ndogValidator({}); // { name: 'Name is required' }\n\ndogValidator({ name: '123', age: 'abc' });\n// { name: 'Name must be alphabetic', age: 'Age must be numeric' }\n\ndogValidator({ name: 'Tucker', age: '10' }); // {}\n```\n\n## Install\n\nInstall with yarn or npm.\n\n```\nyarn add revalidate\n```\n\n```\nnpm install --save revalidate\n```\n\n## Getting Started\n\n#### [Docs](http://revalidate.jeremyfairbank.com)\n\nRevalidate has a host of options along with helper functions for building\nvalidations and some common validation functions right out of the box. To learn\nmore, check out the docs at [revalidate.jeremyfairbank.com](http://revalidate.jeremyfairbank.com).\n\n## Redux Form\n\nJust one more example! You might have heard about revalidate through Redux Form.\nRevalidate was originally conceived as a library for writing validation\nfunctions for Redux Form. Revalidate is still a great companion to Redux Form!\nHere is the simple synchronous form validation from Redux Form's\n[docs](http://redux-form.com/6.1.1/examples/syncValidation) rewritten to use\nrevalidate:\n\n```js\nimport React from 'react'\nimport { Field, reduxForm } from 'redux-form'\n\nimport {\n  createValidator,\n  composeValidators,\n  combineValidators,\n  isRequired,\n  hasLengthLessThan,\n  isNumeric\n} from 'revalidate'\n\nconst isValidEmail = createValidator(\n  message =\u003e value =\u003e {\n    if (value \u0026\u0026 !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i.test(value)) {\n      return message\n    }\n  },\n  'Invalid email address'\n)\n\nconst isGreaterThan = (n) =\u003e createValidator(\n  message =\u003e value =\u003e {\n    if (value \u0026\u0026 Number(value) \u003c= n) {\n      return message\n    }\n  },\n  field =\u003e `${field} must be greater than ${n}`\n)\n\nconst customIsRequired = isRequired({ message: 'Required' })\n\nconst validate = combineValidators({\n  username: composeValidators(\n    customIsRequired,\n\n    hasLengthLessThan(16)({\n      message: 'Must be 15 characters or less'\n    })\n  )(),\n\n  email: composeValidators(\n    customIsRequired,\n    isValidEmail\n  )(),\n\n  age: composeValidators(\n    customIsRequired,\n\n    isNumeric({\n      message: 'Must be a number'\n    }),\n\n    isGreaterThan(17)({\n      message: 'Sorry, you must be at least 18 years old'\n    })\n  )()\n})\n\nconst warn = values =\u003e {\n  const warnings = {}\n  if (values.age \u003c 19) {\n    warnings.age = 'Hmm, you seem a bit young...'\n  }\n  return warnings\n}\n\nconst renderField = ({ input, label, type, meta: { touched, error, warning } }) =\u003e (\n  \u003cdiv\u003e\n    \u003clabel\u003e{label}\u003c/label\u003e\n    \u003cdiv\u003e\n      \u003cinput {...input} placeholder={label} type={type}/\u003e\n      {touched \u0026\u0026 ((error \u0026\u0026 \u003cspan\u003e{error}\u003c/span\u003e) || (warning \u0026\u0026 \u003cspan\u003e{warning}\u003c/span\u003e))}\n    \u003c/div\u003e\n  \u003c/div\u003e\n)\n\nconst SyncValidationForm = (props) =\u003e {\n  const { handleSubmit, pristine, reset, submitting } = props\n  return (\n    \u003cform onSubmit={handleSubmit}\u003e\n      \u003cField name=\"username\" type=\"text\" component={renderField} label=\"Username\"/\u003e\n      \u003cField name=\"email\" type=\"email\" component={renderField} label=\"Email\"/\u003e\n      \u003cField name=\"age\" type=\"number\" component={renderField} label=\"Age\"/\u003e\n      \u003cdiv\u003e\n        \u003cbutton type=\"submit\" disabled={submitting}\u003eSubmit\u003c/button\u003e\n        \u003cbutton type=\"button\" disabled={pristine || submitting} onClick={reset}\u003e\n          Clear Values\n        \u003c/button\u003e\n      \u003c/div\u003e\n    \u003c/form\u003e\n  )\n}\n\nexport default reduxForm({\n  form: 'syncValidation',  // a unique identifier for this form\n  validate,                // \u003c--- validation function given to redux-form\n  warn                     // \u003c--- warning function given to redux-form\n})(SyncValidationForm)\n```\n","funding_links":[],"categories":["JavaScript","UI Components"],"sub_categories":["Form Validation"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfairbank%2Frevalidate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjfairbank%2Frevalidate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfairbank%2Frevalidate/lists"}