cheerio.d.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import type { InternalOptions } from './options.js';
  2. import type { AnyNode, Document, ParentNode } from 'domhandler';
  3. import type { BasicAcceptedElems } from './types.js';
  4. import * as Attributes from './api/attributes.js';
  5. import * as Traversing from './api/traversing.js';
  6. import * as Manipulation from './api/manipulation.js';
  7. import * as Css from './api/css.js';
  8. import * as Forms from './api/forms.js';
  9. import * as Extract from './api/extract.js';
  10. type MethodsType = typeof Attributes & typeof Traversing & typeof Manipulation & typeof Css & typeof Forms & typeof Extract;
  11. /**
  12. * The cheerio class is the central class of the library. It wraps a set of
  13. * elements and provides an API for traversing, modifying, and interacting with
  14. * the set.
  15. *
  16. * Loading a document will return the Cheerio class bound to the root element of
  17. * the document. The class will be instantiated when querying the document (when
  18. * calling `$('selector')`).
  19. *
  20. * @example This is the HTML markup we will be using in all of the API examples:
  21. *
  22. * ```html
  23. * <ul id="fruits">
  24. * <li class="apple">Apple</li>
  25. * <li class="orange">Orange</li>
  26. * <li class="pear">Pear</li>
  27. * </ul>
  28. * ```
  29. */
  30. export declare abstract class Cheerio<T> implements ArrayLike<T> {
  31. length: number;
  32. [index: number]: T;
  33. options: InternalOptions;
  34. /**
  35. * The root of the document. Can be set by using the `root` argument of the
  36. * constructor.
  37. *
  38. * @private
  39. */
  40. _root: Cheerio<Document> | null;
  41. /**
  42. * Instance of cheerio. Methods are specified in the modules. Usage of this
  43. * constructor is not recommended. Please use `$.load` instead.
  44. *
  45. * @private
  46. * @param elements - The new selection.
  47. * @param root - Sets the root node.
  48. * @param options - Options for the instance.
  49. */
  50. constructor(elements: ArrayLike<T> | undefined, root: Cheerio<Document> | null, options: InternalOptions);
  51. prevObject: Cheerio<any> | undefined;
  52. /**
  53. * Make a cheerio object.
  54. *
  55. * @private
  56. * @param dom - The contents of the new object.
  57. * @param context - The context of the new object.
  58. * @returns The new cheerio object.
  59. */
  60. abstract _make<T>(dom: ArrayLike<T> | T | string, context?: BasicAcceptedElems<AnyNode>): Cheerio<T>;
  61. /**
  62. * Parses some content.
  63. *
  64. * @private
  65. * @param content - Content to parse.
  66. * @param options - Options for parsing.
  67. * @param isDocument - Allows parser to be switched to fragment mode.
  68. * @returns A document containing the `content`.
  69. */
  70. abstract _parse(content: string | Document | AnyNode | AnyNode[] | Buffer, options: InternalOptions, isDocument: boolean, context: ParentNode | null): Document;
  71. /**
  72. * Render an element or a set of elements.
  73. *
  74. * @private
  75. * @param dom - DOM to render.
  76. * @returns The rendered DOM.
  77. */
  78. abstract _render(dom: AnyNode | ArrayLike<AnyNode>): string;
  79. }
  80. export interface Cheerio<T> extends MethodsType, Iterable<T> {
  81. cheerio: '[cheerio object]';
  82. splice: typeof Array.prototype.splice;
  83. }
  84. export {};
  85. //# sourceMappingURL=cheerio.d.ts.map