123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.getChildren = getChildren;
- exports.getParent = getParent;
- exports.getSiblings = getSiblings;
- exports.getAttributeValue = getAttributeValue;
- exports.hasAttrib = hasAttrib;
- exports.getName = getName;
- exports.nextElementSibling = nextElementSibling;
- exports.prevElementSibling = prevElementSibling;
- var domhandler_1 = require("domhandler");
- function getChildren(elem) {
- return (0, domhandler_1.hasChildren)(elem) ? elem.children : [];
- }
- function getParent(elem) {
- return elem.parent || null;
- }
- function getSiblings(elem) {
- var _a, _b;
- var parent = getParent(elem);
- if (parent != null)
- return getChildren(parent);
- var siblings = [elem];
- var prev = elem.prev, next = elem.next;
- while (prev != null) {
- siblings.unshift(prev);
- (_a = prev, prev = _a.prev);
- }
- while (next != null) {
- siblings.push(next);
- (_b = next, next = _b.next);
- }
- return siblings;
- }
- function getAttributeValue(elem, name) {
- var _a;
- return (_a = elem.attribs) === null || _a === void 0 ? void 0 : _a[name];
- }
- function hasAttrib(elem, name) {
- return (elem.attribs != null &&
- Object.prototype.hasOwnProperty.call(elem.attribs, name) &&
- elem.attribs[name] != null);
- }
- function getName(elem) {
- return elem.name;
- }
- function nextElementSibling(elem) {
- var _a;
- var next = elem.next;
- while (next !== null && !(0, domhandler_1.isTag)(next))
- (_a = next, next = _a.next);
- return next;
- }
- function prevElementSibling(elem) {
- var _a;
- var prev = elem.prev;
- while (prev !== null && !(0, domhandler_1.isTag)(prev))
- (_a = prev, prev = _a.prev);
- return prev;
- }
|