options.js 1012 B

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.flattenOptions = flattenOptions;
  4. const defaultOpts = {
  5. _useHtmlParser2: false,
  6. };
  7. /**
  8. * Flatten the options for Cheerio.
  9. *
  10. * This will set `_useHtmlParser2` to true if `xml` is set to true.
  11. *
  12. * @param options - The options to flatten.
  13. * @param baseOptions - The base options to use.
  14. * @returns The flattened options.
  15. */
  16. function flattenOptions(options, baseOptions) {
  17. if (!options) {
  18. return baseOptions !== null && baseOptions !== void 0 ? baseOptions : defaultOpts;
  19. }
  20. const opts = {
  21. _useHtmlParser2: !!options.xmlMode,
  22. ...baseOptions,
  23. ...options,
  24. };
  25. if (options.xml) {
  26. opts._useHtmlParser2 = true;
  27. opts.xmlMode = true;
  28. if (options.xml !== true) {
  29. Object.assign(opts, options.xml);
  30. }
  31. }
  32. else if (options.xmlMode) {
  33. opts._useHtmlParser2 = true;
  34. }
  35. return opts;
  36. }
  37. //# sourceMappingURL=options.js.map