-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdedupe.js
47 lines (43 loc) · 1.09 KB
/
dedupe.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
'use strict'
var SPACE = /\s/
var MULTI_SPACE = /\s+/
var HAS_OWN = {}.hasOwnProperty
function process(ref, args) {
for (var i = 0, len = args.length, arg, str, j, len2, arr; i < len; ++i) {
if ((arg = args[i])) {
if ((str = typeof arg) === 'string') {
if (SPACE.test(arg)) {
for (j = 0, arr = arg.split(MULTI_SPACE), len2 = arr.length; j < len2; ++j) ref[arr[j]] = 0
} else ref[arg] = 0
} else if (Array.isArray(arg)) {
process(ref, arg)
} else if (str === 'object') {
for (str in arg) {
/* istanbul ignore next */
if (HAS_OWN.call(arg, str)) {
if (arg[str]) {
if (str) ref[str] = 0
} else if (0 === ref[str]) {
delete ref[str]
}
}
}
} else if (str === 'number') {
ref[arg] = 0
}
}
}
return ref
}
function O() {}
O.prototype = Object.create(null)
module.exports = function () {
var s = '',
c,
classNames = process(new O(), arguments)
for (c in classNames) {
if (s) s += ' '
s += c
}
return s
}