Skip to content

Instantly share code, notes, and snippets.

@pokedotdev
Last active July 22, 2022 03:12
Show Gist options
  • Save pokedotdev/d46d439814d503a373e197fda9c951c2 to your computer and use it in GitHub Desktop.
Save pokedotdev/d46d439814d503a373e197fda9c951c2 to your computer and use it in GitHub Desktop.
Join class names
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");
function cx(...strings) {
return strings.filter(Boolean).join(' ');
}
cx("boo", "oh no", "lol", "", "OH NO");
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