mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add typings for parse5-html-rewriting-stream (#28660)
Please fill in this template. - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. (Run with `npm test`.) - [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). Select one of these and delete the others: If adding a new definition: - [x] The package does not already provide its own types, or cannot have its `.d.ts` files generated via `--declaration` - [x] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package. - [x] Create it with `dts-gen --dt`, not by basing it on an existing project. - [x] `tslint.json` should be present, and `tsconfig.json` should have `noImplicitAny`, `noImplicitThis`, `strictNullChecks`, and `strictFunctionTypes` set to `true`.
This commit is contained in:
parent
3aa09e4e52
commit
a7a32c6740
80
types/parse5-html-rewriting-stream/index.d.ts
vendored
Normal file
80
types/parse5-html-rewriting-stream/index.d.ts
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
// Type definitions for parse5-html-rewriting-stream 5.1
|
||||
// Project: https://github.com/inikulin/parse5/tree/master/packages/parse5-html-rewriting-stream
|
||||
// Definitions by: Sam Li <https://github.com/samuelli>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
import * as parse5 from 'parse5-sax-parser';
|
||||
import * as stream from 'stream';
|
||||
|
||||
/**
|
||||
* Streaming SAX-style HTML rewriter. A transform stream (which means you can
|
||||
* pipe through it, see example). Rewriter uses raw source representation of
|
||||
* tokens if they are not modified by the user, therefore resulting HTML is
|
||||
* not affected by parser error-recovery mechanisms as in the classical
|
||||
* parsing-serialization roundtrip.
|
||||
*/
|
||||
export default class RewritingStream extends stream.Transform {
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
|
||||
/**
|
||||
* Raised when the rewriter encounters a start tag.
|
||||
*/
|
||||
on(type: 'startTag',
|
||||
callback: (startTag: parse5.StartTagToken, rawHtml: string) => void):
|
||||
this;
|
||||
|
||||
/**
|
||||
* Raised when rewriter encounters an end tag.
|
||||
*/
|
||||
on(type: 'endTag',
|
||||
callback: (endTag: parse5.EndTagToken, rawHtml: string) => void): this;
|
||||
|
||||
/**
|
||||
* Raised when rewriter encounters a comment.
|
||||
*/
|
||||
on(type: 'comment',
|
||||
callback: (comment: parse5.CommentToken, rawHtml: string) => void): this;
|
||||
|
||||
/**
|
||||
* Raised when rewriter encounters text content.
|
||||
*/
|
||||
on(type: 'text',
|
||||
callback: (text: parse5.TextToken, rawHtml: string) => void): this;
|
||||
|
||||
/**
|
||||
* Raised when rewriter encounters a document type declaration.
|
||||
*/
|
||||
on(type: 'doctype',
|
||||
callback: (doctype: parse5.DoctypeToken, rawHtml: string) => void): this;
|
||||
|
||||
/**
|
||||
* Emits serialized start tag token into the output stream.
|
||||
*/
|
||||
emitStartTag(startTag: parse5.StartTagToken): void;
|
||||
|
||||
/**
|
||||
* Emits serialized end tag token into the output stream.
|
||||
*/
|
||||
emitEndTag(endTag: parse5.EndTagToken): void;
|
||||
|
||||
/**
|
||||
* Emits serialized text token into the output stream.
|
||||
*/
|
||||
emitText(text: parse5.TextToken): void;
|
||||
|
||||
/**
|
||||
* Emits serialized comment token into the output stream.
|
||||
*/
|
||||
emitComment(text: parse5.CommentToken): void;
|
||||
|
||||
/**
|
||||
* Emits serialized document type token into the output stream.
|
||||
*/
|
||||
emitDoctype(text: parse5.DoctypeToken): void;
|
||||
|
||||
/**
|
||||
* Emits raw HTML string into the output stream.
|
||||
*/
|
||||
emitRaw(html: string): void;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
import RewritingStream from 'parse5-html-rewriting-stream';
|
||||
|
||||
const rewritingStream = new RewritingStream();
|
||||
rewritingStream.on('startTag', (startTag, rawHtml) => {
|
||||
startTag.tagName; // $ExpectType string
|
||||
startTag.selfClosing; // $ExpectType boolean
|
||||
rawHtml; // $ExpectType string
|
||||
|
||||
rewritingStream.emitStartTag(startTag); // $ExpectType void
|
||||
});
|
||||
23
types/parse5-html-rewriting-stream/tsconfig.json
Normal file
23
types/parse5-html-rewriting-stream/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"parse5-html-rewriting-stream-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/parse5-html-rewriting-stream/tslint.json
Normal file
1
types/parse5-html-rewriting-stream/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user