Last active
July 22, 2022 03:12
-
-
Save pokedotdev/d46d439814d503a373e197fda9c951c2 to your computer and use it in GitHub Desktop.
Join class names
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
function toVal(mix) { | |
var k, y, str=''; | |
if (typeof mix === 'string' || typeof mix === 'number') { | |
str += mix; | |
} else if (typeof mix === 'object') { | |
if (Array.isArray(mix)) { | |
for (k=0; k < mix.length; k++) { | |
if (mix[k]) { | |
if (y = toVal(mix[k])) { | |
str && (str += ' '); | |
str += y; | |
} | |
} | |
} | |
} else { | |
for (k in mix) { | |
if (mix[k]) { | |
str && (str += ' '); | |
str += k; | |
} | |
} | |
} | |
} | |
return str; | |
} | |
function cx() { | |
var i=0, tmp, x, str=''; | |
while (i < arguments.length) { | |
if (tmp = arguments[i++]) { | |
if (x = toVal(tmp)) { | |
str && (str += ' '); | |
str += x; | |
} | |
} | |
} | |
return str; | |
} | |
cx("boo", "oh no", "lol", "", "OH NO"); |
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
function cx(...strings) { | |
return strings.filter(Boolean).join(' '); | |
} | |
cx("boo", "oh no", "lol", "", "OH NO"); |
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
function cx(...strings) { | |
return strings.join(' '); | |
} | |
cx("boo", "oh no", "lol", "", "OH NO"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment