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.

34 lines (33 loc) 1.12 kB
import { locales } from "./config.js"; import { parseJsonObject } from "./utils.js"; import { detect } from "../feeds/atom/detect/index.js"; import { parse as parse$1 } from "../feeds/atom/parse/index.js"; import { detect as detect$1 } from "../feeds/json/detect/index.js"; import { parse as parse$2 } from "../feeds/json/parse/index.js"; import { detect as detect$2 } from "../feeds/rdf/detect/index.js"; import { parse as parse$3 } from "../feeds/rdf/parse/index.js"; import { detect as detect$3 } from "../feeds/rss/detect/index.js"; import { parse as parse$4 } from "../feeds/rss/parse/index.js"; //#region src/common/parse.ts const parse = (value, options) => { if (detect$3(value)) return { format: "rss", feed: parse$4(value, options) }; if (detect(value)) return { format: "atom", feed: parse$1(value, options) }; if (detect$2(value)) return { format: "rdf", feed: parse$3(value, options) }; const json = parseJsonObject(value); if (detect$1(json)) return { format: "json", feed: parse$2(json, options) }; throw new Error(locales.unrecognizedFeedFormat); }; //#endregion export { parse };