UNPKG

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.

15 lines (14 loc) 633 B
import { isNonEmptyString } from "../../../common/utils.js"; //#region src/feeds/rss/detect/index.ts const rssElementRegex = /(?:^|[\s>])<(?:\w+:)?rss[\s>]/im; const versionAttributeRegex = /version\s*=\s*["'][^"']*["']/i; const rssElementsRegex = /(<(channel|item|title|link|description|pubDate|guid)[\s>])/i; const detect = (value) => { if (!isNonEmptyString(value)) return false; if (!rssElementRegex.test(value)) return false; const hasVersionAttribute = versionAttributeRegex.test(value); const hasRssElements = rssElementsRegex.test(value); return hasVersionAttribute || hasRssElements; }; //#endregion export { detect };