Created
September 2, 2022 09:26
-
-
Save sakshstore/69e5d3b8fc67eb3054326600df83ab5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 validateObject = (object, rules) => | |
Object.keys(rules).every((key) => rules[key](object[key])); | |
// Usage | |
const rules = { | |
name: (name) => name.length > 0, | |
email: (email) => validateEmail(email), | |
password: (password) => password.length > 0, | |
}; | |
validateObject({ name: "", email: "", password: "" }, rules); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment