Created
June 22, 2018 03:24
-
-
Save joshburgess/f106ae44b8eea9e11a99f4acca55a150 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
const classNamesBy = mapper => R.compose( | |
R.trim, | |
R.join(' '), | |
R.chain(mapper), | |
R.toPairs, | |
) | |
const classNames = R.curry((base, obj) => { | |
const standard = ([k, v]) => [v ? k : ''] | |
const reversed = R.compose(standard, R.reverse) | |
const baseResult = typeof base === 'string' | |
? base | |
: classNamesBy(reversed)(base) | |
return R.compose( | |
classes => `${baseResult} ${classes}`, | |
classNamesBy(standard), | |
)(obj) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment