Refactor getSubTags and getParentTags in order to use cheerio maps#86
Refactor getSubTags and getParentTags in order to use cheerio maps#86darthnithin wants to merge 29 commits intoFujoWebDev:mainfrom
Conversation
| anonymous: false, | ||
| }); | ||
| }); | ||
| } as Author |
There was a problem hiding this comment.
We should figure out why you need "as Author" here. What happens if change line 42 to be
return authorLinks.map((_, element): Author => {There was a problem hiding this comment.
i'm pretty sure i don't need to. I'll check tomorrow
| const description = $seriesPage("dl.series blockquote.userstuff").html(); | ||
| return description ? description.trim() : null; | ||
| export const getSeriesDescription = ($seriesPage: SeriesPage): string | null => { | ||
| return $seriesPage("dl.series blockquote.userstuff").html()?.trim() || null; |
There was a problem hiding this comment.
[...].trim() ?? null, unless you want empty string to become null.
There was a problem hiding this comment.
that's the original behavior which I preserved.
if description is an empty string the conditional is falsy
| }); | ||
| }); | ||
| return $tagPage(".sub > ul.tags > li").map((_, element) => { | ||
| if($tagPage($tagPage(element).has("ul.tags")).length) { |
There was a problem hiding this comment.
Change this for an early if return (the thing we discussed on Discord) if you can :)
| return pseudsArray.join(PSEUD_SUFFIX); | ||
| return pseuds.length !== 0 | ||
| ? pseuds.map((_, element) => decodeURI(element.attribs.href.match(/users\/(.+)\/pseuds\/(.+)/)![2])) | ||
| .get() |
There was a problem hiding this comment.
is there a reason why you changed this? it makes it harder to understand what's going on.
I would
- if
pseudsis empty, immediately return"" - if not, do
pseuds.maplike you're doing now - keep the inner function (
const url = element.attribs.href;etc) as is, but return instead of adding to the array.
| return authors; | ||
| } | ||
| }).get() | ||
| : [] as Author[]; |
There was a problem hiding this comment.
Ternary operators are useful, but they can be cognitively heavy when large. If you immediately return [] as soon as you know that the authorNode is empty, that will make the code much easier to reason about. Same in the code below.
Refactored getSubTags