purescript-cheerio/src/Cheerio.js

67 lines
1.4 KiB
JavaScript
Raw Normal View History

import cheerio from 'cheerio'
2018-01-16 04:35:48 +00:00
// Attributes
2023-10-28 19:47:41 +00:00
export const attrImpl = function (nothing, just, name, cheerioInst) {
if (cheerioInst.length > 0) {
2023-10-28 19:47:41 +00:00
const value = cheerioInst.attr(name)
return value != null ? just(value) : nothing
}
2023-10-28 19:47:41 +00:00
return nothing
2018-01-16 04:35:48 +00:00
}
2023-10-28 19:47:41 +00:00
export const hasClassImpl = function (className, cheerioInst) {
return cheerioInst.hasClass(className)
2018-01-16 04:35:48 +00:00
}
// Traversing
2023-10-28 19:47:41 +00:00
export const findImpl = function (selector, cheerioInst) {
return cheerioInst.find(selector)
2018-01-16 04:35:48 +00:00
}
2023-10-28 19:47:41 +00:00
export const parent = function (cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.parent()
}
2023-10-28 19:47:41 +00:00
export const next = function (cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.next()
}
2023-10-28 19:47:41 +00:00
export const prev = function (cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.prev()
}
2023-10-28 19:47:41 +00:00
export const siblings = function (cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.siblings()
}
2023-10-28 19:47:41 +00:00
export const children = function (cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.children()
}
2023-10-28 19:47:41 +00:00
export const first = function (cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.first()
}
2023-10-28 19:47:41 +00:00
export const last = function (cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.last()
}
2023-10-28 19:47:41 +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:47:41 +00:00
export const htmlImpl = function (nothing, just, cheerioInst) {
return cheerioInst.length ? just(cheerioInst.html()) : nothing
2018-01-16 04:35:48 +00:00
}
2023-10-28 19:47:41 +00:00
export const text = function (cheerioInst) {
2018-01-16 04:35:48 +00:00
return cheerioInst.text()
}
// Miscellaneous
2023-10-28 19:47:41 +00:00
export const length = function (cheerioInst) {
return cheerioInst.length
}