-
Notifications
You must be signed in to change notification settings - Fork 1
/
cx.js
65 lines (61 loc) · 1.47 KB
/
cx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict'
var HAS_OWN = {}.hasOwnProperty
function getClass(arg) {
if (typeof arg === 'string') return arg
var s,
className = ''
if (Array.isArray(arg)) {
for (var k = 0, len = arg.length; k < len; ++k) {
if ((s = arg[k]))
if ((s = getClass(s))) {
if (className) className += ' '
className += s
}
}
return className
}
if (typeof arg === 'object') {
for (s in arg) {
if (arg[s] && s) {
/* istanbul ignore next */
if (HAS_OWN.call(arg, s)) {
if (className) className += ' '
className += s
}
}
}
return className
}
if (typeof arg === 'number') return '' + arg
return className
}
module.exports = function (arg0) {
var className = '',
len = arguments.length,
str
// Most common cases. Though a bit redundant, it's just way faster...
if (1 == len) {
if (typeof arg0 === 'string') return arg0
if (!Array.isArray(arg0) && typeof arg0 === 'object') {
for (str in arg0) {
if (arg0[str] && str) {
/* istanbul ignore next */
if (HAS_OWN.call(arg0, str)) {
if (className) className += ' '
className += str
}
}
}
return className
}
}
// General cases
for (var i = 0; i < len; ++i) {
if ((str = arguments[i]))
if ((str = getClass(str))) {
if (className) className += ' '
className += str
}
}
return className
}