blob: 534936516b216561b54efb95ce67c8dbc5f0fd33 (
plain)
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
|
function h(tagName, text, attributes, children) {
/* allow for not adding text */
if (children === undefined && typeof(text) === 'object') {
children = attributes;
attributes = text;
text = null;
}
/* allow for not adding attributes */
if (children === undefined && Array.isArray(attributes)) {
children = attributes;
attributes = {};
}
/* allow for not adding children */
if (children === undefined) {
children = [];
}
const element = document.createElement(tagName);
if (text)
element.appendChild(document.createTextNode(text));
for (let key in attributes) {
const value = attributes[key];
element.setAttribute(key, value);
}
for (let child of children)
element.appendChild(child);
return element;
}
export default h;
|