Last active
September 11, 2018 14:37
-
-
Save wholypantalones/8deb31d01d6fc8e4c13d618398d5c77a to your computer and use it in GitHub Desktop.
Params obj from config block
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
config = { | |
page: 0, | |
pageSize: 25, | |
sortColumn: 'publishDate', | |
sortDirection: 'ASC' | |
}; | |
/** | |
* loop through the config block and delete the things we do not need | |
* to make a params obj from the config obj | |
*/ | |
objFromConfig(obj) { | |
const newObj = JSON.parse(JSON.stringify(obj)); | |
Object.entries(newObj).map(([k, v]) => { | |
if (v === null || v === '') { | |
delete newObj[k]; | |
} | |
}); | |
return newObj; | |
} | |
// usage: params = this.objFromConfig(config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment