@hookform/resolvers
Advanced tools
Comparing version 0.2.0-beta.11 to 2.0.0-rc.1
@@ -1,3 +0,1 @@ | ||
import { Resolver } from 'react-hook-form'; | ||
import Joi from '@hapi/joi'; | ||
export declare const joiResolver: <TFieldValues extends Record<string, any>>(schema: Joi.Schema, options?: Joi.AsyncValidationOptions) => Resolver<TFieldValues, object>; | ||
export * from './dist/joi'; |
42
joi.js
@@ -1,41 +0,1 @@ | ||
import { transformToNestObject, appendErrors } from 'react-hook-form'; | ||
import convertArrayToPathName$1 from './utils/convertArrayToPathName.js'; | ||
const parseErrorSchema = (error, validateAllFieldCriteria) => Array.isArray(error.details) | ||
? error.details.reduce((previous, { path, message = '', type }) => { | ||
const currentPath = convertArrayToPathName$1(path); | ||
return Object.assign(Object.assign({}, previous), (path | ||
? previous[currentPath] && validateAllFieldCriteria | ||
? { | ||
[currentPath]: appendErrors(currentPath, validateAllFieldCriteria, previous, type, message), | ||
} | ||
: { | ||
[currentPath]: previous[currentPath] || Object.assign({ message, | ||
type }, (validateAllFieldCriteria | ||
? { | ||
types: { [type]: message || true }, | ||
} | ||
: {})), | ||
} | ||
: {})); | ||
}, {}) | ||
: []; | ||
const joiResolver = (schema, options = { | ||
abortEarly: false, | ||
}) => async (values, _, validateAllFieldCriteria = false) => { | ||
try { | ||
return { | ||
values: await schema.validateAsync(values, Object.assign({}, options)), | ||
errors: {}, | ||
}; | ||
} | ||
catch (e) { | ||
return { | ||
values: {}, | ||
errors: transformToNestObject(parseErrorSchema(e, validateAllFieldCriteria)), | ||
}; | ||
} | ||
}; | ||
export { joiResolver }; | ||
//# sourceMappingURL=joi.js.map | ||
module.exports = require('./dist/joi'); |
{ | ||
"name": "@hookform/resolvers", | ||
"version": "0.2.0-beta.11", | ||
"version": "2.0.0-rc.1", | ||
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct and etc.", | ||
"main": "cjs/index.js", | ||
"module": "index.js", | ||
"umd:main": "umd/index.production.min.js", | ||
"unpkg": "umd/index.production.min.js", | ||
"jsdelivr": "umd/index.production.min.js", | ||
"jsnext:main": "esm/index.js", | ||
"source": "src/index.ts", | ||
"types": "index.d.ts", | ||
"umd:main": "umd/index.js", | ||
"unpkg": "umd/index.js", | ||
"jsdelivr": "umd/index.js", | ||
"sideEffects": false, | ||
"files": [ | ||
"*" | ||
"dist", | ||
"yup.js", | ||
"yup.d.ts", | ||
"joi.js", | ||
"joi.d.ts", | ||
"superstruct.js", | ||
"superstruct.d.ts" | ||
], | ||
@@ -23,3 +24,6 @@ "publishConfig": { | ||
"prebuild": "npm run clean", | ||
"build": "cpy package.json README.md dist/ && node rollup/writeCjsEntryFile.js && rollup -c", | ||
"build": "run-p bundle bundle:ie11 bundle:umd", | ||
"bundle": "tsc", | ||
"bundle:ie11": "tsc --outDir dist/ie11 --downlevelIteration --target es5", | ||
"bundle:umd": "rollup -c", | ||
"lint": "eslint '**/*.{js,ts}'", | ||
@@ -30,3 +34,4 @@ "lint:fix": "npm run lint -- --fix", | ||
"test:watch": "npm run test -- --watchAll --coverage", | ||
"postversion": "git push && git push origin v$npm_package_version" | ||
"postversion": "git push && git push origin v$npm_package_version", | ||
"prepublishOnly": "npm run lint && npm run lint:types && npm test && npm run build" | ||
}, | ||
@@ -57,5 +62,3 @@ "keywords": [ | ||
"@rollup/plugin-commonjs": "^13.0.0", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^8.0.1", | ||
"@rollup/plugin-replace": "^2.3.3", | ||
"@types/hapi__joi": "^17.1.0", | ||
@@ -66,3 +69,2 @@ "@types/jest": "^26.0.0", | ||
"@typescript-eslint/parser": "^3.2.0", | ||
"cpy-cli": "^3.1.1", | ||
"eslint": "^7.2.0", | ||
@@ -74,2 +76,3 @@ "eslint-config-prettier": "^6.11.0", | ||
"lint-staged": "^10.2.10", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.0.5", | ||
@@ -80,4 +83,2 @@ "react": "^16.13.1", | ||
"rollup": "^2.16.1", | ||
"rollup-plugin-peer-deps-external": "^2.2.2", | ||
"rollup-plugin-sourcemaps": "^0.6.2", | ||
"rollup-plugin-terser": "^6.1.0", | ||
@@ -84,0 +85,0 @@ "rollup-plugin-typescript2": "^0.27.1", |
@@ -1,39 +0,1 @@ | ||
import { transformToNestObject, appendErrors } from 'react-hook-form'; | ||
import convertArrayToPathName$1 from './utils/convertArrayToPathName.js'; | ||
const parseErrorSchema = (error, validateAllFieldCriteria) => Array.isArray(error.failures) | ||
? error.failures.reduce((previous, { path, message = '', type }) => { | ||
const currentPath = convertArrayToPathName$1(path); | ||
return Object.assign(Object.assign({}, previous), (path | ||
? previous[currentPath] && validateAllFieldCriteria | ||
? { | ||
[currentPath]: appendErrors(currentPath, validateAllFieldCriteria, previous, type || '', message), | ||
} | ||
: { | ||
[currentPath]: previous[currentPath] || Object.assign({ message, | ||
type }, (validateAllFieldCriteria | ||
? { | ||
types: { [type || '']: message || true }, | ||
} | ||
: {})), | ||
} | ||
: {})); | ||
}, {}) | ||
: []; | ||
const superstructResolver = (schema) => async (values, _, validateAllFieldCriteria = false) => { | ||
try { | ||
return { | ||
values: schema(values), | ||
errors: {}, | ||
}; | ||
} | ||
catch (e) { | ||
return { | ||
values: {}, | ||
errors: transformToNestObject(parseErrorSchema(e, validateAllFieldCriteria)), | ||
}; | ||
} | ||
}; | ||
export { superstructResolver }; | ||
//# sourceMappingURL=superstruct.js.map | ||
module.exports = require('./dist/superstruct'); |
@@ -1,3 +0,1 @@ | ||
import { Resolver } from 'react-hook-form'; | ||
import Yup from 'yup'; | ||
export declare const yupResolver: <TFieldValues extends Record<string, any>>(schema: Yup.ObjectSchema | Yup.Lazy, options?: Omit<Yup.ValidateOptions, 'context'>) => Resolver<TFieldValues, object>; | ||
export * from './dist/yup'; |
50
yup.js
@@ -1,49 +0,1 @@ | ||
import { transformToNestObject } from 'react-hook-form'; | ||
const parseErrorSchema = (error, validateAllFieldCriteria) => Array.isArray(error.inner) && error.inner.length | ||
? error.inner.reduce((previous, { path, message, type }) => { | ||
const previousTypes = (previous[path] && previous[path].types) || {}; | ||
const key = path || type; | ||
return Object.assign(Object.assign({}, previous), (key | ||
? { | ||
[key]: Object.assign(Object.assign({}, (previous[key] || { | ||
message, | ||
type, | ||
})), (validateAllFieldCriteria | ||
? { | ||
types: Object.assign(Object.assign({}, previousTypes), { [type]: previousTypes[type] | ||
? [...[].concat(previousTypes[type]), message] | ||
: message }), | ||
} | ||
: {})), | ||
} | ||
: {})); | ||
}, {}) | ||
: { | ||
[error.path]: { message: error.message, type: error.type }, | ||
}; | ||
const yupResolver = (schema, options = { | ||
abortEarly: false, | ||
}) => async (values, context, validateAllFieldCriteria = false) => { | ||
try { | ||
if (options.context && | ||
process.env.NODE_ENV === 'development') { | ||
// eslint-disable-next-line no-console | ||
console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"); | ||
} | ||
return { | ||
values: (await schema.validate(values, Object.assign(Object.assign({}, options), { context }))), | ||
errors: {}, | ||
}; | ||
} | ||
catch (e) { | ||
const parsedErrors = parseErrorSchema(e, validateAllFieldCriteria); | ||
return { | ||
values: {}, | ||
errors: transformToNestObject(parsedErrors), | ||
}; | ||
} | ||
}; | ||
export { yupResolver }; | ||
//# sourceMappingURL=yup.js.map | ||
module.exports = require('./dist/yup'); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
26
2
53038
33
508