How to use unist-util-filter - 1 common examples

To help you get started, we’ve selected a few unist-util-filter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github logux / logux.io / scripts / steps / create-layout.js View on Github external
unistVisit(tree, 'element', node => {
      let cls = node.properties.className || []
      if (node.tagName === 'article') {
        node.children = []
      } else if (node.tagName === 'a') {
        if (cls.some(i => i === 'menu_link')) {
          node.properties.className = cls.filter(i => i !== 'is-current')
        }
      } else if (cls[0] === 'submenu') {
        node.children = []
      } else if (cls[0] === 'menu_extra') {
        node.children = [{ type: 'text', value: `(${ chatUsers } people)` }]
      }
    })
    let articles = 0
    return unistFilter(tree, 'element', node => {
      let props = node.properties || { }
      if (node.tagName === 'article') {
        articles += 1
        return articles === 1
      } if (node.tagName === 'script') {
        return !removeAssets.some(i => props.src.includes(i))
      } else if (node.tagName === 'link' && props.rel[0] === 'stylesheet') {
        return !removeAssets.some(i => props.href.includes(i))
      } else if (node.tagName === 'link' && props.rel[0] === 'preload') {
        return !removeAssets.some(i => props.href.includes(i))
      } else if (node.tagName === 'link' && props.rel[0] === 'preconnect') {
        return !removeAssets.some(i => props.href.includes(i))
      } else {
        return true
      }
    })

unist-util-filter

unist utility to create a new tree with nodes that pass a filter

MIT
Latest version published 1 year ago

Package Health Score

60 / 100
Full package analysis

Popular unist-util-filter functions