UNPKG

712 BJavaScriptView Raw
1/**
2 * Assign properties from `props` to `obj`
3 * @template O, P The obj and props types
4 * @param {O} obj The object to copy properties to
5 * @param {P} props The object to copy properties from
6 * @returns {O & P}
7 */
8export function assign(obj, props) {
9 for (let i in props) obj[i] = props[i];
10 return /** @type {O & P} */ (obj);
11}
12
13/**
14 * Remove a child node from its parent if attached. This is a workaround for
15 * IE11 which doesn't support `Element.prototype.remove()`. Using this function
16 * is smaller than including a dedicated polyfill.
17 * @param {Node} node The node to remove
18 */
19export function removeNode(node) {
20 let parentNode = node.parentNode;
21 if (parentNode) parentNode.removeChild(node);
22}