-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.ts
54 lines (52 loc) · 1.7 KB
/
index.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
/** Types of elements found in htmlparser2's DOM */
export enum ElementType {
/** Type for the root element of a document */
Root = "root",
/** Type for Text */
Text = "text",
/** Type for <? ... ?> */
Directive = "directive",
/** Type for <!-- ... --> */
Comment = "comment",
/** Type for <script> tags */
Script = "script",
/** Type for <style> tags */
Style = "style",
/** Type for Any tag */
Tag = "tag",
/** Type for <![CDATA[ ... ]]> */
CDATA = "cdata",
/** Type for <!doctype ...> */
Doctype = "doctype",
}
/**
* Tests whether an element is a tag or not.
*
* @param elem Element to test
*/
export function isTag(elem: { type: ElementType }): boolean {
return (
elem.type === ElementType.Tag ||
elem.type === ElementType.Script ||
elem.type === ElementType.Style
);
}
// Exports for backwards compatibility
/** Type for the root element of a document */
export const Root: ElementType.Root = ElementType.Root;
/** Type for Text */
export const Text: ElementType.Text = ElementType.Text;
/** Type for <? ... ?> */
export const Directive: ElementType.Directive = ElementType.Directive;
/** Type for <!-- ... --> */
export const Comment: ElementType.Comment = ElementType.Comment;
/** Type for <script> tags */
export const Script: ElementType.Script = ElementType.Script;
/** Type for <style> tags */
export const Style: ElementType.Style = ElementType.Style;
/** Type for Any tag */
export const Tag: ElementType.Tag = ElementType.Tag;
/** Type for <![CDATA[ ... ]]> */
export const CDATA: ElementType.CDATA = ElementType.CDATA;
/** Type for <!doctype ...> */
export const Doctype: ElementType.Doctype = ElementType.Doctype;