-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathutils.js
More file actions
61 lines (48 loc) · 1.59 KB
/
Copy pathutils.js
File metadata and controls
61 lines (48 loc) · 1.59 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const {ELEMENT_NODE} = require('./constants.js');
const {END, MIME, NEXT, PREV} = require('./symbols.js');
const $String = String;
exports.String = $String;
const getEnd = node => node.nodeType === ELEMENT_NODE ? node[END] : node;
exports.getEnd = getEnd;
const ignoreCase = ({ownerDocument}) => ownerDocument[MIME].ignoreCase;
exports.ignoreCase = ignoreCase;
const knownAdjacent = (prev, next) => {
prev[NEXT] = next;
next[PREV] = prev;
};
exports.knownAdjacent = knownAdjacent;
const knownBoundaries = (prev, current, next) => {
knownAdjacent(prev, current);
knownAdjacent(getEnd(current), next);
};
exports.knownBoundaries = knownBoundaries;
const knownSegment = (prev, start, end, next) => {
knownAdjacent(prev, start);
knownAdjacent(getEnd(end), next);
};
exports.knownSegment = knownSegment;
const knownSiblings = (prev, current, next) => {
knownAdjacent(prev, current);
knownAdjacent(current, next);
};
exports.knownSiblings = knownSiblings;
const localCase = ({localName, ownerDocument}) => {
return ownerDocument[MIME].ignoreCase ? localName.toUpperCase() : localName;
};
exports.localCase = localCase;
const setAdjacent = (prev, next) => {
if (prev)
prev[NEXT] = next;
if (next)
next[PREV] = prev;
};
exports.setAdjacent = setAdjacent;
const htmlToFragment = (ownerDocument, html) => {
const fragment = ownerDocument.createDocumentFragment();
const elem = ownerDocument.createElement('');
elem.innerHTML = html;
for (const node of elem.childNodes) fragment.appendChild(node.cloneNode(true));
return fragment;
};
exports.htmlToFragment = htmlToFragment;