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.

17 lines (16 loc) 732 B
import { isNonEmptyString, isObject, parseJsonObject } from "../../../common/utils.js"; import { createCaseInsensitiveGetter } from "../parse/utils.js"; //#region src/feeds/json/detect/index.ts const detect = (value) => { const json = parseJsonObject(value); if (!isObject(json)) return false; const get = createCaseInsensitiveGetter(json); const version = get("version"); if (isNonEmptyString(version)) return version.includes("jsonfeed.org/version/"); const hasTitle = isNonEmptyString(get("title")); const hasItems = Array.isArray(get("items")); const hasJsonFeedProps = !!(get("home_page_url") || get("feed_url") || get("authors")); return hasTitle && (hasItems || hasJsonFeedProps); }; //#endregion export { detect };