Gathering detailed insights and metrics for @jorgebarredo/resolvers
Gathering detailed insights and metrics for @jorgebarredo/resolvers
Gathering detailed insights and metrics for @jorgebarredo/resolvers
Gathering detailed insights and metrics for @jorgebarredo/resolvers
📋 Validation resolvers: Yup, Zod, AJV, Joi, Superstruct, Vest, class-validator, io-ts, typanion, Ajv and nope.
npm install @jorgebarredo/resolvers
Typescript
Module System
Node Version
NPM Version
67.6
Supply Chain
91.9
Quality
75.3
Maintenance
100
Vulnerability
100
License
TypeScript (98.33%)
JavaScript (1.61%)
Shell (0.06%)
Total Downloads
1,295
Last Day
3
Last Week
4
Last Month
6
Last Year
938
270 Commits
1 Forks
12 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
@jorgebarredo/resolvers@1.0.1
Unpacked Size
2.86 MB
Size
734.15 kB
File Count
248
NPM Version
8.5.5
Node Version
17.8.0
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
0%
4
Compared to previous week
Last month
-53.8%
6
Compared to previous month
Last year
610.6%
938
Compared to previous year
1
40
Performant, flexible and extensible forms with easy to use validation.
$ npm install @hookform/resolvers
type Options = {
mode: 'async' | 'sync',
rawValues?: boolean
}
resolver(schema: object, schemaOptions?: object, resolverOptions: Options)
type | Required | Description | |
---|---|---|---|
schema | object | ✓ | validation schema |
schemaOptions | object | validation library schema options | |
resolverOptions | object | resolver options, async is the default mode |
Dead simple Object schema validation.
1import { useForm } from 'react-hook-form'; 2import { yupResolver } from '@hookform/resolvers/yup'; 3import * as yup from 'yup'; 4 5const schema = yup 6 .object() 7 .shape({ 8 name: yup.string().required(), 9 age: yup.number().required(), 10 }) 11 .required(); 12 13const App = () => { 14 const { register, handleSubmit } = useForm({ 15 resolver: yupResolver(schema), 16 }); 17 18 return ( 19 <form onSubmit={handleSubmit((d) => console.log(d))}> 20 <input {...register('name')} /> 21 <input type="number" {...register('age')} /> 22 <input type="submit" /> 23 </form> 24 ); 25};
TypeScript-first schema validation with static type inference
⚠️ Example below uses the
valueAsNumber
, which requiresreact-hook-form
v6.12.0 (released Nov 28, 2020) or later.
1import { useForm } from 'react-hook-form'; 2import { zodResolver } from '@hookform/resolvers/zod'; 3import * as z from 'zod'; 4 5const schema = z.object({ 6 name: z.string().min(1, { message: 'Required' }), 7 age: z.number().min(10), 8}); 9 10const App = () => { 11 const { 12 register, 13 handleSubmit, 14 formState: { errors }, 15 } = useForm({ 16 resolver: zodResolver(schema), 17 }); 18 19 return ( 20 <form onSubmit={handleSubmit((d) => console.log(d))}> 21 <input {...register('name')} /> 22 {errors.name?.message && <p>{errors.name?.message}</p>} 23 <input type="number" {...register('age', { valueAsNumber: true })} /> 24 {errors.age?.message && <p>{errors.age?.message}</p>} 25 <input type="submit" /> 26 </form> 27 ); 28};
A simple and composable way to validate data in JavaScript (or TypeScript).
1import { useForm } from 'react-hook-form'; 2import { superstructResolver } from '@hookform/resolvers/superstruct'; 3import { object, string, number } from 'superstruct'; 4 5const schema = object({ 6 name: string(), 7 age: number(), 8}); 9 10const App = () => { 11 const { register, handleSubmit } = useForm({ 12 resolver: superstructResolver(schema), 13 }); 14 15 return ( 16 <form onSubmit={handleSubmit((d) => console.log(d))}> 17 <input {...register('name')} /> 18 <input type="number" {...register('age', { valueAsNumber: true })} /> 19 <input type="submit" /> 20 </form> 21 ); 22};
The most powerful data validation library for JS.
1import { useForm } from 'react-hook-form'; 2import { joiResolver } from '@hookform/resolvers/joi'; 3import Joi from 'joi'; 4 5const schema = Joi.object({ 6 name: Joi.string().required(), 7 age: Joi.number().required(), 8}); 9 10const App = () => { 11 const { register, handleSubmit } = useForm({ 12 resolver: joiResolver(schema), 13 }); 14 15 return ( 16 <form onSubmit={handleSubmit((d) => console.log(d))}> 17 <input {...register('name')} /> 18 <input type="number" {...register('age')} /> 19 <input type="submit" /> 20 </form> 21 ); 22};
Vest 🦺 Declarative Validation Testing.
1import { useForm } from 'react-hook-form'; 2import { vestResolver } from '@hookform/resolvers/vest'; 3import { create, test, enforce } from 'vest'; 4 5const validationSuite = create((data = {}) => { 6 test('username', 'Username is required', () => { 7 enforce(data.username).isNotEmpty(); 8 }); 9 10 test('password', 'Password is required', () => { 11 enforce(data.password).isNotEmpty(); 12 }); 13}); 14 15const App = () => { 16 const { register, handleSubmit, errors } = useForm({ 17 resolver: vestResolver(validationSuite), 18 }); 19 20 return ( 21 <form onSubmit={handleSubmit((data) => console.log(data))}> 22 <input {...register('username')} /> 23 <input type="password" {...register('password')} /> 24 <input type="submit" /> 25 </form> 26 ); 27};
Decorator-based property validation for classes.
⚠️ Remember to add these options to your
tsconfig.json
!
"strictPropertyInitialization": false,
"experimentalDecorators": true
1import { useForm } from 'react-hook-form'; 2import { classValidatorResolver } from '@hookform/resolvers/class-validator'; 3import { Length, Min, IsEmail } from 'class-validator'; 4 5class User { 6 @Length(2, 30) 7 username: string; 8 9 @IsEmail() 10 email: string; 11} 12 13const resolver = classValidatorResolver(User); 14 15const App = () => { 16 const { 17 register, 18 handleSubmit, 19 formState: { errors }, 20 } = useForm<User>({ resolver }); 21 22 return ( 23 <form onSubmit={handleSubmit((data) => console.log(data))}> 24 <input type="text" {...register('username')} /> 25 {errors.username && <span>{errors.username.message}</span>} 26 <input type="text" {...register('email')} /> 27 {errors.email && <span>{errors.email.message}</span>} 28 <input type="submit" value="Submit" /> 29 </form> 30 ); 31};
Validate your data with powerful decoders.
1import React from 'react'; 2import { useForm } from 'react-hook-form'; 3import { ioTsResolver } from '@hookform/resolvers/io-ts'; 4import t from 'io-ts'; 5// you don't have to use io-ts-types but it's very useful 6import tt from 'io-ts-types'; 7 8const schema = t.type({ 9 username: t.string, 10 age: tt.NumberFromString, 11}); 12 13const App = () => { 14 const { register, handleSubmit } = useForm({ 15 resolver: ioTsResolver(schema), 16 }); 17 18 return ( 19 <form onSubmit={handleSubmit((d) => console.log(d))}> 20 <input {...register('username')} /> 21 <input type="number" {...register('age')} /> 22 <input type="submit" /> 23 </form> 24 ); 25}; 26 27export default App;
A small, simple, and fast JS validator
1import { useForm } from 'react-hook-form'; 2import { nopeResolver } from '@hookform/resolvers/nope'; 3import Nope from 'nope-validator'; 4 5const schema = Nope.object().shape({ 6 name: Nope.string().required(), 7 age: Nope.number().required(), 8}); 9 10const App = () => { 11 const { register, handleSubmit } = useForm({ 12 resolver: nopeResolver(schema), 13 }); 14 15 return ( 16 <form onSubmit={handleSubmit((d) => console.log(d))}> 17 <input {...register('name')} /> 18 <input type="number" {...register('age')} /> 19 <input type="submit" /> 20 </form> 21 ); 22};
TypeScript-first schema validation with static type inference
1import { useForm } from 'react-hook-form'; 2import { computedTypesResolver } from '@hookform/resolvers/computed-types'; 3import Schema, { number, string } from 'computed-types'; 4 5const schema = Schema({ 6 username: string.min(1).error('username field is required'), 7 age: number, 8}); 9 10const App = () => { 11 const { 12 register, 13 handleSubmit, 14 formState: { errors }, 15 } = useForm({ 16 resolver: computedTypesResolver(schema), 17 }); 18 19 return ( 20 <form onSubmit={handleSubmit((d) => console.log(d))}> 21 <input {...register('name')} /> 22 {errors.name?.message && <p>{errors.name?.message}</p>} 23 <input type="number" {...register('age', { valueAsNumber: true })} /> 24 {errors.age?.message && <p>{errors.age?.message}</p>} 25 <input type="submit" /> 26 </form> 27 ); 28};
Static and runtime type assertion library with no dependencies
1import { useForm } from 'react-hook-form'; 2import { typanionResolver } from '@hookform/resolvers/typanion'; 3import * as t from 'typanion'; 4 5const isUser = t.isObject({ 6 username: t.applyCascade(t.isString(), [t.hasMinLength(1)]), 7 age: t.applyCascade(t.isNumber(), [ 8 t.isInteger(), 9 t.isInInclusiveRange(1, 100), 10 ]), 11}); 12 13const App = () => { 14 const { 15 register, 16 handleSubmit, 17 formState: { errors }, 18 } = useForm({ 19 resolver: typanionResolver(isUser), 20 }); 21 22 return ( 23 <form onSubmit={handleSubmit((d) => console.log(d))}> 24 <input {...register('name')} /> 25 {errors.name?.message && <p>{errors.name?.message}</p>} 26 <input type="number" {...register('age')} /> 27 {errors.age?.message && <p>{errors.age?.message}</p>} 28 <input type="submit" /> 29 </form> 30 ); 31};
The fastest JSON validator for Node.js and browser
1import { useForm } from 'react-hook-form'; 2import { ajvResolver } from '@hookform/resolvers/ajv'; 3 4// must use `minLength: 1` to implement required field 5const schema = { 6 type: 'object', 7 properties: { 8 username: { 9 type: 'string', 10 minLength: 1, 11 errorMessage: { minLength: 'username field is required' }, 12 }, 13 password: { 14 type: 'string', 15 minLength: 1, 16 errorMessage: { minLength: 'password field is required' }, 17 }, 18 }, 19 required: ['username', 'password'], 20 additionalProperties: false, 21}; 22 23const App = () => { 24 const { 25 register, 26 handleSubmit, 27 formState: { errors }, 28 } = useForm({ 29 resolver: ajvResolver(schema), 30 }); 31 32 return ( 33 <form onSubmit={handleSubmit((data) => console.log(data))}> 34 <input {...register('username')} /> 35 {errors.username && <span>{errors.username.message}</span>} 36 <input {...register('password')} /> 37 {errors.password && <span>{errors.password.message}</span>} 38 <button type="submit">submit</button> 39 </form> 40 ); 41};
Thanks goes to all our backers! [Become a backer].
Thanks goes to these wonderful organizations! [Contribute].
Thanks goes to these wonderful people! [Become a contributor].
No vulnerabilities found.
No security vulnerabilities found.