-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
118 lines (102 loc) · 2.25 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* eslint-disable @typescript-eslint/naming-convention */
async function LibXML_WASM(): Promise<LibXML>;
/**
* Parse XML string to Document
* @param xml XML string
*/
class Document {
constructor(xml: string);
/**
* Get Node by XPath
* @param xpath XPath string
*/
getNode(xpath: string): Node[];
/**
* Stringify Document
* - Known issue: returns only first node
* @returns XML string
*/
toString(): string;
/**
* Get Document's children nodes
*/
getChildNodes(): Node[];
}
export type NodeType =
"XML_ELEMENT_NODE"
| "XML_ATTRIBUTE_NODE"
| "XML_TEXT_NODE"
| "XML_CDATA_SECTION_NODE"
| "XML_ENTITY_REF_NODE"
| "XML_ENTITY_NODE"
| "XML_PI_NODE"
| "XML_COMMENT_NODE"
| "XML_DOCUMENT_NODE"
| "XML_DOCUMENT_TYPE_NODE"
| "XML_DOCUMENT_FRAG_NODE"
| "XML_NOTATION_NODE"
| "XML_HTML_DOCUMENT_NODE"
| "XML_DTD_NODE"
| "XML_ELEMENT_DECL"
| "XML_ATTRIBUTE_DECL"
| "XML_ENTITY_DECL"
| "XML_NAMESPACE_DECL"
| "XML_XINCLUDE_START"
| "XML_XINCLUDE_END"
/**
* Node
*/
abstract class Node {
/** Node's innerText */
content: string;
/** Node's tag name */
name: string;
/** Node's attrs */
attr: Record<string, string>;
/** Get node's children nodes */
children: Node[];
/**
* Node's type
* - `XML_ELEMENT_NODE`
* - `XML_ATTRIBUTE_NODE`
* - `XML_TEXT_NODE`
* - `XML_CDATA_SECTION_NODE`
* - `XML_ENTITY_REF_NODE`
* - `XML_ENTITY_NODE`
* - `XML_PI_NODE`
* - `XML_COMMENT_NODE`
* - `XML_DOCUMENT_NODE`
* - `XML_DOCUMENT_TYPE_NODE`
* - `XML_DOCUMENT_FRAG_NODE`
* - `XML_NOTATION_NODE`
* - `XML_HTML_DOCUMENT_NODE`
* - `XML_DTD_NODE`
* - `XML_ELEMENT_DECL`
* - `XML_ATTRIBUTE_DECL`
* - `XML_ENTITY_DECL`
* - `XML_NAMESPACE_DECL`
* - `XML_XINCLUDE_START`
* - `XML_XINCLUDE_END`
*/
type: NodeType;
/** Get node's parent node */
getParent(): Node;
/** Stringify Node like `<div>text</div>` */
toString(): string;
/** Get Node by XPath */
getNode(xpath: string): Node[];
}
/**
* LibXML
*/
interface LibXML {
Document: typeof Document;
Node: typeof Node;
/**
* Parse XML string to Document
* @param html HTML string
*/
parseHTML: (html: string) => Document;
}
// export = LibXML_WASM;
export default LibXML_WASM;