traversal.d.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { AnyNode, ChildNode, Element, ParentNode } from "domhandler";
  2. /**
  3. * Get a node's children.
  4. *
  5. * @category Traversal
  6. * @param elem Node to get the children of.
  7. * @returns `elem`'s children, or an empty array.
  8. */
  9. export declare function getChildren(elem: AnyNode): ChildNode[];
  10. export declare function getParent(elem: AnyNode): ParentNode | null;
  11. /**
  12. * Gets an elements siblings, including the element itself.
  13. *
  14. * Attempts to get the children through the element's parent first. If we don't
  15. * have a parent (the element is a root node), we walk the element's `prev` &
  16. * `next` to get all remaining nodes.
  17. *
  18. * @category Traversal
  19. * @param elem Element to get the siblings of.
  20. * @returns `elem`'s siblings.
  21. */
  22. export declare function getSiblings(elem: AnyNode): AnyNode[];
  23. /**
  24. * Gets an attribute from an element.
  25. *
  26. * @category Traversal
  27. * @param elem Element to check.
  28. * @param name Attribute name to retrieve.
  29. * @returns The element's attribute value, or `undefined`.
  30. */
  31. export declare function getAttributeValue(elem: Element, name: string): string | undefined;
  32. /**
  33. * Checks whether an element has an attribute.
  34. *
  35. * @category Traversal
  36. * @param elem Element to check.
  37. * @param name Attribute name to look for.
  38. * @returns Returns whether `elem` has the attribute `name`.
  39. */
  40. export declare function hasAttrib(elem: Element, name: string): boolean;
  41. /**
  42. * Get the tag name of an element.
  43. *
  44. * @category Traversal
  45. * @param elem The element to get the name for.
  46. * @returns The tag name of `elem`.
  47. */
  48. export declare function getName(elem: Element): string;
  49. /**
  50. * Returns the next element sibling of a node.
  51. *
  52. * @category Traversal
  53. * @param elem The element to get the next sibling of.
  54. * @returns `elem`'s next sibling that is a tag.
  55. */
  56. export declare function nextElementSibling(elem: AnyNode): Element | null;
  57. /**
  58. * Returns the previous element sibling of a node.
  59. *
  60. * @category Traversal
  61. * @param elem The element to get the previous sibling of.
  62. * @returns `elem`'s previous sibling that is a tag.
  63. */
  64. export declare function prevElementSibling(elem: AnyNode): Element | null;
  65. //# sourceMappingURL=traversal.d.ts.map