node-pick

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i node-pick

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

67.1 kB

Total Files

12

Last publish

Collaborators

  • xiaokeket