mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Updated tests
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import * as htmlparser from "htmlparser2";
|
||||
import { DomHandler, DomHandlerOptions, Node } from "domhandler";
|
||||
|
||||
const rawHtml = "Xyz <script language= javascript>var foo = '<<bar>>';< / script><!--<!-- Waah! -- -->";
|
||||
const handler = new htmlparser.DomHandler((error: Error, dom: htmlparser.DomElement[]) => {
|
||||
const handler = new DomHandler((error: Error, dom: any) => {
|
||||
if (error)
|
||||
console.error('There has been an error...');
|
||||
else
|
||||
console.log(dom);
|
||||
});
|
||||
const parser = new htmlparser.Parser(handler);
|
||||
parser.write(rawHtml);
|
||||
parser.end();
|
||||
handler.ontext = (data: string) => { console.log(data); };
|
||||
handler.onreset = () => { console.log('We have a reset.'); };
|
||||
handler.onerror = (error: Error) => { console.error(Error); };
|
||||
handler.onopentag = (name: string, attribs) => { console.log(name, attribs); };
|
||||
|
||||
const dho: DomHandlerOptions = { normalizeWhitespace: true, withDomLvl1: true, withEndIndices: true, withStartIndices: true };
|
||||
|
||||
Vendored
+9
-10
@@ -1,4 +1,4 @@
|
||||
// Type definitions for domhandler 2.4.2
|
||||
// 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
|
||||
@@ -9,12 +9,12 @@ 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;
|
||||
normalizeWhitespace?: boolean;
|
||||
|
||||
/***
|
||||
* Adds DOM level 1 properties to all elements.
|
||||
*/
|
||||
withDomLvl1: boolean;
|
||||
withDomLvl1?: boolean;
|
||||
|
||||
/***
|
||||
* Indicates whether a startIndex property will be added to nodes.
|
||||
@@ -22,7 +22,7 @@ export interface DomHandlerOptions {
|
||||
* indicating the position of the start of the node in the document.
|
||||
* The default value is "false".
|
||||
*/
|
||||
withStartIndices: boolean;
|
||||
withStartIndices?: boolean;
|
||||
|
||||
/***
|
||||
* Indicates whether a endIndex property will be added to nodes.
|
||||
@@ -30,7 +30,7 @@ export interface DomHandlerOptions {
|
||||
* indicating the position of the end of the node in the document.
|
||||
* The default value is "false".
|
||||
*/
|
||||
withEndIndices: boolean;
|
||||
withEndIndices?: boolean;
|
||||
}
|
||||
|
||||
export interface DomElement {
|
||||
@@ -49,14 +49,13 @@ export interface Element extends DomElement {
|
||||
}
|
||||
|
||||
export interface Node extends DomElement {
|
||||
firstChild(): DomElement;
|
||||
lastChild(): DomElement;
|
||||
nodeType(): number;
|
||||
readonly firstChild: DomElement;
|
||||
readonly lastChild: DomElement;
|
||||
readonly nodeType: number;
|
||||
}
|
||||
|
||||
export class DomHandler {
|
||||
constructor(callback: (error: any, dom: DomElement[]) => any);
|
||||
constructor(callback: (error: any, dom: DomElement[]) => any, options: DomHandlerOptions);
|
||||
constructor(callback: (error: any, dom: DomElement[]) => any, options?: DomHandlerOptions);
|
||||
|
||||
onparserinit(parser: any): void;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
|
||||
Reference in New Issue
Block a user