Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/parse5

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/parse5 - npm Package Compare versions

Comparing version 5.0.3 to 6.0.0

parse5/lib/tree-adapters/default.d.ts

296

parse5/index.d.ts

@@ -1,5 +0,6 @@

// Type definitions for parse5 5.0
// Type definitions for parse5 6.0
// Project: https://github.com/inikulin/parse5
// Definitions by: Ivan Nikulin <https://github.com/inikulin>
// ExE Boss <https://github.com/ExE-Boss>
// James Garbutt <https://github.com/43081j>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

@@ -62,3 +63,3 @@

export interface ParserOptions {
export interface ParserOptions<T extends TreeAdapter = TreeAdapter> {
/**

@@ -89,6 +90,6 @@ * The [scripting flag](https://html.spec.whatwg.org/multipage/parsing.html#scripting-flag). If set

*/
treeAdapter?: TreeAdapter;
treeAdapter?: T;
}
export interface SerializerOptions {
export interface SerializerOptions<T extends TreeAdapter = TreeAdapter> {
/***

@@ -99,3 +100,3 @@ * Specifies input tree format.

*/
treeAdapter?: TreeAdapter;
treeAdapter?: T;
}

@@ -136,35 +137,5 @@

/**
* Default tree adapter Node interface.
*/
export interface DefaultTreeNode {
/**
* The name of the node. E.g. {@link Document} will have `nodeName` equal to '#document'`.
*/
nodeName: string;
}
/**
* Default tree adapter ParentNode interface.
*/
export interface DefaultTreeParentNode extends DefaultTreeNode {
/**
* Child nodes.
*/
childNodes: DefaultTreeNode[];
}
/**
* Default tree adapter ChildNode interface.
*/
export interface DefaultTreeChildNode extends DefaultTreeNode {
/**
* Parent node.
*/
parentNode: DefaultTreeParentNode;
}
/**
* Default tree adapter DocumentType interface.
*/
export interface DefaultTreeDocumentType extends DefaultTreeNode {
export interface DocumentType {
/**

@@ -194,3 +165,3 @@ * The name of the node.

*/
export interface DefaultTreeDocument extends DefaultTreeParentNode {
export interface Document {
/**

@@ -205,2 +176,7 @@ * The name of the node.

mode: DocumentMode;
/**
* Child nodes.
*/
childNodes: ChildNode[];
}

@@ -211,3 +187,3 @@

*/
export interface DefaultTreeDocumentFragment extends DefaultTreeParentNode {
export interface DocumentFragment {
/**

@@ -217,2 +193,7 @@ * The name of the node.

nodeName: "#document-fragment";
/**
* Child nodes.
*/
childNodes: ChildNode[];
}

@@ -223,3 +204,3 @@

*/
export interface DefaultTreeElement extends DefaultTreeChildNode, DefaultTreeParentNode {
export interface Element {
/**

@@ -249,2 +230,12 @@ * The name of the node. Equals to element {@link tagName}.

sourceCodeLocation?: ElementLocation;
/**
* Child nodes.
*/
childNodes: ChildNode[];
/**
* Parent node.
*/
parentNode: ParentNode;
}

@@ -255,3 +246,3 @@

*/
export interface DefaultTreeCommentNode extends DefaultTreeChildNode {
export interface CommentNode {
/**

@@ -271,2 +262,7 @@ * The name of the node.

sourceCodeLocation?: Location;
/**
* Parent node.
*/
parentNode: ParentNode;
}

@@ -277,3 +273,3 @@

*/
export interface DefaultTreeTextNode extends DefaultTreeChildNode {
export interface TextNode {
/**

@@ -293,60 +289,93 @@ * The name of the node.

sourceCodeLocation?: Location;
/**
* Parent node.
*/
parentNode: ParentNode;
}
// Generic node interfaces
/**
* Generic Node interface.
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeNode}) to get access to the properties.
* Default tree adapter Node interface.
*/
export type Node = DefaultTreeNode | object;
export type Node = CommentNode | Document | DocumentFragment | DocumentType | Element | TextNode;
/**
* Generic ChildNode interface.
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeChildNode}) to get access to the properties.
* Default tree adapter ChildNode type.
*/
export type ChildNode = DefaultTreeChildNode | object;
export type ChildNode = TextNode | Element | CommentNode;
/**
* Generic ParentNode interface.
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeParentNode}) to get access to the properties.
* Default tree adapter ParentNode type.
*/
export type ParentNode = DefaultTreeParentNode | object;
export type ParentNode = Document | DocumentFragment | Element;
/**
* Generic DocumentType interface.
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeDocumentType}) to get access to the properties.
*/
export type DocumentType = DefaultTreeDocumentType | object;
export interface TreeAdapterTypeMap {
attribute: unknown;
childNode: unknown;
commentNode: unknown;
document: unknown;
documentFragment: unknown;
documentType: unknown;
element: unknown;
node: unknown;
parentNode: unknown;
textNode: unknown;
}
/**
* Generic Document interface.
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeDocument}) to get access to the properties.
*/
export type Document = DefaultTreeDocument | object;
export interface TreeAdapter {
adoptAttributes(recipient: unknown, attrs: unknown[]): void;
appendChild(parentNode: unknown, newNode: unknown): void;
createCommentNode(data: string): unknown;
createDocument(): unknown;
createDocumentFragment(): unknown;
createElement(
tagName: string,
namespaceURI: string,
attrs: unknown[]
): unknown;
detachNode(node: unknown): void;
getAttrList(element: unknown): unknown[];
getChildNodes(node: unknown): unknown[];
getCommentNodeContent(commentNode: unknown): string;
getDocumentMode(document: unknown): unknown;
getDocumentTypeNodeName(doctypeNode: unknown): string;
getDocumentTypeNodePublicId(doctypeNode: unknown): string;
getDocumentTypeNodeSystemId(doctypeNode: unknown): string;
getFirstChild(node: unknown): unknown;
getNamespaceURI(element: unknown): string;
getNodeSourceCodeLocation(node: unknown): Location | StartTagLocation | ElementLocation;
getParentNode(node: unknown): unknown;
getTagName(element: unknown): string;
getTextNodeContent(textNode: unknown): string;
getTemplateContent(templateElement: unknown): unknown;
insertBefore(
parentNode: unknown,
newNode: unknown,
referenceNode: unknown
): void;
insertText(parentNode: unknown, text: string): void;
insertTextBefore(
parentNode: unknown,
text: string,
referenceNode: unknown
): void;
isCommentNode(node: unknown): boolean;
isDocumentTypeNode(node: unknown): boolean;
isElementNode(node: unknown): boolean;
isTextNode(node: unknown): boolean;
setDocumentMode(document: unknown, mode: DocumentMode): void;
setDocumentType(
document: unknown,
name: string,
publicId: string,
systemId: string
): void;
setNodeSourceCodeLocation(node: unknown, location: Location | StartTagLocation | ElementLocation): void;
setTemplateContent(
templateElement: unknown,
contentElement: unknown
): void;
}
/**
* Generic DocumentFragment interface.
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeDocumentFragment}) to get access to the properties.
*/
export type DocumentFragment = DefaultTreeDocumentFragment | object;
/**
* Generic Element interface.
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeElement}) to get access to the properties.
*/
export type Element = DefaultTreeElement | object;
/**
* Generic TextNode interface.
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeTextNode}) to get access to the properties.
*/
export type TextNode = DefaultTreeTextNode | object;
/**
* Generic CommentNode interface.
* Cast to the actual AST interface (e.g. {@link parse5.Default.CommentNode}) to get access to the properties.
*/
export type CommentNode = DefaultTreeCommentNode | object;
/**
* Tree adapter is a set of utility functions that provides minimal required abstraction layer beetween parser and a specific AST format.

@@ -358,3 +387,3 @@ * Note that `TreeAdapter` is not designed to be a general purpose AST manipulation library. You can build such library

*/
export interface TreeAdapter {
export interface TypedTreeAdapter<T extends TreeAdapterTypeMap> extends TreeAdapter {
/**

@@ -366,3 +395,3 @@ * Copies attributes to the given element. Only attributes that are not yet present in the element are copied.

*/
adoptAttributes(recipient: Element, attrs: Attribute[]): void;
adoptAttributes(recipient: T['element'], attrs: Array<T['attribute']>): void;

@@ -375,3 +404,3 @@ /**

*/
appendChild(parentNode: ParentNode, newNode: Node): void;
appendChild(parentNode: T['parentNode'], newNode: T['node']): void;

@@ -383,3 +412,3 @@ /**

*/
createCommentNode(data: string): CommentNode;
createCommentNode(data: string): T['commentNode'];

@@ -389,3 +418,3 @@ /**

*/
createDocument(): Document;
createDocument(): T['document'];

@@ -395,3 +424,3 @@ /**

*/
createDocumentFragment(): DocumentFragment;
createDocumentFragment(): T['documentFragment'];

@@ -408,4 +437,4 @@ /**

namespaceURI: string,
attrs: Attribute[]
): Element;
attrs: Array<T['attribute']>
): T['element'];

@@ -417,3 +446,3 @@ /**

*/
detachNode(node: Node): void;
detachNode(node: T['node']): void;

@@ -426,3 +455,3 @@ /**

*/
getAttrList(element: Element): Attribute[];
getAttrList(element: T['element']): Array<T['attribute']>;

@@ -434,3 +463,3 @@ /**

*/
getChildNodes(node: ParentNode): Node[];
getChildNodes(node: T['parentNode']): Array<T['childNode']>;

@@ -442,3 +471,3 @@ /**

*/
getCommentNodeContent(commentNode: CommentNode): string;
getCommentNodeContent(commentNode: T['commentNode']): string;

@@ -450,3 +479,3 @@ /**

*/
getDocumentMode(document: Document): DocumentMode;
getDocumentMode(document: T['document']): DocumentMode;

@@ -458,3 +487,3 @@ /**

*/
getDocumentTypeNodeName(doctypeNode: DocumentType): string;
getDocumentTypeNodeName(doctypeNode: T['documentType']): string;

@@ -466,3 +495,3 @@ /**

*/
getDocumentTypeNodePublicId(doctypeNode: DocumentType): string;
getDocumentTypeNodePublicId(doctypeNode: T['documentType']): string;

@@ -474,3 +503,3 @@ /**

*/
getDocumentTypeNodeSystemId(doctypeNode: DocumentType): string;
getDocumentTypeNodeSystemId(doctypeNode: T['documentType']): string;

@@ -482,3 +511,3 @@ /**

*/
getFirstChild(node: ParentNode): Node;
getFirstChild(node: T['parentNode']): T['childNode']|undefined;

@@ -490,3 +519,3 @@ /**

*/
getNamespaceURI(element: Element): string;
getNamespaceURI(element: T['element']): string;

@@ -498,3 +527,3 @@ /**

*/
getNodeSourceCodeLocation(node: Node): Location | StartTagLocation | ElementLocation;
getNodeSourceCodeLocation(node: T['node']): Location | StartTagLocation | ElementLocation;

@@ -506,3 +535,3 @@ /**

*/
getParentNode(node: ChildNode): ParentNode;
getParentNode(node: T['childNode']): T['parentNode'];

@@ -514,3 +543,3 @@ /**

*/
getTagName(element: Element): string;
getTagName(element: T['element']): string;

@@ -522,3 +551,3 @@ /**

*/
getTextNodeContent(textNode: TextNode): string;
getTextNodeContent(textNode: T['textNode']): string;

@@ -530,3 +559,3 @@ /**

*/
getTemplateContent(templateElement: Element): DocumentFragment;
getTemplateContent(templateElement: T['element']): T['documentFragment'];

@@ -541,5 +570,5 @@ /**

insertBefore(
parentNode: ParentNode,
newNode: Node,
referenceNode: Node
parentNode: T['parentNode'],
newNode: T['node'],
referenceNode: T['node']
): void;

@@ -554,3 +583,3 @@

*/
insertText(parentNode: ParentNode, text: string): void;
insertText(parentNode: T['parentNode'], text: string): void;

@@ -567,5 +596,5 @@ /**

insertTextBefore(
parentNode: ParentNode,
parentNode: T['parentNode'],
text: string,
referenceNode: Node
referenceNode: T['node']
): void;

@@ -578,3 +607,3 @@

*/
isCommentNode(node: Node): boolean;
isCommentNode(node: T['node']): node is T['commentNode'];

@@ -586,3 +615,3 @@ /**

*/
isDocumentTypeNode(node: Node): boolean;
isDocumentTypeNode(node: T['node']): node is T['documentType'];

@@ -594,3 +623,3 @@ /**

*/
isElementNode(node: Node): boolean;
isElementNode(node: T['node']): node is T['element'];

@@ -602,3 +631,3 @@ /**

*/
isTextNode(node: Node): boolean;
isTextNode(node: T['node']): node is T['textNode'];

@@ -611,3 +640,3 @@ /**

*/
setDocumentMode(document: Document, mode: DocumentMode): void;
setDocumentMode(document: T['document'], mode: DocumentMode): void;

@@ -625,3 +654,3 @@ /**

setDocumentType(
document: Document,
document: T['document'],
name: string,

@@ -637,3 +666,3 @@ publicId: string,

*/
setNodeSourceCodeLocation(node: Node, location: Location | StartTagLocation | ElementLocation): void;
setNodeSourceCodeLocation(node: T['node'], location: Location | StartTagLocation | ElementLocation): void;

@@ -647,4 +676,4 @@ /**

setTemplateContent(
templateElement: Element,
contentElement: DocumentFragment
templateElement: T['element'],
contentElement: T['documentFragment']
): void;

@@ -669,3 +698,5 @@ }

*/
export function parse(html: string, options?: ParserOptions): Document;
export function parse<T extends TreeAdapter = typeof import('./lib/tree-adapters/default')>(
html: string,
options?: ParserOptions<T>): T extends TypedTreeAdapter<infer TMap> ? TMap['document'] : Document;

@@ -694,11 +725,10 @@ /**

*/
export function parseFragment(
export function parseFragment<T extends TreeAdapter = typeof import('./lib/tree-adapters/default')>(
html: string,
options?: ParserOptions<T>
): T extends TypedTreeAdapter<infer TMap> ? TMap['documentFragment'] : DocumentFragment;
export function parseFragment<T extends TreeAdapter = typeof import('./lib/tree-adapters/default')>(
fragmentContext: Element,
html: string,
options?: ParserOptions
): DocumentFragment;
export function parseFragment(
html: string,
options?: ParserOptions
): DocumentFragment;
options?: ParserOptions<T>): T extends TypedTreeAdapter<infer TMap> ? TMap['documentFragment'] : DocumentFragment;

@@ -727,2 +757,4 @@ /**

*/
export function serialize(node: Node, options?: SerializerOptions): string;
export function serialize<T extends TreeAdapter = typeof import('./lib/tree-adapters/default')>(
node: T extends TypedTreeAdapter<infer TMap> ? TMap['node'] : Node,
options?: SerializerOptions<T>): string;
{
"name": "@types/parse5",
"version": "5.0.3",
"version": "6.0.0",
"description": "TypeScript definitions for parse5",

@@ -16,2 +16,7 @@ "license": "MIT",

"githubUsername": "ExE-Boss"
},
{
"name": "James Garbutt",
"url": "https://github.com/43081j",
"githubUsername": "43081j"
}

@@ -28,4 +33,4 @@ ],

"dependencies": {},
"typesPublisherContentHash": "c008c5f4d7bb5f52d9fff6caef66399c1389fc27c66811a26a35981e3f4455cf",
"typeScriptVersion": "2.9"
"typesPublisherContentHash": "5d9a77f4a626e6993f8e3a998227aa89b152999ec1d499e0e0056b1f71f2ccc6",
"typeScriptVersion": "3.3"
}

@@ -11,3 +11,3 @@ # Installation

### Additional Details
* Last updated: Wed, 13 May 2020 21:41:59 GMT
* Last updated: Fri, 08 Jan 2021 00:53:03 GMT
* Dependencies: none

@@ -17,2 +17,2 @@ * Global values: none

# Credits
These definitions were written by [Ivan Nikulin](https://github.com/inikulin), and [ExE Boss](https://github.com/ExE-Boss).
These definitions were written by [Ivan Nikulin](https://github.com/inikulin), [ExE Boss](https://github.com/ExE-Boss), and [James Garbutt](https://github.com/43081j).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc