I want to create JavaScript function that takes a object and schema and validate and get a detailed errors. In this case im using yup library .
Its possible with using hookform and resolvers in react but I cant figure out how to do without them.
Validation.ts
import * as Yup from "yup";
export const Validation = async (object: any, schema: Yup.ObjectSchema<any>) => {
try {
const repsonse = await schema.validate(object, { abortEarly: false });
console.log(repsonse);
} catch (e: any) {
console.log(e);
}
};
but console.log(e) only output error like :
ValidationError: 5 errors occurred
at finishTestRun (runTests.js:54:1)
at runTests.js:8:1
at finishTestRun (runTests.js:54:1)
at createValidation.js:60:1
expected output
{
errors: [
{
path: "email",
message: ["email must be a valid email"],
},
.....
]
}