chore: fmt

This commit is contained in:
orion 2023-10-28 14:47:41 -05:00
parent c5fc886786
commit f3ddfde201
Signed by: orion
GPG Key ID: 6D4165AE4C928719
10 changed files with 49 additions and 45 deletions

View File

@ -4,5 +4,5 @@ module.exports = {
singleQuote: true, singleQuote: true,
semi: false, semi: false,
arrowParens: 'avoid', arrowParens: 'avoid',
plugins: ['prettier-plugin-sh'], plugins: [],
} }

BIN
bun.lockb

Binary file not shown.

View File

@ -7,7 +7,7 @@
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"fmt": "bun fmt", "fmt": "bun bun/fmt.js",
"build": "bun x spago build", "build": "bun x spago build",
"test": "bun x spago test" "test": "bun x spago test"
}, },

View File

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

View File

@ -26,8 +26,9 @@ import Data.Maybe (Maybe(..))
foreign import data Cheerio :: Type foreign import data Cheerio :: Type
-- Attributes -- Attributes
foreign import attrImpl :: forall a. foreign import attrImpl
Fn4 (Maybe a) (a -> Maybe a) String Cheerio (Maybe String) :: forall a
. Fn4 (Maybe a) (a -> Maybe a) String Cheerio (Maybe String)
-- | Gets an attribute value from the first selected element, returning -- | Gets an attribute value from the first selected element, returning
-- | Nothing when there are no selected elements, or when the first selected -- | Nothing when there are no selected elements, or when the first selected
@ -60,8 +61,9 @@ eq :: Int -> Cheerio -> Cheerio
eq = runFn2 eqImpl eq = runFn2 eqImpl
-- Rendering -- Rendering
foreign import htmlImpl :: forall a. foreign import htmlImpl
Fn3 (Maybe a) (a -> Maybe a) Cheerio (Maybe String) :: forall a
. Fn3 (Maybe a) (a -> Maybe a) Cheerio (Maybe String)
-- | Gets an html content string from the first selected element, returning -- | Gets an html content string from the first selected element, returning
-- | Nothing when there are no selected elements. -- | Nothing when there are no selected elements.
@ -79,4 +81,4 @@ foreign import length :: Cheerio -> Int
toArray :: Cheerio -> Array Cheerio toArray :: Cheerio -> Array Cheerio
toArray c toArray c
| length c == 0 = [] | length c == 0 = []
| otherwise = map (\i -> eq i c) (0 .. (length c - 1)) | otherwise = map (\i -> eq i c) (0 .. (length c - 1))

View File

@ -4,21 +4,21 @@ import cheerio from 'cheerio'
export const load = cheerio.load export const load = cheerio.load
// Selecting // Selecting
export const selectImpl = function(str, cheerioStatic) { export const selectImpl = function (str, cheerioStatic) {
return cheerioStatic(str) return cheerioStatic(str)
} }
export const selectDeepImpl = function(strArr, cheerioStatic) { export const selectDeepImpl = function (strArr, cheerioStatic) {
return cheerioStatic.apply(cheerioStatic, strArr) return cheerioStatic.apply(cheerioStatic, strArr)
} }
// Rendering // Rendering
export const htmlImpl = function(nothing, just, cheerioInst) { export const htmlImpl = function (nothing, just, cheerioInst) {
const ret = cheerio.html(cheerioInst) const ret = cheerio.html(cheerioInst)
return ret != null ? just(ret) : nothing return ret != null ? just(ret) : nothing
} }
// Utilities // Utilities
export const root = function(cheerioStatic) { export const root = function (cheerioStatic) {
return cheerio.root.call(cheerioStatic) return cheerio.root.call(cheerioStatic)
} }

View File

@ -30,8 +30,9 @@ selectDeep :: Array String -> CheerioStatic -> Cheerio
selectDeep = runFn2 selectDeepImpl selectDeep = runFn2 selectDeepImpl
-- Rendering -- Rendering
foreign import htmlImpl :: forall a. foreign import htmlImpl
Fn3 (Maybe a) (a -> Maybe a) Cheerio (Maybe String) :: forall a
. Fn3 (Maybe a) (a -> Maybe a) Cheerio (Maybe String)
html :: Cheerio -> Maybe String html :: Cheerio -> Maybe String
html = runFn3 htmlImpl Nothing Just html = runFn3 htmlImpl Nothing Just

View File

@ -155,7 +155,7 @@ suites = do
(emptyCheerio # toArray # map (attr "class")) (emptyCheerio # toArray # map (attr "class"))
Assert.equal Assert.equal
(map Just ["apple", "orange", "pear"]) (map Just [ "apple", "orange", "pear" ])
(loadRoot htmlEx # find "li" # toArray # map (attr "class")) (loadRoot htmlEx # find "li" # toArray # map (attr "class"))
suite "More" do suite "More" do
@ -163,10 +163,11 @@ suites = do
Assert.equal Assert.equal
"Apple" "Apple"
( loadRoot htmlEx ( loadRoot htmlEx
# find ".apple" # find ".apple"
# siblings # siblings
# eq 1 # eq 1
# parent # parent
# children # children
# first # first
# text) # text
)

View File

@ -41,7 +41,7 @@ suites = do
test "selectDeep" do test "selectDeep" do
Assert.equal Assert.equal
"Apple" "Apple"
(load htmlEx # selectDeep [".apple", "#fruits"] # text) (load htmlEx # selectDeep [ ".apple", "#fruits" ] # text)
suite "Rendering" do suite "Rendering" do
test "html" do test "html" do

View File

@ -1,7 +1,8 @@
module Test.HtmlEx where module Test.HtmlEx where
htmlEx :: String htmlEx :: String
htmlEx = """ htmlEx =
"""
<ul id="fruits"> <ul id="fruits">
<li class="apple">Apple</li> <li class="apple">Apple</li>
<li class="orange">Orange</li> <li class="orange">Orange</li>