UNPKG

3.78 kBTypeScriptView Raw
1// Type definitions for htmlparser2 v3.10.x
2// Project: https://github.com/fb55/htmlparser2/
3// Definitions by: James Roland Cabresos <https://github.com/staticfunction>
4// Linus Unnebäck <https://github.com/LinusU>
5// Johan Davidsson <https://github.com/johandavidson>
6// GP <https://github.com/paambaati>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8// TypeScript Version: 2.2
9
10///<reference types="node"/>
11///<reference types="domhandler"/>
12///<reference types="domutils"/>
13
14import { Writable } from 'stream'
15import { DomHandler } from 'domhandler';
16import * as DomUtils from 'domutils';
17export { DomElement, DomHandlerOptions, DomHandler, Element, Node } from 'domhandler';
18
19export interface ParserOptions {
20
21 /***
22 * Indicates whether special tags (<script> and <style>) should get special treatment
23 * and if "empty" tags (eg. <br>) can have children. If false, the content of special tags
24 * will be text only. For feeds and other XML content (documents that don't consist of HTML),
25 * set this to true. Default: false.
26 */
27 xmlMode?: boolean | undefined;
28
29 /***
30 * If set to true, entities within the document will be decoded. Defaults to false.
31 */
32 decodeEntities?: boolean | undefined;
33
34 /***
35 * If set to true, all tags will be lowercased. If xmlMode is disabled, this defaults to true.
36 */
37 lowerCaseTags?: boolean | undefined;
38
39 /***
40 * If set to true, all attribute names will be lowercased. This has noticeable impact on speed, so it defaults to false.
41 */
42 lowerCaseAttributeNames?: boolean | undefined;
43
44 /***
45 * If set to true, CDATA sections will be recognized as text even if the xmlMode option is not enabled.
46 * NOTE: If xmlMode is set to true then CDATA sections will always be recognized as text.
47 */
48 recognizeCDATA?: boolean | undefined;
49
50 /***
51 * If set to true, self-closing tags will trigger the onclosetag event even if xmlMode is not set to true.
52 * NOTE: If xmlMode is set to true then self-closing tags will always be recognized.
53 */
54 recognizeSelfClosing?: boolean | undefined;
55}
56/**
57 * @deprecated
58 */
59export type Options = ParserOptions
60
61export declare class WritableStream extends Writable {
62 constructor(handler: DomHandler, options?: ParserOptions);
63}
64
65export declare class Parser {
66 constructor(handler: Partial<DomHandler>, options?: ParserOptions);
67
68 /***
69 * Parses a chunk of data and calls the corresponding callbacks.
70 * @param input
71 */
72 write(input: string): void;
73
74 /***
75 * alias for backwards compat
76 */
77 parseChunk(chunk: string): void;
78
79 /***
80 * Parses the end of the buffer and clears the stack, calls onend.
81 */
82 end(): void;
83
84 /***
85 * Parses the end of the buffer and clears the stack, calls onend.
86 */
87 end(chunk: string): void;
88
89 /***
90 * alias for backwards compat
91 */
92 done(): void;
93
94 /***
95 * Pauses the parser
96 */
97 pause(): void;
98
99 /***
100 * Resumes the parser
101 */
102 resume(): void;
103
104 /***
105 * Resets the parser, parses the data & calls end.
106 * @param input
107 */
108 parseComplete(input: string): void;
109
110 /***
111 * Resets buffer & stack, calls onreset.
112 */
113 reset(): void;
114
115 ontext(data: any): void;
116 onopentagname(name: string): void;
117 onopentagend(): void;
118 onclosetag(name: string): void;
119 onselfclosingtag(): void;
120 onattribname(name: string): void;
121 onattribend(): void;
122 ondeclaration(): void;
123 onprocessinginstruction(value: string): void;
124 oncomment(value: string): void;
125 oncdata(value: string): void;
126 onerror(err: Error): void;
127 onend(): void;
128}
129
130export { DomUtils }