-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathutils.js
More file actions
46 lines (39 loc) · 1.07 KB
/
utils.js
File metadata and controls
46 lines (39 loc) · 1.07 KB
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
38
39
40
41
42
43
44
45
46
const { isArray } = Array;
const { getPrototypeOf, getOwnPropertyDescriptor } = Object;
export { isArray };
export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
export const empty = [];
export const newRange = () => document.createRange();
/**
* 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}
*/
export const set = (map, key, value) => {
map.set(key, value);
return value;
};
/**
* Return a descriptor, if any, for the referenced *Element*
* @param {Element} ref
* @param {string} prop
* @returns
*/
export const gPD = (ref, prop) => {
let desc;
do { desc = getOwnPropertyDescriptor(ref, prop); }
while(!desc && (ref = getPrototypeOf(ref)));
return desc;
};
/* c8 ignore start */
/**
* @param {DocumentFragment} content
* @param {number[]} path
* @returns {Element}
*/
export const find = (content, path) => path.reduceRight(childNodesIndex, content);
const childNodesIndex = (node, i) => node.childNodes[i];
/* c8 ignore stop */