static.d.ts 3.2 KB

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