forked from ohmjs/ohm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
37 lines (32 loc) · 839 Bytes
/
lib.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
/* eslint-env browser */
'use strict';
window.makeElement = function(tagName, ...children) {
const element = document.createElement(tagName);
for (const child of children) {
const childEl = typeof child === 'string' ? document.createTextNode(child) : child;
element.appendChild(childEl);
}
return element;
};
window.removeChildren = function(element) {
while (element.firstChild) {
element.removeChild(element.firstChild);
}
};
window.show = function(divId, what) {
if (!(what instanceof Node)) {
what = document.createTextNode('' + what);
}
const div = document.getElementById(divId);
while (div.firstChild) {
div.removeChild(div.firstChild);
}
div.appendChild(what);
};
window.repeat = function(s, n) {
const arr = [];
while (n-- > 0) {
arr.push(s);
}
return arr.join('');
};