Created
September 21, 2020 20:31
-
-
Save humphd/44b0bf55d4da896affcf6b8ef2074991 to your computer and use it in GitHub Desktop.
Link Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const linkchecker = (link) => { | |
//processes Links | |
let status = 200; | |
fetch(link.url).then(res => { | |
const status = res.status; | |
switch (status) { | |
case 200: | |
link.status = StatusEnum.good; | |
console.log(chalk.green(link.toString())); | |
break; | |
case 400: | |
case 404: | |
link.status = StatusEnum.bad; | |
console.log(chalk.red(link.toString())); | |
break; | |
default: | |
console.log(chalk.grey(link.toString())); | |
}) | |
.catch(err => console.log('...') | |
}; | |
const documentProccessing = async (doc) => { | |
//processDocument | |
try { | |
let data = await fs.readFile(process.cwd() + "/" + doc, "utf8"); // gets the data in the document | |
new Set(doc.match(link_reg)).forEach((e) => { | |
// gets all http/https linnks in the document and create a Link and checks it | |
let checkThis = new Link(e, StatusEnum.unknown); | |
linkchecker(checkThis); | |
}); | |
} catch (e) { | |
console.log(e); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment