Skip to content

Instantly share code, notes, and snippets.

@haishanh
Created August 15, 2016 06:02
Show Gist options
  • Save haishanh/f585d8465b6086308148902edcdc7981 to your computer and use it in GitHub Desktop.
Save haishanh/f585d8465b6086308148902edcdc7981 to your computer and use it in GitHub Desktop.
Simple classNames
'use strict';
function cx() {
var classNames = [];
var args = Array.prototype.slice.call(arguments);
args.forEach(function (arg) {
if (Array.isArray(arg)) {
classNames = classNames.concat(arg);
} else if (typeof arg === 'object') {
for (var prop in arg) {
if (arg[prop]) {
classNames.push(prop);
}
}
} else {
classNames.push(arg.toString());
}
});
return classNames.join(' ');
}
module.exports = cx;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment