node-pick

yarn add node-pick

Usage no npm install needed!

<script type="module">
  import nodePick from 'https://cdn.skypack.dev/node-pick';
</script>

README

Node-Pick

Dom selection tool based on cheerio.js

Install

yarn add node-pick

Rule

const pickRule = {
  title: {
    selector: 'title'
  },
  apple: {
    selector: ['.apple', '@text']
  },
  list: {
    selector: [
      'div',
      {
        text: '@text',
        names: {
          selector: ['ul > li', '@text']
        }
      }
    ]
  }
}

console.log(nodePick('you-html-string').output(pickRule))

Output 🌈

{
  "title": ["Hello World!"],
  "apple": ["Apple"],
  "list": [
    {
      "names": ["Apple", "Orange", "Pear"],
      "text": "\n    \n      Apple\n      Orange\n      Pear\n    \n  "
    }
  ]
}

TODO:

  • more operators / custom operators
  • add value type
  • ...

License

MIT