All files / src/helpers/markup getNodeContent.js

100% Statements 9/9
100% Branches 9/9
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                    149x 149x 149x 75x 50x         25x       74x 49x     25x    
import inlineTextFormat from "../common/inlineTextFormat.js"
 
/**
 * This extract content from a HTMLElement node
 *
 * @param {HTMLElement} node
 * @param {object} selector
 * @return {string} Return content
 */
export default (node, selector) => {
  const { value, attribute, prefix = "", suffix = "", inline = true } = selector
  const el = node.querySelector(value)
  if (attribute) {
    if (el) {
      return `${prefix}${inlineTextFormat(
        el.getAttribute(attribute),
        inline
      )}${suffix}`
    } else {
      return null
    }
  }
 
  if (el) {
    return `${prefix}${inlineTextFormat(el.textContent, inline)}${suffix}`
  }
 
  return null
}