options.js 901 B

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