Created
September 23, 2020 16:08
-
-
Save theodoregold/0fa956f5821a6d45c298aca8ec69cc08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const obj = { | |
name: "John Doe", | |
email: "john.doe@company.space", | |
firstName: "John", | |
phone: "123-4567", | |
age: 33, | |
}; | |
const Validator = require("fastest-validator"); | |
const v = new Validator(); | |
const constraints = { | |
name: { | |
type: "string", | |
min: 4, | |
max: 25, | |
}, | |
email: { type: "email" }, | |
firstName: { type: "string" }, | |
phone: { type: "string" }, | |
age: { | |
type: "number", | |
min: 18, | |
}, | |
}; | |
let check = v.compile(constraints); | |
console.time(); | |
let testObj = obj; | |
console.log(check(testObj)); | |
// console.log(v.validate(testObj, constraints)); | |
console.timeEnd(); | |
//---- | |
// const yup = require("yup"); | |
// const schema = yup.object().shape({ | |
// name: yup.string().min(4).max(25).required(), | |
// email: yup.string().email().required(), | |
// firstName: yup.mixed().required(), | |
// phone: yup.mixed().required(), | |
// age: yup.number().integer().min(18).required(), | |
// }); | |
// console.time(); | |
// schema.isValid(obj).then((r) => { | |
// console.log(r); | |
// console.timeEnd(); | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment