UNPKG

link-checker-cli

Version:

CLI tool to check for broken links in a website or project

21 lines (20 loc) 527 B
export function isLink(value) { const isLinkRegex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/; return isLinkRegex.test(value); } export async function getPageData(url) { const fetchAble = isLink(url); if (fetchAble) { const response = await fetch(url); if (response.ok) { return await response.text(); } else { return ""; } } else { throw new Error("Input value is not a link!"); } } ;