link-checker-cli
Version:
CLI tool to check for broken links in a website or project
26 lines (25 loc) • 887 B
JavaScript
const LOC_TAG = /<loc>(.*?)<\/loc>/g;
const LOC = /<\/?loc>/g;
class ParserXML {
constructor() {
this.getLinks = (xmlDocument) => {
if (xmlDocument.length === 0)
return [];
const urls = xmlDocument.match(LOC_TAG)?.map((loc) => {
const value = loc.replace(LOC, "");
return { value, type: "internal" };
}) || [];
if (urls.length === 0 && !xmlDocument.startsWith("<")) {
const sliced = xmlDocument.split("https://");
for (const link of sliced) {
if (link.length > 0) {
const value = `https://${link}`;
urls.push({ value, type: "internal" });
}
}
}
return urls;
};
}
}
export const parserXml = new ParserXML();