npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@grenzbotin/feedlink

v0.5.1

Published

Utils for rss feeds on websites.

Downloads

10

Readme

@grenzbotin/feedlink

npm npm made-with-javascript license

GitHub last commit GitHub issues Tests

This package contains helpful utils for reading and working with rss feeds on websites.


Contents

  1. Installation
  2. Functions
  3. Shoutout

👋 Installation

npm i @grenzbotin/feedlink

🤘 Functions

Usage

Import the package.

import * as feedlink from "@grenzbotin/feedlink";

Get

since @grenzbotin/feedlink@0.1.0

Description: The get function takes any website link and tries to find and return a feed link.

Note: Will return a promise.

import * as feedlink from "@grenzbotin/feedlink";

async function getRSS(link) {
  return feedlink.get(link);
}

const rssLink = await getRSS("https://www.(Example1|2|3)");

console.log("Result: ", rssLink);

Example 1: nature.com

Result:  { success: true, href: 'https://www.nature.com/nature.rss' }

Example 2: css-tricks.com

Result:  { success: true, href: 'https://css-tricks.com/feed/' }

Example 3: science.org

Result:  { success: false, err: 'ERR_NON_2XX_3XX_RESPONSE' }

Limitation: As you see on the third example, there is no guarantee that the module will find a feed link. While the package might become more clever over time and find more rss feeds on the go, not every page has an rss feed or wants to have one.


Validate

since @grenzbotin/feedlink@0.1.3

Description: The validate function takes any feed link and returns whether its a valid link including potential errors, warnings or information with the help of the w3c validator. Not possible without the great work behind validator.w3.org/feed.

Note: Will return a promise.

import * as feedlink from "@grenzbotin/feedlink";

async function validate(link) {
  return feedlink.validate(link);
}

const result = await validate("https://some-link");

console.log("Result: ", result);

// Result:  {
//  isValid: true,
//  errorsList: [],
//  warningsList: [
//    'SelfDoesntMatchLocation',
//    'UnknownNamespace',
//    'NotHtml',
//    'NotHtml',
//    'ContainsRelRef'
//  ],
//  infoList: []
// }

Parse

since @grenzbotin/feedlink@0.2.0

Description: The parse function takes any feed link or feed string and returns feed information in json-format. It is just a simplified wrapper around the rss-parser. Thus, you can hand in the same parsing options as described here.

Note: Will return a promise.

Example 1: parse link

import * as feedlink from "@grenzbotin/feedlink";

async function parse(link) {
  return feedlink.parse(link);
}

const result = await parse("https://some-link");

console.log("Example result: ", result);

// Example result:  {
//  success: true,
//  result: {
//    items: [
//      [Object], [Object],
//      [Object], [Object],
//      [Object], [Object],
//      [Object], [Object],
//      [Object], [Object],
//      [Object], [Object],
//      [Object], [Object],
//      [Object]
//    ],
//    feedUrl: 'url',
//    image: {...},
//    paginationLinks: { self: 'url' },
//    title: 'title',
//    description: 'description',
//    generator: 'https://wordpress.org/?v=6.2.2',
//    link: 'url',
//    language: 'en-US',
//    lastBuildDate: 'Wed, 12 Apr 2023 17:42:35 +0000'
//  }
//}

Example 2: parse string

import * as feedlink from "@grenzbotin/feedlink";

async function parse(string) {
  return feedlink.parse(string);
}

const exampleString = `
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Feed title</title>
    <link>Website url</link>
    <description>description</description>
    <language>en-en</language>
    <pubDate>Sun, 6 Aug 2023 2:43:19</pubDate>
    <image>
      <url>image url</url>
      <title>image title</title>
      <link>url link</link>
    </image>
    <item>
      <title>title</title>
      <description>description</description>
    </item>
  </channel>
</rss>`;

const result = await parse(exampleString);

console.log("Example result: ", result);

// Example result:  {
//  success: true,
//  result: {
//    items: [{
//      content: "description",
//      contentSnippet: "description",
//      title: "title",
//    }],
//    image: { link: 'url link', url: 'image url', title: 'image title' },
//    title: 'Feed title',
//    description: 'description',
//    pubDate: 'Sun, 6 Aug 2023 2:43:19',
//    link: 'Website url',
//    language: 'en-en'
//  }
//}

Example 3: parse string with renaming keys

import * as feedlink from "@grenzbotin/feedlink";

async function parse(string) {
  return feedlink.parse(string);
}

const exampleString = `
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Feed title</title>
    <link>Website url</link>
    <description>description</description>
    <language>en-en</language>
    <pubDate>Sun, 6 Aug 2023 2:43:19</pubDate>
    <image>
      <url>image url</url>
      <title>image title</title>
      <link>url link</link>
    </image>
    <item>
      <title>title</title>
      <description>description</description>
    </item>
  </channel>
</rss>`;

const result = await parse(exampleString, {
  customFields: {
    item: [
      ["description", "👾content"],
      ["title", "👾title"],
    ],
  },
});

console.log("Example result: ", result);

// Example result:  {
//  success: true,
//  result: {
//    items: [  {
//      "👾content": "description",
//      content: "description",
//      contentSnippet: "description",
//      "👾title": "title",
//      title: "title",
//    }],
//    image: { link: 'url link', url: 'image url', title: 'image title' },
//    title: 'Feed title',
//    description: 'description',
//    pubDate: 'Sun, 6 Aug 2023 2:43:19',
//    link: 'Website url',
//    language: 'en-en'
//  }
//}

🌻 Shoutout

A big shoutout and thank you goes to

Notes

  • v0.5.0 Temporary adjustment: rss-parser: contains a reference to a commit to solve request timeout handling due to missing merge.

MacOS arm

For users that are working on macos arm processors: Please follow the instructions mentioned in here to make the lib work on your machine: [email protected] install: node install.js on M1