mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import {
|
|
StartTagToken,
|
|
EndTagToken,
|
|
CommentToken,
|
|
TextToken,
|
|
DoctypeToken
|
|
} from "parse5-sax-parser";
|
|
import SAXParser = require("parse5-sax-parser");
|
|
import { createReadStream, createWriteStream } from "fs";
|
|
|
|
let sax = new SAXParser();
|
|
|
|
sax = new SAXParser({ sourceCodeLocationInfo: true });
|
|
|
|
sax.stop();
|
|
|
|
sax
|
|
.on("startTag", (startTag: StartTagToken) => {
|
|
startTag.tagName; // $ExpectType string
|
|
startTag.attrs; // $ExpectType Attribute[]
|
|
startTag.selfClosing; // $ExpectType boolean
|
|
startTag.sourceCodeLocation!; // $ExpectType StartTagLocation
|
|
})
|
|
.on("endTag", (endTag: EndTagToken) => {
|
|
endTag.tagName; // $ExpectType string
|
|
endTag.sourceCodeLocation!; // $ExpectType Location
|
|
})
|
|
.on("comment", (comment: CommentToken) => {
|
|
comment.text; // $ExpectType string
|
|
comment.sourceCodeLocation!; // $ExpectType Location
|
|
})
|
|
.on("text", (text: TextToken) => {
|
|
text.text; // $ExpectType string
|
|
text.sourceCodeLocation!; // $ExpectType Location
|
|
})
|
|
.on("doctype", (doctype: DoctypeToken) => {
|
|
doctype.name; // $ExpectType string
|
|
doctype.publicId; // $ExpectType string
|
|
doctype.systemId; // $ExpectType string
|
|
doctype.sourceCodeLocation!; // $ExpectType Location
|
|
})
|
|
.on("finish", () => {});
|
|
|
|
createReadStream("file1")
|
|
.pipe(sax)
|
|
.pipe(createWriteStream("file2"));
|