feedsmith

repository·main·Indexed 20 days ago

https://github.com/macieklamberski/feedsmith

A 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. It provides dual ESM/CJS package exports and includes functions such as generateRssFeed, generateAtomFeed, generateJsonFeed, and generateOpml for creating formatted feed strings.

Tokens
34.8K
Snippets
117
Records
166
Agent score
69%

What's inside feedsmith

  1. Overview of Feedsmith benchmark modes

    main

    Feedsmith provides two distinct types of benchmarks to evaluate performance:

    1. JavaScript Benchmarks: Used to compare Feedsmith's performance against other JavaScript-based feed parsing libraries.
    2. Cross-Language Benchmarks: Used to compare Feedsmith against prominent feed parsing libraries written in other programming languages.

    Note on Comparison Fairness: When reviewing results, be aware that different packages vary in feature support (e.g., handling specific XML namespaces or feed formats). Direct comparisons may not always be perfectly equivalent due to these functional differences.

  2. Overview of compatibility test scenarios

    main

    The test suite covers 16 distinct scenarios to ensure feedsmith works in diverse consumer environments. These are categorized into four main groups:

    TypeScript (9 scenarios)

    Validates different module and moduleResolution settings:

    • modern-esm ("type": "module"): Covers node (legacy), node16, nodenext, and bundler resolutions.
    • modern-cjs ("type": "commonjs"): Covers combinations of commonjs/node16/nodenext/esnext modules with their corresponding resolutions.
    • legacy-cjs ("type": "commonjs"): Uses module: "commonjs" with moduleResolution: "node" and require() syntax.

    Explicit Module Extensions (3 scenarios)

    Validates file extension handling:

    • esm-package: .mts and .cts files in an ESM context.
    • cjs-package: .mts and .cts files in a CJS context.
    • mixed-package: Coexistence of .ts, .mts, and .cts files.

    JavaScript Runtime (2 scenarios)

    Validates execution in pure JS environments:

    • esm: Runs index.js (following package type) and index.mjs (explicit ESM).
    • cjs: Runs index.js (following package type) and index.cjs (explicit CJS).

    Bundler (2 scenarios)

    Validates integration with build tools like Vite:

    • Vite ESM: TypeScript entry (index.ts) using import syntax.
    • Vite CJS: CommonJS entry (index.cjs) using require() syntax.
  3. How Feedsmith handles date parsing

    main

    Feedsmith does not attempt to automatically parse date strings into Date objects. Instead, it returns dates in their original string form as found in the feed.

    This design choice prevents parsing errors caused by non-standard formats and allows developers to use their own preferred date parsing library (such as date-fns or luxon), a custom parsing function, or the native JavaScript Date object to handle the strings.

  4. Compare Strict Mode vs Lenient Mode

    main

    Strict Mode (Default)

    Use this when creating new feeds from scratch with complete data and when you want TypeScript to enforce specification requirements. Dates must be Date objects.

    const feed = {
      title: 'My Blog',
      link: 'https://example.com',
      description: 'A blog about things',
      pubDate: new Date('2024-01-01'),
      items: [
        {
          title: 'Post 1',
          link: 'https://example.com/post1',
          description: 'First post',
          pubDate: new Date('2024-01-02')
        }
      ]
    }
    const xml = generateRssFeed(feed)

    Lenient Mode

    Use this for processing external feeds, building feeds incrementally, or working with legacy data. All fields are optional and string dates are accepted.

    const partialFeed = {
      title: 'My Blog',
      pubDate: '2024-01-01T00:00:00Z', // String date accepted
      items: [
        {
          title: 'Post 1',
          pubDate: 'Mon, 01 Jan 2024 12:00:00 GMT' // RFC822 string accepted
        }
      ]
    }
    const xml = generateRssFeed(partialFeed, { lenient: true })
  5. Use the Atom Namespace in RSS and RDF feeds

    main
    The Atom namespace (http://www.w3.org/2005/Atom) allows you to include Atom-specific elements within RSS or RDF feeds. This provides richer metadata and linking capabilities by embedding partial Atom elements into other feed formats using the <atom:*> prefix. This is useful when you need to support Atom features while maintaining compatibility with RSS or RDF consumers.
  6. Use the Administrative Namespace (MVCB)

    main

    The Administrative namespace (Meta Vocabulary for Community Building - MVCB) is used to provide administrative metadata within RSS, Atom, or RDF feeds. This metadata helps identify feed generators and provides contact information for error reporting. It follows the Admin Module Specification.

    <!-- Namespace Details -->
    Namespace URI: http://webns.net/mvcb/
    Prefix: <admin:*>
    Available in: RSS, Atom, RDF
  7. Namespace URI tolerance and variations

    main

    Feedsmith is designed to be tolerant of common variations in namespace URI declarations. It automatically recognizes and normalizes the following variations to ensure compatibility with real-world, non-compliant feeds:

    • Protocol variations: Using https:// instead of http://.
    • Casing variations: Different capitalization in the URI string.
    • Trailing slashes: URIs declared with or without a trailing slash.
    • Whitespace: Leading or trailing whitespace around the URI string.
  8. Understand the Explicit Modules - ESM Package test scenario

    main
    The Explicit Modules - ESM Package test suite validates that feedsmith functions correctly when used with explicit TypeScript module extensions within an ESM (ECMAScript Module) package context. This ensures that the library's export conditions for both ESM and CommonJS are correctly handled by TypeScript and runtimes when file extensions are used to disambiguate module types.
  9. Understand the Syndication Namespace (sy)

    main

    The Syndication namespace (sy) provides metadata regarding the frequency and timing of feed updates. This information allows aggregators to determine how often they should poll for new content. It is supported across RSS, Atom, and RDF feed formats.

    Technical Details:

    • Namespace URI: http://purl.org/rss/1.0/modules/syndication/
    • Prefix: <sy:*>
    • Property Name: sy