feedsmith
Version:
Fast, all‑in‑one feed parser and generator for RSS, Atom, RDF, and JSON Feed, with support for Podcast, iTunes, Dublin Core, and OPML files.
26 lines (25 loc) • 1.11 kB
JavaScript
const require_config = require("../../../common/config.cjs");
const require_utils = require("../../../common/utils.cjs");
//#region src/feeds/rdf/detect/index.ts
const rssNamespaceUris = [
"http://purl.org/rss/1.0/",
"https://purl.org/rss/1.0/",
"http://purl.org/rss/1.0",
"https://purl.org/rss/1.0",
"http://channel.netscape.com/rdf/simple/0.9/",
"https://channel.netscape.com/rdf/simple/0.9/",
"http://channel.netscape.com/rdf/simple/0.9",
"https://channel.netscape.com/rdf/simple/0.9"
];
const rdfElementRegex = /(?:^|[\s>])<(?:\w+:)?rdf[\s>]/im;
const rdfElementsRegex = /(<(?:\w+:)?(channel|item|title|link|description)[\s>])/i;
const detect = (value) => {
if (!require_utils.isNonEmptyString(value)) return false;
if (!rdfElementRegex.test(value)) return false;
const hasRdfNamespace = require_config.namespaceUris.rdf.some((uri) => value.includes(uri));
const hasRssNamespace = rssNamespaceUris.some((uri) => value.includes(uri));
const hasRdfElements = rdfElementsRegex.test(value);
return hasRdfNamespace || hasRssNamespace || hasRdfElements;
};
//#endregion
exports.detect = detect;