cracker

0.0.0 • Public • Published

cracker

Usage

// examples/github-profile.js
const fetch = require('cracker')
 
function *run() {
  const url = 'https://github.com/fritx'
  const rules = {
    *stats($) {
      const $stats = $('.vcard-stat')
      const stats = {}
      $stats.each((i, el) => {
        const $el = $(el)
        const key = $el.find('.text-muted').text()
        const val = Number($el.find('.vcard-stat-count').text())
        stats[key] = val
      })
      return stats
    },
    *repos($) {
      // `:first` not supported in cheerio
      // const $repos = $('ul.mini-repo-list:first > li')
      const $repos = $('ul.mini-repo-list').first().find('li')
      const repos = []
      $repos.each((i, el) => {
        const $repo = $(el)
        repos.push({
          title: $repo.find('.repo').text(),
          desc: $repo.find('.repo-description').text(),
          stars: Number($repo.find('.stars').text())
        })
      }).get()
      return repos
    }
  }
  return yield fetch(url, rules)
}

Todo

  • CLI Usage
  • AJAX Support

Readme

Keywords

none

Package Sidebar

Install

npm i cracker

Weekly Downloads

0

Version

0.0.0

License

MIT

Last publish

Collaborators

  • fritx