-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathrenderAttributes.js
More file actions
25 lines (24 loc) · 895 Bytes
/
renderAttributes.js
File metadata and controls
25 lines (24 loc) · 895 Bytes
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
import generateTruthyString from '../shared/generateTruthyString'
export default function renderAttributes(attributes) {
let element = ''
for (const name in attributes) {
if (name === 'debounce') continue
if (!name.startsWith('on') && name !== 'html') {
let attribute = attributes[name]
if ((name === 'class' || name === 'style') && Array.isArray(attributes[name])) {
attribute = generateTruthyString(attributes[name])
} else {
attribute = attributes[name]
}
const type = typeof attribute
if (type !== 'object' && type !== 'function') {
if (name !== 'value' && attribute === true) {
element += ` ${name}`
} else if (name === 'value' || (attribute !== false && attribute !== null && attribute !== undefined)) {
element += ` ${name}="${attribute}"`
}
}
}
}
return element
}