Nope Validator

A small, simple, and fast JS validator. Like, wow that's fast. 🚀
Alternatives To Nope Validator
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
React Hook Form33,9831271,3374 days ago951September 23, 202211mitTypeScript
📋 React Hooks for form state management and validation (Web + React Native)
Redux Form12,61411,7811,24324 days ago235November 17, 2021492mitJavaScript
A Higher Order Component using react-redux to keep form state in a Redux store
Eureka11,588
49011 days ago27September 15, 2020170mitSwift
Elegant iOS form builder in Swift
Vee Validate9,6342,1907352 days ago282September 19, 202248mitTypeScript
✅ Painless Vue forms
Formily9,3341197 days ago209September 20, 202211mitTypeScript
📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
Parsley.js9,045329416 months ago47December 10, 201969mitJavaScript
Validate your forms, frontend, without writing a single line of javascript
React Final Form7,21750038425 days ago76April 01, 2022385mitJavaScript
🏁 High performance subscription-based form state management for React
Tcomb Form Native3,162499186 months ago53October 11, 2018128mitJavaScript
Forms library for react-native
Formkit2,6171318 hours ago144September 23, 202251mitTypeScript
Vue Forms ⚡️ Supercharged
Formsy React2,59922 years ago1November 27, 2015149mitJavaScript
A form input builder and validator for React JS
Alternatives To Nope Validator
Select To Compare


Alternative Project Comparisons
Readme

Nope

CircleCI Fast Version size gzip

This project was created by the awesome Bruno Vego - @bvego, and is currently maintained by @ftonato and the community.


A small, simple and fast JS validator. Like, wow thats fast.

Nope's API is heavily inspired stolen from Yup but Nope attempts to be much smaller and much faster. To achieve this Nope only allows for synchronous data validation which should cover most of the use cases.

Note: Nope is not a plug-and-play replacement for Yup, in some cases at least.

Instead of throwing errors Nope simply returns the error object and if there are no errors it returns undefined.

For more details on what's available in Nope, check out the documentation.

Typescript definitions included.

Getting started

To start using Nope simply do

yarn add nope-validator

or

npm install -S nope-validator

or (even), do you wanna to try it online?

// import the dependency on your app

// const Nope = require('nope-validator'); // or
// const { Nope } = require('nope-validator'); // or
import Nope from 'nope-validator';
// create a schema

const UserSchema = Nope.object().shape({
  name: Nope.string().atLeast(5, 'Please provide a longer name').atMost(255, 'Name is too long!'),
  email: Nope.string().email().required(),
  confirmEmail: Nope.string()
    .oneOf([Nope.ref('email')])
    .required(),
});

UserSchema.validate({
  name: 'John',
  email: '[email protected]',
  confirmEmail: '[email protected]',
}); // returns an error object { name: 'Please provide a longer name '};

UserSchema.validate({
  name: 'Jonathan Livingston',
  email: '[email protected]',
  confirmEmail: '[email protected]',
}); // returns undefined since there are no errors

Usage with react-hook-form

Huge thanks to the RHF team for making a resolver for nope, enabling you to use nope as a validator in your RHF-controlled forms.

import { nopeResolver } from '@hookform/resolvers/nope';
import { useForm } from 'react-hook-form';
import * as Nope from 'nope-validator';

const schema = Nope.object().shape({
  username: Nope.string().required(),
  password: Nope.string().required(),
});

function Component({ onSubmit }) {
  const {
    register,
    formState: { errors },
    handleSubmit,
  } = useForm({
    resolver: nopeResolver(schema),
  });

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register('username')} />
      {errors.username && <div>{errors.username.message}</div>}

      <input {...register('password')} />
      {errors.password && <div>{errors.password.message}</div>}

      <button type="submit">submit</button>
    </form>
  );
}

Usage with Formik

Instead of passing it through the validationSchema prop, you should call Nope's validate on the validate prop as shown in the example below.

import { Formik } from 'formik';
import * as Nope from 'nope-validator';

const schema = Nope.object().shape({
  username: Nope.string().required(),
  password: Nope.string().required(),
});

function Component({ onSubmit }) {
  return (
    <Formik
      initialValues={{ username: '', password: '' }}
      validate={(values) => schema.validate(values)}
      onSubmit={(values) => console.log('Submitted', values)}
    >
      {() => (
        <Form>
          <Field type="username" name="username" />
          <ErrorMessage name="username" component="div" />

          <Field type="password" name="password" />
          <ErrorMessage name="password" component="div" />

          <button type="submit">Submit</button>
        </Form>
      )}
    </Formik>
  );
}

Contribute

Information describing how to contribute can be found here

License

MIT

Popular Validation Projects
Popular Form Projects
Popular Data Processing Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Typescript
Validation
Validator
Form
Schema
Form Validation