Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { map, is, filter, keys, compose, identity, join } from 'ramda'
- const processObj = compose(classnames, keys, filter(identity))
- const processArr = compose(join(' '), filter(identity), map(classnames))
- function classnames (arg) {
- switch (true) {
- case is(String, arg): return arg
- case is(Array, arg): return processArr(arg)
- case is(Object, arg): return processObj(arg)
- default: return null
- }
- }
- const cn = (...args) => classnames(args)
- describe.only('classnames', function () {
- it('merges simple strings', function () {
- expect(cn('first', 'second')).to.eq('first second')
- })
- it('merges array simple strings', function () {
- expect(cn(['first', 'second'])).to.eq('first second')
- })
- it('merges object of strings/predicates', function () {
- expect(cn({ 'first': true, 'second': false })).to.eq('first')
- })
- it('merges damn complex case', function () {
- expect(cn('first', { 'second': true }, [{ 'third': false, 'fourth': true }])).to.eq('first second fourth')
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement