Socket
Socket
Sign inDemoInstall

react-hook-form

Package Overview
Dependencies
86
Maintainers
1
Versions
1026
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.15 to 0.1.0

6

dist/index.d.ts

@@ -11,2 +11,3 @@ export interface RegisterInput {

}
declare type Validate = (data: string | number) => boolean;
export interface Field {

@@ -19,3 +20,5 @@ ref: any;

pattern?: RegExp;
custom?: (data: string | number) => boolean;
validate?: Validate | {
[key: string]: Validate;
};
minLength?: number;

@@ -44,1 +47,2 @@ eventAttached?: boolean;

};
export {};

@@ -64,3 +64,3 @@ import { useRef, useState, useEffect } from 'react';

var validateField = ({ ref: { type, value, name, checked }, required, maxLength, minLength, min, max, pattern, custom }, fields) => {
var validateField = ({ ref: { type, value, name, checked }, required, maxLength, minLength, min, max, pattern, validate }, fields) => {
const copy = {};

@@ -104,4 +104,16 @@ if (required &&

}
if (custom && !custom(value)) {
copy[name] = Object.assign({}, copy[name], { custom: true });
if (validate) {
if (typeof validate === 'function') {
if (!validate(value)) {
copy[name] = Object.assign({}, copy[name], { validate: true });
}
}
else if (typeof validate === 'object') {
return Object.assign({}, copy[name], { validate: Object.entries(validate).reduce((previous, [key, validate]) => {
if (typeof validate === 'function' && !validate(value)) {
previous[key] = true;
}
return previous;
}, {}) });
}
}

@@ -108,0 +120,0 @@ return copy;

@@ -66,3 +66,3 @@ 'use strict';

var validateField = ({ ref: { type, value, name, checked }, required, maxLength, minLength, min, max, pattern, custom }, fields) => {
var validateField = ({ ref: { type, value, name, checked }, required, maxLength, minLength, min, max, pattern, validate }, fields) => {
const copy = {};

@@ -106,4 +106,16 @@ if (required &&

}
if (custom && !custom(value)) {
copy[name] = Object.assign({}, copy[name], { custom: true });
if (validate) {
if (typeof validate === 'function') {
if (!validate(value)) {
copy[name] = Object.assign({}, copy[name], { validate: true });
}
}
else if (typeof validate === 'object') {
return Object.assign({}, copy[name], { validate: Object.entries(validate).reduce((previous, [key, validate]) => {
if (typeof validate === 'function' && !validate(value)) {
previous[key] = true;
}
return previous;
}, {}) });
}
}

@@ -110,0 +122,0 @@ return copy;

2

dist/logic/validateField.d.ts
import { ErrorMessages, Field } from '..';
declare const _default: ({ ref: { type, value, name, checked }, required, maxLength, minLength, min, max, pattern, custom }: Field, fields: {
declare const _default: ({ ref: { type, value, name, checked }, required, maxLength, minLength, min, max, pattern, validate }: Field, fields: {
[key: string]: Field;
}) => ErrorMessages;
export default _default;
{
"name": "react-hook-form",
"version": "0.0.15",
"version": "0.1.0",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "module": "dist/index.es.js",

@@ -1,8 +0,9 @@

<div align="center"><a href="https://react-hook-form.now.sh/"><img src="https://raw.githubusercontent.com/bluebill1049/react-forme/master/website/logo.png" alt="React forme Logo - React hook form valiation" width="350px" /></a></div>
<div align="center"><a href="https://react-hook-form.now.sh/"><img src="https://raw.githubusercontent.com/bluebill1049/react-hook-form/master/website/logo.png" alt="React forme Logo - React hook form valiation" width="350px" /></a></div>
> React hook form management without the hassle
> React hook form validation without the hassle
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=React+Hook-Form&url=https://github.com/bluebill1049/react-hook-form)&nbsp;[![CircleCI](https://circleci.com/gh/bluebill1049/react-forme.svg?style=svg)](https://circleci.com/gh/bluebill1049/react-forme) [![Coverage Status](https://coveralls.io/repos/github/bluebill1049/react-forme/badge.svg?branch=master)](https://coveralls.io/github/bluebill1049/react-forme?branch=master) [![npm downloads](https://img.shields.io/npm/dm/react-forme.svg?style=flat-square)](https://www.npmjs.com/package/react-forme)
[![npm](https://img.shields.io/npm/dt/react-forme.svg?style=flat-square)](https://www.npmjs.com/package/react-forme)
[![npm](https://img.shields.io/npm/l/react-forme.svg?style=flat-square)](https://www.npmjs.com/package/react-lazyload-image)
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=React+Hook-Form&url=https://github.com/bluebill1049/react-hook-form)&nbsp;[![CircleCI](https://circleci.com/gh/bluebill1049/react-hook-form.svg?style=svg)](https://circleci.com/gh/bluebill1049/react-hook-form) [![Coverage Status](https://coveralls.io/repos/github/bluebill1049/react-hook-form/badge.svg?branch=master)](https://coveralls.io/github/bluebill1049/react-hook-form?branch=master) [![npm downloads](https://img.shields.io/npm/dm/react-hook-form.svg?style=flat-square)](https://www.npmjs.com/package/react-hook-form)
[![npm](https://img.shields.io/npm/dt/react-hook-form.svg?style=flat-square)](https://www.npmjs.com/package/react-hook-form)
[![npm](https://img.shields.io/npm/l/react-hook-form.svg?style=flat-square)](https://www.npmjs.com/package/react-lazyload-image)
[![Donate](https://img.shields.io/badge/donate-paypal-orange.svg?style=flat-square)](https://www.paypal.com/donate/?token=_m4SCZMEfepZQZn6nTYqdf7_8aheqLH1Rpy8oteP8nUlD0Ubp1nm4hGcPos5KACFr4AW7m&country.x=AU&locale.x=AU)

@@ -17,3 +18,3 @@ - Super easy to create forms and integrate

$ npm install react-forme
$ npm install react-hook-form

@@ -20,0 +21,0 @@ ## [Website](https://react-hook-form.now.sh/api)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc