summaryrefslogtreecommitdiff
path: root/source/helpers/get-text-nodes.ts
diff options
context:
space:
mode:
authorGravatar Fregante <opensource@bfred.it> 2020-05-19 22:52:08 +0200
committerGravatar GitHub <noreply@github.com> 2020-05-19 22:52:08 +0200
commitf9d8b7a5a402e19b0cb16fd937e0f19c43a6e699 (patch)
tree0b7a3d6cc31c8975921a7d7fcf6c4bc7e0e020e2 /source/helpers/get-text-nodes.ts
parent508c93a3f4cf219f343d19b927ae0d07ec3ad7f8 (diff)
downloadrefined-github-f9d8b7a5a402e19b0cb16fd937e0f19c43a6e699.tar.gz
refined-github-f9d8b7a5a402e19b0cb16fd937e0f19c43a6e699.tar.zst
refined-github-f9d8b7a5a402e19b0cb16fd937e0f19c43a6e699.zip
Meta: Reorganize utility functions (#3110)
Diffstat (limited to 'source/helpers/get-text-nodes.ts')
-rw-r--r--source/helpers/get-text-nodes.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/source/helpers/get-text-nodes.ts b/source/helpers/get-text-nodes.ts
new file mode 100644
index 00000000..a34ddda8
--- /dev/null
+++ b/source/helpers/get-text-nodes.ts
@@ -0,0 +1,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;
+}