DESCRIPTION
StayOn is a simple feed manager library in Node and TypeScript. StayOn helps in the process of feed subscription, and the way to obtain its main information. You can add/remove feeds, get latest articles, and some other properties in a easy way.
Useful links
- GitHub page Feel free to open issue for bugs or feature improvements.
- npm Include npm package into you projects.
How is StayOn composed?
StayOn is composed by 4 main class:
- Feed: which represents the feed and contains all related information;
- FeedError: which provides custom error for Feed class;
- Article: which represents the single article, it contains all realted information like title, summary, last update, content, etc..
- StayOn: which is the main container, it offers a simple way to handle feeds and some methods to retrieve useful information.
GETTING STARTED
Installation
StayOn can be simply installed via npm:
npm install stay-on
Or, alternatively, you can download latest release from GitHub page. In this case you have to build it before using.
npm install // to install npm node_modules
npm run build // to build stay-on package
Example
Once you have installed StayOn, you can start using it! Let's see an example.
import StayOn from "stay-on";
(async() => {
// 1. Build a new StayOn to store feeds
const myFeed = new StayOn();
// 2. Add all the feeds we want
await myFeed.addFeed("https://lorem-rss.herokuapp.com/feed");
await myFeed.addFeed("https://lorem-rss.herokuapp.com/feed");
await myFeed.addFeed("https://lorem-rss.herokuapp.com/feed");
// Alternatively, if you want to add more feeds at one time, you can use addFeeds method
await myFeed.addFeed(["https://lorem-rss.herokuapp.com/feed",
"https://lorem-rss.herokuapp.com/feed",
"https://lorem-rss.herokuapp.com/feed"]);
// 3. Retrieve all the info we want from our feed list. Some examples below
// 3.1 Console.log the title of each feed
myFeed.getFeeds().forEach((feed) => {
console.log(feed.getTitle());
});
// 3.2 Console.log the title of each articles on the first feed
myFeed.getFeeds()[0]
.getArticles().forEach((article) => {
console.log(article.getTitle());
});
})();
DOCUMENTATION
StayOn:
- getFeeds()
- getFeedsByTitle(title: string)
- async addFeed(feedUrl: string)
- async addFeeds(feedsUrl: string[])
- removeFeedByTitle(title: string)
- stringify()
- static async buildFromString(stringifiedStayOn: string)
Feed:
- constructor(url: string)
- getTitle()
- getInfo()
- getArticles()
- getArticlesByTitle(title: string)
- getLatestArticles()
- getArticlesByTitle(title: string)
- getLatestArticles()
- async parseFeed()
- stingifyFeed()
- async validateFeed(url: string)
FeedError
Articles
STAY ON
StayOn class offers useful methods to handle feed list:
getFeeds(): Feed[]
Returns feeds list
getFeedsByTitle(title: string): Feed[]
Returns feeds which matches with give title
async addFeed(feedUrl: string): Promise<Feed[]> | never
Add a feed with given feedUrl
:
- if the feed is valid, it's added to feed list which is then Returnsed
- if the feed is invalid, an exception is thrown
async addFeeds(feedsUrl: string[]): Promise<Feed[]> | never
Add all given feeds feedsUrl
:
- if the feed list is valid, it's added to feed list which is then Returnsed
- if the feed list is invalid, an exception is thrown
removeFeedByTitle(title: string): Feed[]
Removes the feed with given title
:
- if the feed is found, it's removed from the list which is then Returnsed
- if the feed is not found, nothing happen and the list is Returnsed
stringify(): string
Returns currend feed list in a stringified form
static async buildFromString(stringifiedStayOn: string): Promise
Builds and returns a feed list from given stringifiedStayOn
FEED
Feed class represents a single feed, and provides useful methods to interact with it:
constructor(url: string)
Builds a Feed object with given url
getTitle(): string
Returns feed's title
getInfo(): object
Returns a JSON object which contains all feed's information
getArticles(): Article[]
Returns all feed's article
getArticlesByTitle(title: string): Article[]
Returns all feeds articles which matches the title
getLatestArticles(): Article
Returns last updated article
async parseFeed(): Promise<void | unknown> | never
Parses the current feed to retrieve its information. Could throw an error if something wrong happens during parsing process
stingifyFeed(): string
Returns feed's information in a stringified form
async validateFeed(url: string): Promise| never
Validates given url. An error is thrown if given url is not valid
FEED ERROR
FeedError class represents custom error for Feed
constructor(message: string, feed: string)
Builds a custom error with given message
for feed
.
toString(): string
Returns a custom error
ARTICLE
Article is a class which represents a single article, and offers several methods to interact with it:
getTitle(): string
Returns article's title
getAuthor(): string
Returns article's author
getContent(): string
Returns article's content
getSummary(): string
Returns article's summary
getLastEditDate(): Date
Returns the last date it was updated the article
getPublishDate(): Date
Returns the publish date of the article
getLink(): string
Returns article's link
CONTRIBUTION
If you want to report a bug, request a new feature, or contribute, please open an issue.
LICENCE
The MIT License (MIT)
Copyright (c) 2015 Filipe Deschamps
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.