Comparing version 1.0.3 to 1.0.4
24
index.ts
@@ -42,3 +42,3 @@ #!/usr/bin/env bun | ||
const checkLink = async (url: string): Promise<void> => { | ||
const checkLink = async (url: string): Promise<boolean> => { | ||
try { | ||
@@ -55,4 +55,6 @@ let response = await fetch(url, { method: "HEAD" }); | ||
); | ||
return response.ok; | ||
} catch (error) { | ||
console.error(`Error checking ${url}:`, error); | ||
return false; | ||
} | ||
@@ -70,14 +72,26 @@ }; | ||
const startTime = performance.now(); | ||
const links = await getLinksFromPage(website); | ||
// Execute link checks in parallel. | ||
await Promise.all(links.map((link) => checkLink(link))); | ||
// Fetch links and check them in parallel for efficiency | ||
const linkStatuses = (await getLinksFromPage(website)).map(checkLink); | ||
const results = await Promise.allSettled(linkStatuses); | ||
const endTime = performance.now(); | ||
const okCount = results.filter( | ||
(result) => result.status === "fulfilled" && result.value | ||
).length; | ||
const brokenCount = results.length - okCount; | ||
console.log(chalk.blueBright("~".repeat(40))); | ||
console.log( | ||
`Checked ${links.length} links in ${(endTime - startTime).toFixed( | ||
`Checked ${results.length} links in ${(endTime - startTime).toFixed( | ||
2 | ||
)} milliseconds.` | ||
); | ||
console.log(`Total OK: ${chalk.green(okCount.toString())}`); | ||
console.log(`Total Broken: ${chalk.red(brokenCount.toString())}`); | ||
}; | ||
main(); |
{ | ||
"name": "brokenurl", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "index.ts", | ||
@@ -5,0 +5,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
13205
101