import cheerio from 'cheerio' // Attributes export const attrImpl = function (nothing, just, name, cheerioInst) { if (cheerioInst.length > 0) { const value = cheerioInst.attr(name) return value != null ? just(value) : nothing } return nothing } export const hasClassImpl = function (className, cheerioInst) { return cheerioInst.hasClass(className) } // Traversing export const findImpl = function (selector, cheerioInst) { return cheerioInst.find(selector) } export const parent = function (cheerioInst) { return cheerioInst.parent() } export const next = function (cheerioInst) { return cheerioInst.next() } export const prev = function (cheerioInst) { return cheerioInst.prev() } export const siblings = function (cheerioInst) { return cheerioInst.siblings() } export const children = function (cheerioInst) { return cheerioInst.children() } export const first = function (cheerioInst) { return cheerioInst.first() } export const last = function (cheerioInst) { return cheerioInst.last() } export const eqImpl = function (index, cheerioInst) { return cheerioInst.eq(index) } // Rendering export const htmlImpl = function (nothing, just, cheerioInst) { return cheerioInst.length ? just(cheerioInst.html()) : nothing } export const text = function (cheerioInst) { return cheerioInst.text() } // Miscellaneous export const length = function (cheerioInst) { return cheerioInst.length }