mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Types for fast-html-parser (#38171)
This commit is contained in:
parent
a3e848394f
commit
9b39d947b0
30
types/fast-html-parser/fast-html-parser-tests.ts
Normal file
30
types/fast-html-parser/fast-html-parser-tests.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { NodeType, parse } from 'fast-html-parser';
|
||||
|
||||
const root = parse(
|
||||
'<!doctype html><html lang="en-us"><html><body><div id="firstdiv"> first-div </div><div> second-div </div></body></html>',
|
||||
{
|
||||
lowerCaseTagName: true,
|
||||
pre: true,
|
||||
script: true,
|
||||
style: true,
|
||||
},
|
||||
);
|
||||
|
||||
const firstDiv = root.querySelector('div');
|
||||
const paragraph = parse('<p>This is a paragraph</p>');
|
||||
const firstDivWithParagraph = firstDiv.appendChild(paragraph);
|
||||
|
||||
console.log(root.nodeType);
|
||||
console.log(firstDiv);
|
||||
console.log(firstDivWithParagraph);
|
||||
console.log(root.rawAttributes);
|
||||
console.log(root.rawAttrs);
|
||||
console.log(root.rawText);
|
||||
console.log(root.removeWhitespace());
|
||||
console.log(root.structure);
|
||||
console.log(root.structuredText);
|
||||
console.log(root.tagName);
|
||||
console.log(root.text);
|
||||
console.log(root.trimRight());
|
||||
console.log(root.querySelectorAll('div'));
|
||||
console.log(NodeType.ELEMENT_NODE);
|
||||
46
types/fast-html-parser/index.d.ts
vendored
Normal file
46
types/fast-html-parser/index.d.ts
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
// Type definitions for fast-html-parser 1.0
|
||||
// Project: https://github.com/ashi009/node-fast-html-parser
|
||||
// Definitions by: Ryan Howard <https://github.com/rollercodester>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
export function parse(data: string, options?: ParseOptions): HTMLElement;
|
||||
|
||||
export enum NodeType {
|
||||
ELEMENT_NODE = 1,
|
||||
TEXT_NODE = 3,
|
||||
}
|
||||
|
||||
export interface Attributes {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export interface HTMLElement {
|
||||
readonly attributes: Attributes;
|
||||
readonly childNodes: HTMLElement[];
|
||||
readonly classNames: string[];
|
||||
readonly firstChild: HTMLElement;
|
||||
readonly id: string;
|
||||
readonly isWhitespace: boolean;
|
||||
readonly lastChild: HTMLElement;
|
||||
readonly nodeType: NodeType;
|
||||
readonly rawAttrs: string;
|
||||
readonly rawAttributes: Attributes;
|
||||
readonly rawText: string;
|
||||
readonly structure: string;
|
||||
readonly structuredText: string;
|
||||
readonly text: string;
|
||||
readonly tagName: string;
|
||||
appendChild(node: HTMLElement): HTMLElement;
|
||||
querySelector(selector: string): HTMLElement;
|
||||
querySelectorAll(selector: string): HTMLElement[];
|
||||
removeWhitespace(): HTMLElement;
|
||||
trimRight(pattern?: RegExp): HTMLElement;
|
||||
}
|
||||
|
||||
export interface ParseOptions {
|
||||
lowerCaseTagName?: boolean;
|
||||
pre?: boolean;
|
||||
script?: boolean;
|
||||
style?: boolean;
|
||||
}
|
||||
24
types/fast-html-parser/tsconfig.json
Normal file
24
types/fast-html-parser/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"fast-html-parser-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/fast-html-parser/tslint.json
Normal file
1
types/fast-html-parser/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user