Created
July 13, 2017 15:32
-
-
Save daniellizik/ec5cd5f12aa9cb8512003aa7b2a70aaa to your computer and use it in GitHub Desktop.
.textContent but with parse5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { parseFragment } from 'parse5' | |
const walk = (node = {}) => { | |
return (node.value || '') + (node.childNodes || []).reduce((child) => { | |
return walk(child) | |
}) | |
} | |
export default (htmlStr) => [parseFragment(htmlStr)].reduce(walk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment