UNPKG

1.35 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.nextElementSibling = exports.getName = exports.hasAttrib = exports.getAttributeValue = exports.getSiblings = exports.getParent = exports.getChildren = void 0;
4function getChildren(elem) {
5 return elem.children || null;
6}
7exports.getChildren = getChildren;
8function getParent(elem) {
9 return elem.parent || null;
10}
11exports.getParent = getParent;
12function getSiblings(elem) {
13 var parent = getParent(elem);
14 return parent ? getChildren(parent) : [elem];
15}
16exports.getSiblings = getSiblings;
17function getAttributeValue(elem, name) {
18 var _a;
19 return (_a = elem.attribs) === null || _a === void 0 ? void 0 : _a[name];
20}
21exports.getAttributeValue = getAttributeValue;
22function hasAttrib(elem, name) {
23 return (!!elem.attribs &&
24 Object.prototype.hasOwnProperty.call(elem.attribs, name) &&
25 elem.attribs[name] != null);
26}
27exports.hasAttrib = hasAttrib;
28/***
29 * Returns the name property of an element
30 *
31 * @param elem The element to get the name for
32 */
33function getName(elem) {
34 return elem.name;
35}
36exports.getName = getName;
37function nextElementSibling(elem) {
38 var node = elem.next;
39 while (node !== null && node.type !== "tag")
40 node = node.next;
41 return node;
42}
43exports.nextElementSibling = nextElementSibling;