Created
September 2, 2020 13:40
-
-
Save jktravis/ea99ef9d6c9c266e561b812ed6eba47e 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
/** | |
* A "parser" of an object similar to classnames. | |
* Includes the key and value when the include prop is truthy | |
* Filters out the key/value otherwise. | |
*/ | |
const reduce = require('lodash/fp/reduce'); | |
const toPairs = require('lodash/fp/toPairs'); | |
const compose = require('lodash/fp/compose'); | |
function reducer(result, [key, [value, include]]) { | |
if (include) { | |
result[key] = value; | |
} | |
return result; | |
} | |
const parse = compose(reduce(reducer, {}), toPairs) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment