Skip to content

Instantly share code, notes, and snippets.

@sakshstore
Created September 2, 2022 09:26
Show Gist options
  • Save sakshstore/69e5d3b8fc67eb3054326600df83ab5a to your computer and use it in GitHub Desktop.
Save sakshstore/69e5d3b8fc67eb3054326600df83ab5a to your computer and use it in GitHub Desktop.
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