UNPKG

uhtml

Version:
54 lines (46 loc) • 1.23 kB
'use strict'; const { isArray } = Array; const { getPrototypeOf, getOwnPropertyDescriptor } = Object; exports.isArray = isArray; const SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; exports.SVG_NAMESPACE = SVG_NAMESPACE; const empty = []; exports.empty = empty; const newRange = () => document.createRange(); exports.newRange = newRange; /** * Set the `key` `value` pair to the *Map* or *WeakMap* and returns the `value` * @template T * @param {Map | WeakMap} map * @param {any} key * @param {T} value * @returns {T} */ const set = (map, key, value) => { map.set(key, value); return value; }; exports.set = set; /** * Return a descriptor, if any, for the referenced *Element* * @param {Element} ref * @param {string} prop * @returns */ const gPD = (ref, prop) => { let desc; do { desc = getOwnPropertyDescriptor(ref, prop); } while(!desc && (ref = getPrototypeOf(ref))); return desc; }; exports.gPD = gPD; /* c8 ignore start */ /** * @param {DocumentFragment} content * @param {number[]} path * @returns {Element} */ const find = (content, path) => path.reduceRight(childNodesIndex, content); exports.find = find; const childNodesIndex = (node, i) => node.childNodes[i]; /* c8 ignore stop */