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

listener-rss

v0.0.3

Published

A lightweight library to create a listener from a rss feed.

Downloads

45

Readme

listener rss

A lightweight library to make simple actions with a RSS feed.

USAGE

Punctual usage

You can parse RSS from a URL with some custom data.
An example :

const ListenerModule = require("ListenerRSS");
const ListenerRss = ListenerModule.ListenerRss;

const listener = new ListenerRss({
    address: "fake.rss.service"
  });

// make a request to the adr 'fake.rss.service'
const feed = await myListener.fetchRSS();

Recurrent usage

You can parse RSS from a URL each n times.
An example :

const ListenerModule = require("ListenerRSS");
const ListenerRss = ListenerModule.ListenerRss;

const listener = new ListenerRss({
    address: "fake.rss.service"
  });

listener.on("update", feed => { /* ... */ });
listener.on("error", err => { /* ... */ });
listener.on("newEntries", feedEntries => { /* ... */ });


listener.start();

/*...*/

listener.stop();

Documentation

ListenerRss.Config

An interface to structure listener's data.

Constructor

  • address : the service address
  • [optional] timeloop : time to wait between 2 request in seconds (default 5 minutes)
  • [optional] customfields : to notice field who's custom to the service (default blank) cf annexe CustomFields
  • [optional] lastEntriesLinks : to specify an predefined history.

ListenerRSS

Constructor

constructor(ListenerRss.Config)

  • ListenerRss.Config : object from the ListenerRss.Config's class.

fetchRSS()

This function allows to make a request to the rss service.

Return

Return a promise object who's resolved like resolve: (value: result_fetch) => void)) where result_fetch is a json object who's contain the data. cf Annexe Output

Issues

Reject the promise if the server can't be resolved.

start()

This function will call the update event to each success update, the error event to each fail update, and the newEntries event for each update who contains a new item.

Events

Each event take one arg into the callback function.

listener.on("update", feed => { /* ... */ });
listener.on("error", err => { /* ... */ });
listener.on("newEntries", feedEntries => { /* ... */ });

update

It used a callback who receive the received object entirely inside an object.

error

It used a callback who receive an error object.

newEntries

It used a callback who receive only new entries inside an array.

stop()

This function will stop the execution of the callbackFun each time loop.

getProperty()

This function will return a ListenerRss.Config (a.k.a. a JSON object) item corresponding to the internal configuration of the class.

Annexe

CustomFields

This parameter permit to specify some custom fields who's present in the service but not in the RFC. For example the YouTube RSS api give some data into the <media:group> field. So you can give this info with this :

[["media:group", "media:group"]];

You can also rename the field with the left part :

[["my_custom_media_group_name", "media:group"]];

In adition you can rename child element into custom field like this :

[
  ["media:group", "media:group"],
  ["description", ["media:group", "media:description"]],
  ["icon", ["media:group", "media:thumbnail"]],
];

In this case it's useless to specify the parent field, so you can just omit the first line :

[
  ["description", ["media:group", "media:description"]],
  ["icon", ["media:group", "media:thumbnail"]],
];

Output

Here an example of what type of json object is output during a fetch :

{
  "feedUrl": "fake.rrs.service",
  "title": "myFakeApiTitle",
  "description": "My Fake api desc",
  "link": "fake.rrs.service",
  "items": [
    {
      "title": "My last item",
      "link": "fake.rrs.service/item1",
      "pubDate": "Thu, 12 Nov 2015 21:16:39 +0000",
      "creator": "someone",
      "content": "<a href=\"http://example.com\">this is a link</a> &amp; <b>this is bold text</b>",
      "contentSnippet": "this is a link & this is bold text",
      "guid": "fake.rrs.service/item1",
      "categories": ["test", "npm", "fakeInfos"],
      "isoDate": "2015-11-12T21:16:39.000Z"
    }
    /*Some Others items*/
  ]
}