1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export const EVENTS: string[];
|
11 |
|
12 | export interface SAXOptions {
|
13 | trim?: boolean | undefined;
|
14 | normalize?: boolean | undefined;
|
15 | lowercase?: boolean | undefined;
|
16 | xmlns?: boolean | undefined;
|
17 | noscript?: boolean | undefined;
|
18 | position?: boolean | undefined;
|
19 | }
|
20 |
|
21 | export interface QualifiedName {
|
22 | name: string;
|
23 | prefix: string;
|
24 | local: string;
|
25 | uri: string;
|
26 | }
|
27 |
|
28 | export interface QualifiedAttribute extends QualifiedName {
|
29 | value: string;
|
30 | }
|
31 |
|
32 | export interface BaseTag {
|
33 | name: string;
|
34 | isSelfClosing: boolean;
|
35 | }
|
36 |
|
37 |
|
38 | export interface QualifiedTag extends QualifiedName, BaseTag {
|
39 | ns: { [key: string]: string };
|
40 | attributes: { [key: string]: QualifiedAttribute };
|
41 | }
|
42 |
|
43 | export interface Tag extends BaseTag {
|
44 | attributes: { [key: string]: string };
|
45 | }
|
46 |
|
47 | export function parser(strict?: boolean, opt?: SAXOptions): SAXParser;
|
48 | export class SAXParser {
|
49 | constructor(strict?: boolean, opt?: SAXOptions);
|
50 |
|
51 | // Methods
|
52 | end(): void;
|
53 | write(s: string): SAXParser;
|
54 | resume(): SAXParser;
|
55 | close(): SAXParser;
|
56 | flush(): void;
|
57 |
|
58 | // Members
|
59 | line: number;
|
60 | column: number;
|
61 | error: Error;
|
62 | position: number;
|
63 | startTagPosition: number;
|
64 | closed: boolean;
|
65 | strict: boolean;
|
66 | opt: SAXOptions;
|
67 | tag: Tag;
|
68 | ENTITIES: {[key: string]: string};
|
69 |
|
70 |
|
71 | onerror(e: Error): void;
|
72 | ontext(t: string): void;
|
73 | ondoctype(doctype: string): void;
|
74 | onprocessinginstruction(node: { name: string; body: string }): void;
|
75 | onopentag(tag: Tag | QualifiedTag): void;
|
76 | onclosetag(tagName: string): void;
|
77 | onattribute(attr: { name: string; value: string }): void;
|
78 | oncomment(comment: string): void;
|
79 | onopencdata(): void;
|
80 | oncdata(cdata: string): void;
|
81 | onclosecdata(): void;
|
82 | onopennamespace(ns: { prefix: string; uri: string }): void;
|
83 | onclosenamespace(ns: { prefix: string; uri: string }): void;
|
84 | onend(): void;
|
85 | onready(): void;
|
86 | onscript(script: string): void;
|
87 | }
|
88 |
|
89 | import stream = require("stream");
|
90 | export function createStream(strict?: boolean, opt?: SAXOptions): SAXStream;
|
91 | export class SAXStream extends stream.Duplex {
|
92 | constructor(strict?: boolean, opt?: SAXOptions);
|
93 | _parser: SAXParser;
|
94 | on(event: "text", listener: (this: this, text: string) => void): this;
|
95 | on(event: "doctype", listener: (this: this, doctype: string) => void): this;
|
96 | on(event: "processinginstruction", listener: (this: this, node: { name: string; body: string }) => void): this;
|
97 | on(event: "opentag", listener: (this: this, tag: Tag | QualifiedTag) => void): this;
|
98 | on(event: "closetag", listener: (this: this, tagName: string) => void): this;
|
99 | on(event: "attribute", listener: (this: this, attr: { name: string; value: string }) => void): this;
|
100 | on(event: "comment", listener: (this: this, comment: string) => void): this;
|
101 | on(event: "opencdata" | "closecdata" | "end" | "ready" | "close" | "readable" | "drain" | "finish", listener: (this: this) => void): this;
|
102 | on(event: "cdata", listener: (this: this, cdata: string) => void): this;
|
103 | on(event: "opennamespace" | "closenamespace", listener: (this: this, ns: { prefix: string; uri: string }) => void): this;
|
104 | on(event: "script", listener: (this: this, script: string) => void): this;
|
105 | on(event: "data", listener: (this: this, chunk: any) => void): this;
|
106 | on(event: "error", listener: (this: this, err: Error) => void): this;
|
107 | on(event: "pipe" | "unpipe", listener: (this: this, src: stream.Readable) => void): this;
|
108 | on(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;
|
109 | }
|