UNPKG

2.98 kBTypeScriptView Raw
1/// <reference types="node" />
2import type { DomHandlerOptions } from 'domhandler';
3import type { ParserOptions } from 'htmlparser2';
4import type { Options as SelectOptions } from 'cheerio-select';
5/**
6 * Options accepted by htmlparser2, the default parser for XML.
7 *
8 * @see https://github.com/fb55/htmlparser2/wiki/Parser-options
9 */
10export interface HTMLParser2Options extends DomHandlerOptions, ParserOptions {
11}
12/** Options for parse5, the default parser for HTML. */
13export interface Parse5Options {
14 /** Disable scripting in parse5, so noscript tags would be parsed. */
15 scriptingEnabled?: boolean;
16 /** Enable location support for parse5. */
17 sourceCodeLocationInfo?: boolean;
18}
19/**
20 * Options accepted by Cheerio.
21 *
22 * Please note that parser-specific options are _only recognized_ if the
23 * relevant parser is used.
24 */
25export interface CheerioOptions extends HTMLParser2Options, Parse5Options {
26 /** Recommended way of configuring htmlparser2 when wanting to parse XML. */
27 xml?: HTMLParser2Options | boolean;
28 /** The base URI for the document. Used for the `href` and `src` props. */
29 baseURI?: string | URL;
30 /**
31 * Is the document in quirks mode?
32 *
33 * This will lead to `.className` and `#id` being case-insensitive.
34 *
35 * @default false
36 */
37 quirksMode?: SelectOptions['quirksMode'];
38 /**
39 * Extension point for pseudo-classes.
40 *
41 * Maps from names to either strings of functions.
42 *
43 * - A string value is a selector that the element must match to be selected.
44 * - A function is called with the element as its first argument, and optional
45 * parameters second. If it returns true, the element is selected.
46 *
47 * @example
48 *
49 * ```js
50 * const $ = cheerio.load(
51 * '<div class="foo"></div><div data-bar="boo"></div>',
52 * {
53 * pseudos: {
54 * // `:foo` is an alias for `div.foo`
55 * foo: 'div.foo',
56 * // `:bar(val)` is equivalent to `[data-bar=val s]`
57 * bar: (el, val) => el.attribs['data-bar'] === val,
58 * },
59 * }
60 * );
61 *
62 * $(':foo').length; // 1
63 * $('div:bar(boo)').length; // 1
64 * $('div:bar(baz)').length; // 0
65 * ```
66 */
67 pseudos?: SelectOptions['pseudos'];
68}
69/** Internal options for Cheerio. */
70export interface InternalOptions extends Omit<CheerioOptions, 'xml'> {
71 /**
72 * Whether to use htmlparser2.
73 *
74 * This is set to true if `xml` is set to true.
75 */
76 _useHtmlParser2?: boolean;
77}
78declare const defaultOpts: CheerioOptions;
79/** Cheerio default options. */
80export default defaultOpts;
81/**
82 * Flatten the options for Cheerio.
83 *
84 * This will set `_useHtmlParser2` to true if `xml` is set to true.
85 *
86 * @param options - The options to flatten.
87 * @returns The flattened options.
88 */
89export declare function flatten(options?: CheerioOptions | null): InternalOptions | undefined;
90//# sourceMappingURL=options.d.ts.map
\No newline at end of file