File size: 395 Bytes
f56a29b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export function getTextContent(node, trim = true) {
  let returnString = ''
  if (node.type === 'text') {
    let text = node.data.replace(/[\u2062]|[\u200B]/g, '')
    if (trim) {
      text = text.trim()
    }
    returnString += text
  } else if (node.children) {
    node.children.forEach((subNode) => {
      returnString += getTextContent(subNode, trim)
    })
  }
  return returnString
}