load.d.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { type CheerioOptions, type InternalOptions } from './options.js';
  2. import * as staticMethods from './static.js';
  3. import { Cheerio } from './cheerio.js';
  4. import type { AnyNode, Document, Element } from 'domhandler';
  5. import type { SelectorType, BasicAcceptedElems } from './types.js';
  6. type StaticType = typeof staticMethods;
  7. /**
  8. * A querying function, bound to a document created from the provided markup.
  9. *
  10. * Also provides several helper methods for dealing with the document as a
  11. * whole.
  12. */
  13. export interface CheerioAPI extends StaticType {
  14. /**
  15. * This selector method is the starting point for traversing and manipulating
  16. * the document. Like jQuery, it's the primary method for selecting elements
  17. * in the document.
  18. *
  19. * `selector` searches within the `context` scope, which searches within the
  20. * `root` scope.
  21. *
  22. * @example
  23. *
  24. * ```js
  25. * $('ul .pear').attr('class');
  26. * //=> pear
  27. *
  28. * $('li[class=orange]').html();
  29. * //=> Orange
  30. *
  31. * $('.apple', '#fruits').text();
  32. * //=> Apple
  33. * ```
  34. *
  35. * Optionally, you can also load HTML by passing the string as the selector:
  36. *
  37. * ```js
  38. * $('<ul id="fruits">...</ul>');
  39. * ```
  40. *
  41. * Or the context:
  42. *
  43. * ```js
  44. * $('ul', '<ul id="fruits">...</ul>');
  45. * ```
  46. *
  47. * Or as the root:
  48. *
  49. * ```js
  50. * $('li', 'ul', '<ul id="fruits">...</ul>');
  51. * ```
  52. *
  53. * @param selector - Either a selector to look for within the document, or the
  54. * contents of a new Cheerio instance.
  55. * @param context - Either a selector to look for within the root, or the
  56. * contents of the document to query.
  57. * @param root - Optional HTML document string.
  58. */
  59. <T extends AnyNode, S extends string>(selector?: S | BasicAcceptedElems<T>, context?: BasicAcceptedElems<AnyNode> | null, root?: BasicAcceptedElems<Document>, options?: CheerioOptions): Cheerio<S extends SelectorType ? Element : T>;
  60. /**
  61. * The root the document was originally loaded with.
  62. *
  63. * @private
  64. */
  65. _root: Document;
  66. /**
  67. * The options the document was originally loaded with.
  68. *
  69. * @private
  70. */
  71. _options: InternalOptions;
  72. /** Mimic jQuery's prototype alias for plugin authors. */
  73. fn: typeof Cheerio.prototype;
  74. /**
  75. * The `.load` static method defined on the "loaded" Cheerio factory function
  76. * is deprecated. Users are encouraged to instead use the `load` function
  77. * exported by the Cheerio module.
  78. *
  79. * @deprecated Use the `load` function exported by the Cheerio module.
  80. * @category Deprecated
  81. * @example
  82. *
  83. * ```js
  84. * const $ = cheerio.load('<h1>Hello, <span>world</span>.</h1>');
  85. * ```
  86. */
  87. load: ReturnType<typeof getLoad>;
  88. }
  89. export declare function getLoad(parse: typeof Cheerio.prototype._parse, render: (dom: AnyNode | ArrayLike<AnyNode>, options: InternalOptions) => string): (content: string | AnyNode | AnyNode[] | Buffer, options?: CheerioOptions | null, isDocument?: boolean) => CheerioAPI;
  90. export {};
  91. //# sourceMappingURL=load.d.ts.map