Skip to content

Instantly share code, notes, and snippets.

@jktravis
Created September 2, 2020 13:40
Show Gist options
  • Save jktravis/ea99ef9d6c9c266e561b812ed6eba47e to your computer and use it in GitHub Desktop.
Save jktravis/ea99ef9d6c9c266e561b812ed6eba47e to your computer and use it in GitHub Desktop.
/**
* 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