-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·27 lines (24 loc) · 988 Bytes
/
index.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
'use strict'
module.exports = function (opts) {
opts = opts || {}
const separators = opts.separators || {}
const elementSeparator = separators.element || '__'
const modifierSeparator = ' ' + (separators.modifier || '-')
const mixinSeparator = ' '
function addClassNames (className, entries, separator) {
if (entries == null) return className
if ('string boolean numeric'.indexOf(typeof entries) >= 0) return className + separator + entries
if (Array.isArray(entries)) {
for (let i = 0, len = entries.length; i < len; ++i) className += separator + entries[i]
} else {
Object.keys(entries).forEach(prop => {
if (entries[prop]) className += separator + prop
})
}
return className
}
return function (block, element, modifiers, mixins) {
const className = element ? block + elementSeparator + element : block
return addClassNames(addClassNames(className, modifiers, modifierSeparator), mixins, mixinSeparator)
}
}