react-hook-form
Advanced tools
Comparing version 0.4.0 to 1.0.0
@@ -52,3 +52,5 @@ declare type Validate = (data: string | number) => boolean | string | number | Date; | ||
[key: string]: { | ||
string: boolean | string; | ||
ref: any; | ||
message: string | boolean; | ||
type: string; | ||
} | {}; | ||
@@ -55,0 +57,0 @@ } |
@@ -71,3 +71,3 @@ import { useRef, useState, useEffect } from 'react'; | ||
var validateField = ({ ref: { type, value, name, checked }, options, required, maxLength, minLength, min, max, pattern, validate }, fields) => { | ||
var validateField = ({ ref, ref: { type, value, name, checked }, options, required, maxLength, minLength, min, max, pattern, validate }, fields) => { | ||
const copy = {}; | ||
@@ -79,7 +79,8 @@ if (required && | ||
copy[name] = { | ||
required, | ||
type: 'required', | ||
message: required, | ||
ref, | ||
}; | ||
return copy; | ||
} | ||
if (value === '') | ||
return copy; | ||
// min and max section | ||
@@ -102,5 +103,10 @@ if (min || max) { | ||
} | ||
if (exceedMax || exceedMin) { | ||
copy[name] = Object.assign({}, copy[name], (exceedMax ? { max: maxMessage } : null), (exceedMin ? { min: minMessage } : null)); | ||
if (exceedMax) { | ||
copy[name] = Object.assign({}, copy[name], { type: 'max', message: maxMessage, ref }); | ||
return copy; | ||
} | ||
if (exceedMin) { | ||
copy[name] = Object.assign({}, copy[name], { type: 'min', message: minMessage, ref }); | ||
return copy; | ||
} | ||
} | ||
@@ -112,5 +118,10 @@ if ((maxLength || minLength) && STRING_INPUTS.includes(type)) { | ||
const exceedMin = minLength && value.toString().length < minLengthValue; | ||
if (exceedMax || exceedMin) { | ||
copy[name] = Object.assign({}, copy[name], (exceedMax ? { maxLength: maxLengthMessage } : null), (exceedMin ? { minLength: minLengthMessage } : null)); | ||
if (exceedMax) { | ||
copy[name] = Object.assign({}, copy[name], { type: 'maxLength', message: maxLengthMessage, ref }); | ||
return copy; | ||
} | ||
if (exceedMin) { | ||
copy[name] = Object.assign({}, copy[name], { type: 'minLength', message: minLengthMessage, ref }); | ||
return copy; | ||
} | ||
} | ||
@@ -120,3 +131,4 @@ if (pattern) { | ||
if (patternValue instanceof RegExp && !patternValue.test(value)) { | ||
copy[name] = Object.assign({}, copy[name], { pattern: patternMessage }); | ||
copy[name] = Object.assign({}, copy[name], { type: 'pattern', message: patternMessage, ref }); | ||
return copy; | ||
} | ||
@@ -129,3 +141,4 @@ } | ||
if (typeof result !== 'boolean' || !result) { | ||
copy[name] = Object.assign({}, copy[name], { validate: result || true }); | ||
copy[name] = Object.assign({}, copy[name], { type: 'validate', message: result || true, ref }); | ||
return copy; | ||
} | ||
@@ -136,9 +149,14 @@ } | ||
const result = typeof validate === 'function' && validate(fieldValue); | ||
if (Object.keys(previous).length) | ||
return previous; | ||
if (typeof result !== 'boolean' || !result) { | ||
previous[key] = result || true; | ||
return { | ||
type: key, | ||
message: result || true, | ||
}; | ||
} | ||
return previous; | ||
}, {}); | ||
if (Object.keys(result).length) { | ||
copy[name] = Object.assign({}, copy[name], { validate: result }); | ||
copy[name] = Object.assign({}, copy[name], { ref }, result); | ||
return copy; | ||
} | ||
@@ -145,0 +163,0 @@ } |
@@ -73,3 +73,3 @@ 'use strict'; | ||
var validateField = ({ ref: { type, value, name, checked }, options, required, maxLength, minLength, min, max, pattern, validate }, fields) => { | ||
var validateField = ({ ref, ref: { type, value, name, checked }, options, required, maxLength, minLength, min, max, pattern, validate }, fields) => { | ||
const copy = {}; | ||
@@ -81,7 +81,8 @@ if (required && | ||
copy[name] = { | ||
required, | ||
type: 'required', | ||
message: required, | ||
ref, | ||
}; | ||
return copy; | ||
} | ||
if (value === '') | ||
return copy; | ||
// min and max section | ||
@@ -104,5 +105,10 @@ if (min || max) { | ||
} | ||
if (exceedMax || exceedMin) { | ||
copy[name] = Object.assign({}, copy[name], (exceedMax ? { max: maxMessage } : null), (exceedMin ? { min: minMessage } : null)); | ||
if (exceedMax) { | ||
copy[name] = Object.assign({}, copy[name], { type: 'max', message: maxMessage, ref }); | ||
return copy; | ||
} | ||
if (exceedMin) { | ||
copy[name] = Object.assign({}, copy[name], { type: 'min', message: minMessage, ref }); | ||
return copy; | ||
} | ||
} | ||
@@ -114,5 +120,10 @@ if ((maxLength || minLength) && STRING_INPUTS.includes(type)) { | ||
const exceedMin = minLength && value.toString().length < minLengthValue; | ||
if (exceedMax || exceedMin) { | ||
copy[name] = Object.assign({}, copy[name], (exceedMax ? { maxLength: maxLengthMessage } : null), (exceedMin ? { minLength: minLengthMessage } : null)); | ||
if (exceedMax) { | ||
copy[name] = Object.assign({}, copy[name], { type: 'maxLength', message: maxLengthMessage, ref }); | ||
return copy; | ||
} | ||
if (exceedMin) { | ||
copy[name] = Object.assign({}, copy[name], { type: 'minLength', message: minLengthMessage, ref }); | ||
return copy; | ||
} | ||
} | ||
@@ -122,3 +133,4 @@ if (pattern) { | ||
if (patternValue instanceof RegExp && !patternValue.test(value)) { | ||
copy[name] = Object.assign({}, copy[name], { pattern: patternMessage }); | ||
copy[name] = Object.assign({}, copy[name], { type: 'pattern', message: patternMessage, ref }); | ||
return copy; | ||
} | ||
@@ -131,3 +143,4 @@ } | ||
if (typeof result !== 'boolean' || !result) { | ||
copy[name] = Object.assign({}, copy[name], { validate: result || true }); | ||
copy[name] = Object.assign({}, copy[name], { type: 'validate', message: result || true, ref }); | ||
return copy; | ||
} | ||
@@ -138,9 +151,14 @@ } | ||
const result = typeof validate === 'function' && validate(fieldValue); | ||
if (Object.keys(previous).length) | ||
return previous; | ||
if (typeof result !== 'boolean' || !result) { | ||
previous[key] = result || true; | ||
return { | ||
type: key, | ||
message: result || true, | ||
}; | ||
} | ||
return previous; | ||
}, {}); | ||
if (Object.keys(result).length) { | ||
copy[name] = Object.assign({}, copy[name], { validate: result }); | ||
copy[name] = Object.assign({}, copy[name], { ref }, result); | ||
return copy; | ||
} | ||
@@ -147,0 +165,0 @@ } |
import { ErrorMessages, Field } from '..'; | ||
declare const _default: ({ ref: { type, value, name, checked }, options, required, maxLength, minLength, min, max, pattern, validate }: Field, fields: { | ||
declare const _default: ({ ref, ref: { type, value, name, checked }, options, required, maxLength, minLength, min, max, pattern, validate }: Field, fields: { | ||
[key: string]: Field; | ||
}) => ErrorMessages; | ||
export default _default; |
{ | ||
"name": "react-hook-form", | ||
"version": "0.4.0", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.es.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
41516
935
1