DefinitelyTyped/types/domhandler/index.d.ts
Johan Davidsson 3c9fd4a692 [@types/htmlparser2] Update typings for Htmlparser2 (and related modules) to match updates (#33921)
* Added new types for domelementtype

* Modify existing types for htmlparser2

* Updating PULL_REQUEST_TEMPLATE.md

* Revert changes to .github/PULL_REQUEST_TEMPLATE.md

* Fixed missing optional

* Adding DomUtils

* Update dependencies

* Removed requirement for TypeScript 2.1 and updated test

* Updated test to include DomUtils and DomHandlerOptions.

* Updated domhandler tests

* Remove incorrect constructor in Parser

* Remove incorrect constructor in WritableStream

* Change way of importing in tests

* Adding deprecated fallback to Options

* Add deprecated Options as a fallback to sanitize-html

* Add ParserOptions

* Use the deprecated Options
2019-03-25 09:39:20 -07:00

79 lines
2.2 KiB
TypeScript

// Type definitions for domhandler 2.4
// Project: https://github.com/fb55/DomHandler#readme
// Definitions by: Johan Davidsson <https://github.com/johandavidson>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface DomHandlerOptions {
/***
* Indicates whether the whitespace in text nodes should be normalized
* (= all whitespace should be replaced with single spaces). The default value is "false".
*/
normalizeWhitespace?: boolean;
/***
* Adds DOM level 1 properties to all elements.
*/
withDomLvl1?: boolean;
/***
* Indicates whether a startIndex property will be added to nodes.
* When the parser is used in a non-streaming fashion, startIndex is an integer
* indicating the position of the start of the node in the document.
* The default value is "false".
*/
withStartIndices?: boolean;
/***
* Indicates whether a endIndex property will be added to nodes.
* When the parser is used in a non-streaming fashion, endIndex is an integer
* indicating the position of the end of the node in the document.
* The default value is "false".
*/
withEndIndices?: boolean;
}
export interface DomElement {
attribs?: {[s: string]: string};
children?: DomElement[];
data?: any;
name?: string;
next?: DomElement;
parent?: DomElement;
prev?: DomElement;
type?: string;
}
export interface Element extends DomElement {
name: string;
}
export interface Node extends DomElement {
readonly firstChild: DomElement;
readonly lastChild: DomElement;
readonly nodeType: number;
}
export class DomHandler {
constructor(callback: (error: any, dom: DomElement[]) => any, options?: DomHandlerOptions);
onparserinit(parser: any): void;
/***
* Resets the handler back to starting state
*/
onreset(): void;
/***
* Signals the handler that parsing is done
*/
onend(): void;
onerror(error: Error): void;
onclosetag(): void;
onopentag(name: string, attribs: {[s: string]: string}): void;
ontext(data: string): void;
oncomment(data: string): void;
oncdatastart(): void;
oncommentend(): void;
onprocessinginstruction(name: string, data: string): void;
}