1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { fetch } from "https://esm.town/v/std/fetch";
import { extractCommentInfo } from "https://esm.town/v/willthereader/extractCommentInfo";
import { logMessage } from "https://esm.town/v/willthereader/logMessage";
// File: fetchCommentsVal.ts in Val Town (Named: @username.fetchCommentsVal)
export async function fetchComments(url) {
// logMessage("info", `fetchComments called with url: ${url}`); // Log the URL at the outset
const response = await fetch(url);
// logMessage("info", `Response received with status: ${response.status}`);
if (!response.ok) {
throw new Error("Network response was not ok " + response.statusText);
}
const data = await response.json();
// logMessage("info", `Data received: ${data}`);
// console.log(data.comments[0], data.comments[data.comments.length - 1]);
const commentInfoArray = data.comments.map((comment) => extractCommentInfo(comment));
// logMessage("debug", `commentInfoArray: ${JSON.stringify(commentInfoArray)}`); // Log the processed data for debugging
return commentInfoArray;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
February 14, 2024