Created
August 29, 2017 00:41
-
-
Save rakibulalam/983ad451cbdba3a897f5adf7ba216e11 to your computer and use it in GitHub Desktop.
Schema validation ES6
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
// object validation rules | |
const schema = { | |
first: { | |
required:true | |
}, | |
last: { | |
required:true | |
} | |
} | |
// universal validation function | |
const validate = (schema, values) => { | |
for(field in schema) { | |
if(schema[field].required) { | |
if(!values[field]) { | |
return false; | |
} | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment