index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * Types used in signatures of Cheerio methods.
  3. *
  4. * @category Cheerio
  5. */
  6. export * from './types.js';
  7. import { getLoad } from './load.js';
  8. import { getParse } from './parse.js';
  9. import { renderWithParse5, parseWithParse5 } from './parsers/parse5-adapter.js';
  10. import renderWithHtmlparser2 from 'dom-serializer';
  11. import { parseDocument as parseWithHtmlparser2 } from 'htmlparser2';
  12. const parse = getParse((content, options, isDocument, context) => options.xmlMode || options._useHtmlParser2
  13. ? parseWithHtmlparser2(content, options)
  14. : parseWithParse5(content, options, isDocument, context));
  15. // Duplicate docs due to https://github.com/TypeStrong/typedoc/issues/1616
  16. /**
  17. * Create a querying function, bound to a document created from the provided markup.
  18. *
  19. * Note that similar to web browser contexts, this operation may introduce
  20. * `<html>`, `<head>`, and `<body>` elements; set `isDocument` to `false` to
  21. * switch to fragment mode and disable this.
  22. *
  23. * @param content - Markup to be loaded.
  24. * @param options - Options for the created instance.
  25. * @param isDocument - Allows parser to be switched to fragment mode.
  26. * @returns The loaded document.
  27. * @see {@link https://cheerio.js.org#loading} for additional usage information.
  28. */
  29. export const load = getLoad(parse, (dom, options) => options.xmlMode || options._useHtmlParser2
  30. ? renderWithHtmlparser2(dom, options)
  31. : renderWithParse5(dom));
  32. /**
  33. * The default cheerio instance.
  34. *
  35. * @deprecated Use the function returned by `load` instead.
  36. */
  37. export default load([]);
  38. export { html, xml, text } from './static.js';
  39. import * as staticMethods from './static.js';
  40. /**
  41. * In order to promote consistency with the jQuery library, users are encouraged
  42. * to instead use the static method of the same name.
  43. *
  44. * @deprecated
  45. * @example
  46. *
  47. * ```js
  48. * const $ = cheerio.load('<div><p></p></div>');
  49. *
  50. * $.contains($('div').get(0), $('p').get(0));
  51. * //=> true
  52. *
  53. * $.contains($('p').get(0), $('div').get(0));
  54. * //=> false
  55. * ```
  56. *
  57. * @returns {boolean}
  58. */
  59. export const { contains } = staticMethods;
  60. /**
  61. * In order to promote consistency with the jQuery library, users are encouraged
  62. * to instead use the static method of the same name.
  63. *
  64. * @deprecated
  65. * @example
  66. *
  67. * ```js
  68. * const $ = cheerio.load('');
  69. *
  70. * $.merge([1, 2], [3, 4]);
  71. * //=> [1, 2, 3, 4]
  72. * ```
  73. */
  74. export const { merge } = staticMethods;
  75. /**
  76. * In order to promote consistency with the jQuery library, users are encouraged
  77. * to instead use the static method of the same name as it is defined on the
  78. * "loaded" Cheerio factory function.
  79. *
  80. * @deprecated See {@link static/parseHTML}.
  81. * @example
  82. *
  83. * ```js
  84. * const $ = cheerio.load('');
  85. * $.parseHTML('<b>markup</b>');
  86. * ```
  87. */
  88. export const { parseHTML } = staticMethods;
  89. /**
  90. * Users seeking to access the top-level element of a parsed document should
  91. * instead use the `root` static method of a "loaded" Cheerio function.
  92. *
  93. * @deprecated
  94. * @example
  95. *
  96. * ```js
  97. * const $ = cheerio.load('');
  98. * $.root();
  99. * ```
  100. */
  101. export const { root } = staticMethods;
  102. //# sourceMappingURL=index.js.map