Advertisement
Guest User

Untitled

a guest
May 1st, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import { map, is, filter, keys, compose, identity, join } from 'ramda'
  2.  
  3. const processObj = compose(classnames, keys, filter(identity))
  4.  
  5. const processArr = compose(join(' '), filter(identity), map(classnames))
  6.  
  7. function classnames (arg) {
  8. switch (true) {
  9. case is(String, arg): return arg
  10. case is(Array, arg): return processArr(arg)
  11. case is(Object, arg): return processObj(arg)
  12. default: return null
  13. }
  14. }
  15.  
  16. const cn = (...args) => classnames(args)
  17.  
  18. describe.only('classnames', function () {
  19. it('merges simple strings', function () {
  20. expect(cn('first', 'second')).to.eq('first second')
  21. })
  22. it('merges array simple strings', function () {
  23. expect(cn(['first', 'second'])).to.eq('first second')
  24. })
  25. it('merges object of strings/predicates', function () {
  26. expect(cn({ 'first': true, 'second': false })).to.eq('first')
  27. })
  28. it('merges damn complex case', function () {
  29. expect(cn('first', { 'second': true }, [{ 'third': false, 'fourth': true }])).to.eq('first second fourth')
  30. })
  31. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement