Skip to content

Instantly share code, notes, and snippets.

@joshburgess
Created June 22, 2018 03:24
Show Gist options
  • Save joshburgess/f106ae44b8eea9e11a99f4acca55a150 to your computer and use it in GitHub Desktop.
Save joshburgess/f106ae44b8eea9e11a99f4acca55a150 to your computer and use it in GitHub Desktop.
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