helpers.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { AnyNode } from "domhandler";
  2. /**
  3. * Given an array of nodes, remove any member that is contained by another.
  4. *
  5. * @category Helpers
  6. * @param nodes Nodes to filter.
  7. * @returns Remaining nodes that aren't subtrees of each other.
  8. */
  9. export declare function removeSubsets(nodes: AnyNode[]): AnyNode[];
  10. /**
  11. * @category Helpers
  12. * @see {@link http://dom.spec.whatwg.org/#dom-node-comparedocumentposition}
  13. */
  14. export declare const enum DocumentPosition {
  15. DISCONNECTED = 1,
  16. PRECEDING = 2,
  17. FOLLOWING = 4,
  18. CONTAINS = 8,
  19. CONTAINED_BY = 16
  20. }
  21. /**
  22. * Compare the position of one node against another node in any other document.
  23. * The return value is a bitmask with the values from {@link DocumentPosition}.
  24. *
  25. * Document order:
  26. * > There is an ordering, document order, defined on all the nodes in the
  27. * > document corresponding to the order in which the first character of the
  28. * > XML representation of each node occurs in the XML representation of the
  29. * > document after expansion of general entities. Thus, the document element
  30. * > node will be the first node. Element nodes occur before their children.
  31. * > Thus, document order orders element nodes in order of the occurrence of
  32. * > their start-tag in the XML (after expansion of entities). The attribute
  33. * > nodes of an element occur after the element and before its children. The
  34. * > relative order of attribute nodes is implementation-dependent.
  35. *
  36. * Source:
  37. * http://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-document-order
  38. *
  39. * @category Helpers
  40. * @param nodeA The first node to use in the comparison
  41. * @param nodeB The second node to use in the comparison
  42. * @returns A bitmask describing the input nodes' relative position.
  43. *
  44. * See http://dom.spec.whatwg.org/#dom-node-comparedocumentposition for
  45. * a description of these values.
  46. */
  47. export declare function compareDocumentPosition(nodeA: AnyNode, nodeB: AnyNode): number;
  48. /**
  49. * Sort an array of nodes based on their relative position in the document and
  50. * remove any duplicate nodes. If the array contains nodes that do not belong to
  51. * the same document, sort order is unspecified.
  52. *
  53. * @category Helpers
  54. * @param nodes Array of DOM nodes.
  55. * @returns Collection of unique nodes, sorted in document order.
  56. */
  57. export declare function uniqueSort<T extends AnyNode>(nodes: T[]): T[];
  58. //# sourceMappingURL=helpers.d.ts.map