DefinitelyTyped/types/domhandler/domhandler-tests.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

15 lines
670 B
TypeScript

import { DomHandler, DomHandlerOptions, Node, DomElement } from "domhandler";
const handler = new DomHandler((error: Error, dom: DomElement[]) => {
if (error)
console.error('There has been an error...');
else
console.log(dom);
});
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: { [s: string]: string }) => { console.log(name, attribs); };
const dho: DomHandlerOptions = { normalizeWhitespace: true, withDomLvl1: true, withEndIndices: true, withStartIndices: true };