All Projects β†’ jfairbank β†’ Revalidate

jfairbank / Revalidate

Licence: mit
Elegant and composable validations

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Revalidate

Openapi Spring Webflux Validator
🌱 A friendly kotlin library to validate API endpoints using an OpenApi 3.0 and Swagger 2.0 specification
Stars: ✭ 67 (-81.54%)
Mutual labels:  validation, functional
Redux Form
A Higher Order Component using react-redux to keep form state in a Redux store
Stars: ✭ 12,597 (+3370.25%)
Mutual labels:  validation, redux-form
Redux Form Validators
redux-form-validators
Stars: ✭ 152 (-58.13%)
Mutual labels:  validation, redux-form
Typed
The TypeScript Standard Library
Stars: ✭ 124 (-65.84%)
Mutual labels:  composition, functional
pyroclastic
Functional dataflow through composable computations
Stars: ✭ 17 (-95.32%)
Mutual labels:  functional, composition
Umbrella
"A collection of functional programming libraries that can be composed together. Unlike a framework, thi.ng is a suite of instruments and you (the user) must be the composer of. Geared towards versatility, not any specific type of music." β€” @loganpowell via Twitter
Stars: ✭ 2,186 (+502.2%)
Mutual labels:  composition, functional
Liform React
Generate forms from JSON Schema to use with React (& redux-form)
Stars: ✭ 167 (-53.99%)
Mutual labels:  validation, redux-form
Pipetools
Functional plumbing for Python
Stars: ✭ 143 (-60.61%)
Mutual labels:  composition, functional
functional-structures-refactoring-kata
Starting code and proposed solution for Functional Structures Refactoring Kata
Stars: ✭ 31 (-91.46%)
Mutual labels:  functional, composition
Decoders
Elegant validation library for type-safe input data (for TypeScript and Flow)
Stars: ✭ 246 (-32.23%)
Mutual labels:  validation, composition
Evangelist
🌟 Library of helpers that are useful for functional programming
Stars: ✭ 58 (-84.02%)
Mutual labels:  composition, functional
Swiftz-Validation
A data structure for validations. It implements the applicative functor interface
Stars: ✭ 15 (-95.87%)
Mutual labels:  functional, validation
Kotlin Openapi Spring Functional Template
πŸƒ Kotlin Spring 5 Webflux functional application with api request validation and interactive api doc
Stars: ✭ 159 (-56.2%)
Mutual labels:  validation, functional
Deep Waters
πŸ”₯Deep Waters is an easy-to-compose functional validation system for javascript developers πŸ”₯
Stars: ✭ 188 (-48.21%)
Mutual labels:  validation, functional
validation
Validation in Ruby objects
Stars: ✭ 18 (-95.04%)
Mutual labels:  functional, validation
fefe
Validate, sanitize and transform values with proper TypeScript types and zero dependencies.
Stars: ✭ 34 (-90.63%)
Mutual labels:  functional, validation
Go Tea
Tea provides an Elm inspired functional framework for interactive command-line programs.
Stars: ✭ 329 (-9.37%)
Mutual labels:  functional
Openapi Cop
A proxy that validates responses and requests against an OpenAPI document.
Stars: ✭ 338 (-6.89%)
Mutual labels:  validation
Easyvalidation
βœ”οΈ A text and input validation library in Kotlin for Android
Stars: ✭ 328 (-9.64%)
Mutual labels:  validation
Validator.js
String validation
Stars: ✭ 18,842 (+5090.63%)
Mutual labels:  validation

revalidate

npm Travis branch Codecov

Elegant and composable validations.

Revalidate is a library for creating and composing together small validation functions to create complex, robust validations. There is no need for awkward configuration rules to define validations. Just use functions.

All right. No more upselling. Just look at an example ❀️.

// ES2015
import {
  createValidator,
  composeValidators,
  combineValidators,
  isRequired,
  isAlphabetic,
  isNumeric
} from 'revalidate';

// Or ES5
var r = require('revalidate');
var createValidator = r.createValidator;
var composeValidators = r.composeValidators;
var combineValidators = r.combineValidators;
var isRequired = r.isRequired;
var isAlphabetic = r.isAlphabetic;
var isNumeric = r.isNumeric;

// Usage
const dogValidator = combineValidators({
  name: composeValidators(
    isRequired,
    isAlphabetic
  )('Name'),

  age: isNumeric('Age')
});

dogValidator({}); // { name: 'Name is required' }

dogValidator({ name: '123', age: 'abc' });
// { name: 'Name must be alphabetic', age: 'Age must be numeric' }

dogValidator({ name: 'Tucker', age: '10' }); // {}

Install

Install with yarn or npm.

yarn add revalidate
npm install --save revalidate

Getting Started

Docs

Revalidate has a host of options along with helper functions for building validations and some common validation functions right out of the box. To learn more, check out the docs at revalidate.jeremyfairbank.com.

Redux Form

Just one more example! You might have heard about revalidate through Redux Form. Revalidate was originally conceived as a library for writing validation functions for Redux Form. Revalidate is still a great companion to Redux Form! Here is the simple synchronous form validation from Redux Form's docs rewritten to use revalidate:

import React from 'react'
import { Field, reduxForm } from 'redux-form'

import {
  createValidator,
  composeValidators,
  combineValidators,
  isRequired,
  hasLengthLessThan,
  isNumeric
} from 'revalidate'

const isValidEmail = createValidator(
  message => value => {
    if (value && !/^[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value)) {
      return message
    }
  },
  'Invalid email address'
)

const isGreaterThan = (n) => createValidator(
  message => value => {
    if (value && Number(value) <= n) {
      return message
    }
  },
  field => `${field} must be greater than ${n}`
)

const customIsRequired = isRequired({ message: 'Required' })

const validate = combineValidators({
  username: composeValidators(
    customIsRequired,

    hasLengthLessThan(16)({
      message: 'Must be 15 characters or less'
    })
  )(),

  email: composeValidators(
    customIsRequired,
    isValidEmail
  )(),

  age: composeValidators(
    customIsRequired,

    isNumeric({
      message: 'Must be a number'
    }),

    isGreaterThan(17)({
      message: 'Sorry, you must be at least 18 years old'
    })
  )()
})

const warn = values => {
  const warnings = {}
  if (values.age < 19) {
    warnings.age = 'Hmm, you seem a bit young...'
  }
  return warnings
}

const renderField = ({ input, label, type, meta: { touched, error, warning } }) => (
  <div>
    <label>{label}</label>
    <div>
      <input {...input} placeholder={label} type={type}/>
      {touched && ((error && <span>{error}</span>) || (warning && <span>{warning}</span>))}
    </div>
  </div>
)

const SyncValidationForm = (props) => {
  const { handleSubmit, pristine, reset, submitting } = props
  return (
    <form onSubmit={handleSubmit}>
      <Field name="username" type="text" component={renderField} label="Username"/>
      <Field name="email" type="email" component={renderField} label="Email"/>
      <Field name="age" type="number" component={renderField} label="Age"/>
      <div>
        <button type="submit" disabled={submitting}>Submit</button>
        <button type="button" disabled={pristine || submitting} onClick={reset}>
          Clear Values
        </button>
      </div>
    </form>
  )
}

export default reduxForm({
  form: 'syncValidation',  // a unique identifier for this form
  validate,                // <--- validation function given to redux-form
  warn                     // <--- warning function given to redux-form
})(SyncValidationForm)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].