2023-10-28 19:46:44 +00:00
|
|
|
import cheerio from 'cheerio'
|
2018-01-16 04:35:48 +00:00
|
|
|
|
|
|
|
// Attributes
|
2023-10-28 19:46:44 +00:00
|
|
|
export const attrImpl = function(nothing, just, name, cheerioInst) {
|
2018-07-29 13:55:58 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const hasClassImpl = function(className, cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.hasClass(className);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Traversing
|
2023-10-28 19:46:44 +00:00
|
|
|
export const findImpl = function(selector, cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.find(selector);
|
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const parent = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.parent()
|
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const next = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.next()
|
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const prev = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.prev()
|
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const siblings = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.siblings()
|
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const children = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.children()
|
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const first = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.first()
|
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const last = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.last()
|
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const eqImpl = function(index, cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.eq(index)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rendering
|
2023-10-28 19:46:44 +00:00
|
|
|
export const htmlImpl = function(nothing, just, cheerioInst) {
|
2018-07-29 13:31:38 +00:00
|
|
|
return cheerioInst.length ? just(cheerioInst.html()) : nothing;
|
2018-01-16 04:35:48 +00:00
|
|
|
}
|
|
|
|
|
2023-10-28 19:46:44 +00:00
|
|
|
export const text = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.text()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Miscellaneous
|
2023-10-28 19:46:44 +00:00
|
|
|
export const length = function(cheerioInst) {
|
2018-01-16 04:35:48 +00:00
|
|
|
return cheerioInst.length;
|
2018-07-29 13:31:38 +00:00
|
|
|
}
|