UNPKG

988 BJavaScriptView Raw
1/*!
2 Copyright (c) 2015 Jed Watson.
3 Licensed under the MIT License (MIT), see
4 http://jedwatson.github.io/classnames
5*/
6
7function classNames() {
8 var classes = '';
9 var arg;
10
11 for (var i = 0; i < arguments.length; i++) {
12 arg = arguments[i];
13 if (!arg) {
14 continue;
15 }
16
17 if ('string' === typeof arg || 'number' === typeof arg) {
18 classes += ' ' + arg;
19 } else if (Object.prototype.toString.call(arg) === '[object Array]') {
20 classes += ' ' + classNames.apply(null, arg);
21 } else if ('object' === typeof arg) {
22 for (var key in arg) {
23 if (!arg.hasOwnProperty(key) || !arg[key]) {
24 continue;
25 }
26 classes += ' ' + key;
27 }
28 }
29 }
30 return classes.substr(1);
31}
32
33// safely export classNames for node / browserify
34if (typeof module !== 'undefined' && module.exports) {
35 module.exports = classNames;
36}
37
38// safely export classNames for RequireJS
39if (typeof define !== 'undefined' && define.amd) {
40 define('classnames', [], function() {
41 return classNames;
42 });
43}