Created
August 15, 2016 06:02
-
-
Save haishanh/f585d8465b6086308148902edcdc7981 to your computer and use it in GitHub Desktop.
Simple classNames
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
'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