Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

feed

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feed - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

360

lib/feed.js

@@ -1,3 +0,2 @@

var xml = require('xml');
var xml = require('xml');
var generatorName = 'Feed for Node.js';

@@ -9,46 +8,47 @@

function Feed(options) {
this.title = options.title;
this.description = options.description;
this.link = options.link;
this.image = options.image;
this.copyright = options.copyright;
this.title = options.title;
this.description = options.description;
this.link = options.link;
this.image = options.image;
this.copyright = options.copyright;
this.author = options.author;
this.author = options.author;
this.items = [];
this.categories = [];
this.items = [];
this.categories = [];
this.item = function (options) {
options = options || {};
var item = {
title: options.title,
link: options.link,
description: options.description,
date: options.date,
image: options.image
};
this.item = function (options) {
options = options || {};
var item = {
title: options.title,
link: options.link,
description: options.description,
date: options.date,
image: options.image,
author: options.author
};
this.items.push(item);
return this;
}
this.items.push(item);
return this;
}
this.category = function (category) {
this.categories.push(category);
return this;
}
this.category = function (category) {
this.categories.push(category);
return this;
}
this.render = function (format) {
switch(format) {
case 'rss-2.0':
return rss_2_0(this);
break;
this.render = function (format) {
switch(format) {
case 'rss-2.0':
return rss_2_0(this);
break;
case 'atom-1.0':
return atom_1_0(this);
break;
case 'atom-1.0':
return atom_1_0(this);
break;
default:
return rss_2_0(this);
}
};
default:
return rss_2_0(this);
}
};
};

@@ -58,3 +58,3 @@

// Atom 1.0 [application/atom+xml]
//
//
// - Reference: http://www.atomenabled.org/developers/syndication/

@@ -64,101 +64,117 @@ // ============================================================================

function atom_1_0(options) {
var items = [],
container = [],
feed = [],
var items = [],
container = [],
feed = [],
entries = options.items,
categories = options.categories,
author = options.author,
d = new Date();
entries = options.items,
categories = options.categories,
author = options.author,
d = new Date();
var doctype = '<?xml version="1.0" encoding="utf-8"?>\n';
var doctype = '<?xml version="1.0" encoding="utf-8"?>\n';
container.push({ feed: feed });
feed.push({ _attr: { xmlns: 'http://www.w3.org/2005/Atom' }});
/**************************************************************************
* "feed" node: REQUIRED elements
*************************************************************************/
feed.push({ title: options.title });
feed.push({ id: options.link });
feed.push({ updated: RFC3339(d) }); // Auto-magic :)
container.push({ feed: feed });
feed.push({ _attr: { xmlns: 'http://www.w3.org/2005/Atom' }});
/**************************************************************************
* "feed" node: REQUIRED elements
*************************************************************************/
feed.push({ title: options.title });
feed.push({ id: options.link });
feed.push({ updated: RFC3339(d) }); // Auto-magic :)
/**************************************************************************
* "feed" node: recommended elements
*************************************************************************/
if(author)
feed.push({ author: [
{ name: author.name },
{ email: author.email },
{ uri: author.link }
]});
/**************************************************************************
* "feed" node: recommended elements
*************************************************************************/
if(author)
feed.push({ author: [
{ name: author.name },
{ email: author.email },
{ uri: author.link }
]});
// link (relative link to feed) - will be added in a future version
// link (relative link to feed) - will be added in a future version
/**************************************************************************
* "feed" node: optional elements
*************************************************************************/
if(options.description)
feed.push({ subtitle: options.description });
/**************************************************************************
* "feed" node: optional elements
*************************************************************************/
if(options.description)
feed.push({ subtitle: options.description });
if(options.image)
feed.push({ logo: options.image });
if(options.image)
feed.push({ logo: options.image });
if(options.copyright)
feed.push({ rights: options.copyright });
if(options.copyright)
feed.push({ rights: options.copyright });
feed.push({ generator: generatorName });
feed.push({ generator: generatorName });
// Looping through categories (if any set!)
for(var key in categories) {
feed.push({ category: [{ _attr: { term: categories[key]}}] });
}
// Looping through categories (if any set!)
for(var i in categories)
feed.push({ category: [{ _attr: { term: categories[i] } }] });
// contributor
// icon
// contributor
// icon
/**************************************************************************
* "entry" nodes
*************************************************************************/
for(key in entries) {
//
// entry: required elements
//
var entry = [
{ title: { _cdata: entries[key].title }},
{ id: entries[key].link },
{ updated: RFC3339(entries[key].date) }
];
/**************************************************************************
* "entry" nodes
*************************************************************************/
for(var i in entries) {
//
// entry: required elements
//
var entry = [
{ title: { _attr: { type: 'html' }, _cdata: entries[i].title }},
{ id: entries[i].link },
{ link: [{ _attr: { href: entries[i].link } }]},
{ updated: RFC3339(entries[i].date) }
];
//
// entry: recommended elements
//
if(entries[key].description)
entry.push({ summary: { _cdata: entries[key].description }});
//
// entry: recommended elements
//
if(entries[i].description)
entry.push({ summary: { _attr: { type: 'html' }, _cdata: entries[i].description }});
// author
// entry author(s)
if(entries[i].author) {
for(var y in entries[i].author) {
var entryAuthor = [];
// content
if(entries[i].author[y].name)
entryAuthor.push({ name: entries[i].author[y].name });
// link - relative link to article
if(entries[i].author[y].email)
entryAuthor.push({ email: entries[i].author[y].email });
//
// entry: optional elements
//
if(entries[i].author[y].link)
entryAuthor.push({ uri: entries[i].author[y].link });
// category
entry.push({ author: entryAuthor });
}
}
// contributor
// content
// published
// link - relative link to article
// source
//
// entry: optional elements
//
// rights
// category
feed.push({ entry: entry });
}
// contributor
return doctype + xml(container, true);
// published
// source
// rights
feed.push({ entry: entry });
}
return doctype + xml(container, true);
}

@@ -172,66 +188,84 @@

function rss_2_0(options) {
var items = [],
channel = [],
container = [];
var items = options.items;
var categories = options.categories;
var author = options.author;
var d = new Date();
var items = [],
channel = [],
container = [];
var items = options.items;
var categories = options.categories;
var author = options.author;
var d = new Date();
var doctype = '<?xml version="1.0" encoding="utf-8"?>\n';
var doctype = '<?xml version="1.0" encoding="utf-8"?>\n';
container.push({ rss: [] });
container[0].rss.push({ _attr: { version: '2.0' } });
container[0].rss.push({ channel: channel });
container.push({ rss: [] });
container[0].rss.push({ _attr: { version: '2.0' } });
container[0].rss.push({ channel: channel });
// Required RSS 2.0 channel elements
channel.push({ title: options.title });
channel.push({ description: options.description });
channel.push({ link: options.link });
channel.push({ author: author.email + ' (' + author.name + ')' });
channel.push({ lastBuildDate: d.toUTCString() })
// Required RSS 2.0 channel elements
channel.push({ title: options.title });
channel.push({ description: options.description });
channel.push({ link: options.link });
channel.push({ author: author.email + ' (' + author.name + ')' });
channel.push({ lastBuildDate: d.toUTCString() })
if(options.image)
channel.push({ image: options.image });
if(options.image)
channel.push({ image: options.image });
if(options.copyright)
channel.push({ copyright: options.copyright });
channel.push({ generator: generatorName });
if(options.copyright)
channel.push({ copyright: options.copyright });
channel.push({ generator: generatorName });
// Categories
for(var key in categories) {
channel.push({ category: categories[key] });
}
// Categories
for(var i in categories)
channel.push({ category: categories[i] });
// Items
for(var key in items) {
var item = [
{ title: { _cdata: items[key].title }},
{ link: items[key].link },
{ pubDate: items[key].date.toUTCString() },
{ description: { _cdata: items[key].description }}
];
// Items
for(var i in items) {
var item = [
{ title: { _cdata: items[i].title }},
{ link: items[i].link },
{ pubDate: items[i].date.toUTCString() },
{ description: { _cdata: items[i].description }}
];
if(items[key].image)
item.push({ enclosure: [{ _attr: { url: items[key].image } }] });
if(items[i].author) {
for(var y in items[i].author) {
var itemAuthor = [];
channel.push({ item: item });
}
if(items[i].author[y].name)
itemAuthor.push({ name: items[i].author[y].name });
return doctype + xml(container, true);
if(items[i].author[y].email)
itemAuthor.push({ email: items[i].author[y].email });
if(items[i].author[y].link)
itemAuthor.push({ link: items[i].author[y].link });
item.push({ author: itemAuthor });
}
}
if(items[i].image)
item.push({ enclosure: [{ _attr: { url: items[i].image } }] });
channel.push({ item: item });
}
console.log(container[0].rss[1].channel[9]);
return doctype + xml(container, true);
}
function RFC3339(d) {
function pad(n) { return n < 10 ? '0' + n : n }
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z'
function pad(n) { return n < 10 ? '0' + n : n }
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z'
}
module.exports = Feed;
{
"name": "feed",
"version": "0.2.0",
"description": "Feed is a RSS and Atom feed generator for Node.js, making content syndication simple, intuitive and performant!",
"homepage": "http://projets.jpmonette.net/en/feed",
"author": "Jean-Philippe Monette <contact@jpmonette.net>",
"name": "feed",
"version": "0.2.1",
"description": "Feed is a RSS and Atom feed generator for Node.js, making content syndication simple, intuitive and performant!",
"homepage": "http://projets.jpmonette.net/en/feed",
"author": "Jean-Philippe Monette <contact@jpmonette.net>",
"license": "MIT",
"main": "lib/feed.js",
"main": "lib/feed.js",
"keywords": [
"rss",
"atom",
"feed",
"syndication",
"xml",
"wrapper",
"blog"
],
"dependencies": {
"xml": ">= 0.0.5"
},
"keywords": [
"rss",
"atom",
"feed",
"syndication",
"xml",
"wrapper",
"blog"
],
"dependencies": {
"xml": ">= 0.0.5"
},
"engines": {
"node": ">=0.4.0"
},
"engines": {
"node": ">=0.4.0"
},
"bugs": {
"url": "https://github.com/jpmonette/feed/issues"
},
"bugs": {
"url": "https://github.com/jpmonette/feed/issues"
},
"os" :[],
"cpu" : [],
"os" :[],
"cpu" : [],
"repository": {
"type": "git",
"url": "https://github.com/jpmonette/feed.git"
}
"repository": {
"type": "git",
"url": "https://github.com/jpmonette/feed.git"
}
}

@@ -51,2 +51,14 @@ # Feed for Node.js

description: posts[key].description,
author: [
{
name: 'Jane Doe',
email: 'janedoe@example.com',
link: 'https://example.com/janedoe'
},
{
name: 'Joe Smith',
email: 'joesmith@example.com',
link: 'https://example.com/joesmith'
}
],
date: posts[key].date,

@@ -58,2 +70,8 @@ image: posts[key].image

Insert categories using:
```
feed.category('Technologie');
```
Output a RSS 2.0 feed:

@@ -60,0 +78,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc