summaryrefslogtreecommitdiff
path: root/source/libs/get-text-nodes.ts
blob: 02803cd547a41ccdba386d191844ffed6714cc70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export default (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;
};