UNPKG

1.11 kBJavaScriptView Raw
1/*!
2 Copyright (c) 2015 Jed Watson.
3 Licensed under the MIT License (MIT), see
4 http://jedwatson.github.io/classnames
5*/
6/* global define */
7
8(function () {
9 'use strict';
10
11 var hasOwn = {}.hasOwnProperty;
12
13 function classNames () {
14 var classes = '';
15
16 for (var i = 0; i < arguments.length; i++) {
17 var arg = arguments[i];
18 if (!arg) continue;
19
20 var argType = typeof arg;
21
22 if (argType === 'string' || argType === 'number') {
23 classes += ' ' + arg;
24 } else if (Array.isArray(arg)) {
25 classes += ' ' + classNames.apply(null, arg);
26 } else if (argType === 'object') {
27 for (var key in arg) {
28 if (hasOwn.call(arg, key) && arg[key]) {
29 classes += ' ' + key;
30 }
31 }
32 }
33 }
34
35 return classes.substr(1);
36 }
37
38 if (typeof module !== 'undefined' && module.exports) {
39 module.exports = classNames;
40 } else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
41 // register as 'classnames', consistent with npm package name
42 define('classnames', [], function () {
43 return classNames;
44 });
45 } else {
46 window.classNames = classNames;
47 }
48}());