static.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import type { BasicAcceptedElems } from './types.js';
  2. import type { CheerioAPI } from './load.js';
  3. import type { Cheerio } from './cheerio.js';
  4. import type { AnyNode, Document } from 'domhandler';
  5. import { type CheerioOptions } from './options.js';
  6. import type { ExtractedMap, ExtractMap } from './api/extract.js';
  7. /**
  8. * Renders the document.
  9. *
  10. * @category Static
  11. * @param options - Options for the renderer.
  12. * @returns The rendered document.
  13. */
  14. export declare function html(this: CheerioAPI, options?: CheerioOptions): string;
  15. /**
  16. * Renders the document.
  17. *
  18. * @category Static
  19. * @param dom - Element to render.
  20. * @param options - Options for the renderer.
  21. * @returns The rendered document.
  22. */
  23. export declare function html(this: CheerioAPI, dom?: BasicAcceptedElems<AnyNode>, options?: CheerioOptions): string;
  24. /**
  25. * Render the document as XML.
  26. *
  27. * @category Static
  28. * @param dom - Element to render.
  29. * @returns THe rendered document.
  30. */
  31. export declare function xml(this: CheerioAPI, dom?: BasicAcceptedElems<AnyNode>): string;
  32. /**
  33. * Render the document as text.
  34. *
  35. * This returns the `textContent` of the passed elements. The result will
  36. * include the contents of `<script>` and `<style>` elements. To avoid this, use
  37. * `.prop('innerText')` instead.
  38. *
  39. * @category Static
  40. * @param elements - Elements to render.
  41. * @returns The rendered document.
  42. */
  43. export declare function text(this: CheerioAPI | void, elements?: ArrayLike<AnyNode>): string;
  44. /**
  45. * Parses a string into an array of DOM nodes. The `context` argument has no
  46. * meaning for Cheerio, but it is maintained for API compatibility with jQuery.
  47. *
  48. * @category Static
  49. * @param data - Markup that will be parsed.
  50. * @param context - Will be ignored. If it is a boolean it will be used as the
  51. * value of `keepScripts`.
  52. * @param keepScripts - If false all scripts will be removed.
  53. * @returns The parsed DOM.
  54. * @alias Cheerio.parseHTML
  55. * @see {@link https://api.jquery.com/jQuery.parseHTML/}
  56. */
  57. export declare function parseHTML(this: CheerioAPI, data: string, context?: unknown | boolean, keepScripts?: boolean): AnyNode[];
  58. export declare function parseHTML(this: CheerioAPI, data?: '' | null): null;
  59. /**
  60. * Sometimes you need to work with the top-level root element. To query it, you
  61. * can use `$.root()`.
  62. *
  63. * @category Static
  64. * @example
  65. *
  66. * ```js
  67. * $.root().append('<ul id="vegetables"></ul>').html();
  68. * //=> <ul id="fruits">...</ul><ul id="vegetables"></ul>
  69. * ```
  70. *
  71. * @returns Cheerio instance wrapping the root node.
  72. * @alias Cheerio.root
  73. */
  74. export declare function root(this: CheerioAPI): Cheerio<Document>;
  75. /**
  76. * Checks to see if the `contained` DOM element is a descendant of the
  77. * `container` DOM element.
  78. *
  79. * @category Static
  80. * @param container - Potential parent node.
  81. * @param contained - Potential child node.
  82. * @returns Indicates if the nodes contain one another.
  83. * @alias Cheerio.contains
  84. * @see {@link https://api.jquery.com/jQuery.contains/}
  85. */
  86. export declare function contains(container: AnyNode, contained: AnyNode): boolean;
  87. /**
  88. * Extract multiple values from a document, and store them in an object.
  89. *
  90. * @category Static
  91. * @param map - An object containing key-value pairs. The keys are the names of
  92. * the properties to be created on the object, and the values are the
  93. * selectors to be used to extract the values.
  94. * @returns An object containing the extracted values.
  95. */
  96. export declare function extract<M extends ExtractMap>(this: CheerioAPI, map: M): ExtractedMap<M>;
  97. type Writable<T> = {
  98. -readonly [P in keyof T]: T[P];
  99. };
  100. /**
  101. * $.merge().
  102. *
  103. * @category Static
  104. * @param arr1 - First array.
  105. * @param arr2 - Second array.
  106. * @returns `arr1`, with elements of `arr2` inserted.
  107. * @alias Cheerio.merge
  108. * @see {@link https://api.jquery.com/jQuery.merge/}
  109. */
  110. export declare function merge<T>(arr1: Writable<ArrayLike<T>>, arr2: ArrayLike<T>): ArrayLike<T> | undefined;
  111. export {};
  112. //# sourceMappingURL=static.d.ts.map