purescript-cheerio/src/Cheerio.js

68 lines
1.4 KiB
JavaScript
Raw Normal View History

import cheerio from 'cheerio'
2018-01-16 04:35:48 +00:00
// 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;
2018-01-16 04:35:48 +00:00
}
export const hasClassImpl = function(className, cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.hasClass(className);
}
// Traversing
export const findImpl = function(selector, cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.find(selector);
}
export const parent = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.parent()
}
export const next = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.next()
}
export const prev = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.prev()
}
export const siblings = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.siblings()
}
export const children = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.children()
}
export const first = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.first()
}
export const last = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.last()
}
export const eqImpl = function(index, cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.eq(index)
}
// Rendering
export const htmlImpl = function(nothing, just, cheerioInst) {
return cheerioInst.length ? just(cheerioInst.html()) : nothing;
2018-01-16 04:35:48 +00:00
}
export const text = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.text()
}
// Miscellaneous
export const length = function(cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.length;
}