Skip to content

Commit 1fe439e

Browse files
authored
fix: wrong types
1 parent ba43556 commit 1fe439e

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/normalize.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import type { CommentNode, DocumentNode, ElementNode, TextNode } from "@homebots/parse-html";
1+
import type { DocumentNode, ElementNode, ParserNode } from "@homebots/parse-html";
22

3-
export function normalize(node: ElementNode | DocumentNode | CommentNode | TextNode) {
4-
if ('children' in node === false) {
5-
return node;
6-
}
7-
8-
node.children = node.children.filter((child) => {
9-
if (child.type === "text" && child.text.trim() === "") {
10-
return false;
11-
}
3+
export function normalize<T extends ParserNode>(node: T) {
4+
if ('children' in node) {
5+
node.children = node.children.filter((child) => {
6+
if (child.type === "text" && child.text.trim() === "") {
7+
return false;
8+
}
129

13-
normalize(child);
14-
return true;
15-
});
10+
normalize(child as ElementNode | DocumentNode);
11+
return true;
12+
});
13+
}
1614

1715
return node;
1816
}

0 commit comments

Comments
 (0)