summaryrefslogtreecommitdiff
path: root/source/helpers/get-text-nodes.ts
blob: a34ddda8e807c6a5ebe513288bb9c8a5a292d7c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export default function getTextNodes(element: Node): Text[] {
	const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
	const nodes: Text[] = [];
	let node;

	do {
		node = walker.nextNode();
		if (node) {
			nodes.push(node as Text);
		}
	} while (node);

	return nodes;
}