Interface: DecodeStreamOptions

Interface: DecodeStreamOptions

Defined in: index.ts

Options accepted by Cheerio.

Please note that parser-specific options are only recognized if the relevant parser is used.

Extends

Extended by

Properties

baseURI?

optional baseURI: string | URL;

Defined in: options.ts

The base URI for the document. Used to resolve the href and src props.

Inherited from

DecodeStreamOptions.baseURI


encoding?

optional encoding: SnifferOptions;

Defined in: index.ts


pseudos?

optional pseudos: Record<string, string | (elem, value?) => boolean>;

Defined in: options.ts

Extension point for pseudo-classes.

Maps from names to either strings of functions.

  • A string value is a selector that the element must match to be selected.
  • A function is called with the element as its first argument, and optional parameters second. If it returns true, the element is selected.

Example

const $ = cheerio.load(
  '<div class="foo"></div><div data-bar="boo"></div>',
  {
    pseudos: {
      // `:foo` is an alias for `div.foo`
      foo: 'div.foo',
      // `:bar(val)` is equivalent to `[data-bar=val s]`
      bar: (el, val) => el.attribs['data-bar'] === val,
    },
  },
);

$(':foo').length; // 1
$('div:bar(boo)').length; // 1
$('div:bar(baz)').length; // 0

Inherited from

DecodeStreamOptions.pseudos


quirksMode?

optional quirksMode: boolean;

Defined in: options.ts

Is the document in quirks mode?

This will lead to .className and #id being case-insensitive.

Default

false

Inherited from

DecodeStreamOptions.quirksMode


xml?

optional xml: 
  | boolean
  | HTMLParser2Options;

Defined in: options.ts

Recommended way of configuring htmlparser2 when wanting to parse XML.

This will switch Cheerio to use htmlparser2.

Default

false

Inherited from

DecodeStreamOptions.xml


xmlMode?

optional xmlMode: boolean;

Defined in: options.ts

Enable xml mode, which will switch Cheerio to use htmlparser2.

Deprecated

Please use the xml option instead.

Default

false

Inherited from

CheerioOptions.xmlMode