Skip to content

Commit

Permalink
Refactor code to es6
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnowack committed Jan 19, 2018
1 parent 082413f commit 331d393
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 231 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ node_js:
- "node"
- "8"
- "6"
- "4"
24 changes: 0 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"build": "babel src -d dist",
"generate": "babel-node generate.js",
"clean": "rm -rf dist",
"test": "npm run lint && ava"
"test": "npm run lint && npm run build && ava"
},
"files": [
"src/index.js"
"src/*"
],
"licenses": [
{
Expand Down Expand Up @@ -47,7 +47,7 @@
"env",
{
"targets": {
"node": "4.8.7"
"node": "6.12.3"
}
}
]
Expand All @@ -57,7 +57,11 @@
"extends": [
"airbnb-base"
],
"parser": "babel-eslint"
"parser": "babel-eslint",
"rules": {
"import/no-named-as-default": "off",
"import/no-named-as-default-member": "off"
}
},
"dependencies": {
"rss": "^1.2.2"
Expand All @@ -72,7 +76,6 @@
"eslint-plugin-babel": "^4.1.2",
"eslint-plugin-import": "^2.8.0",
"include-folder": "^1.0.0",
"mockdate": "^2.0.2",
"xml2js": "^0.4.1"
"mockdate": "^2.0.2"
}
}
43 changes: 17 additions & 26 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
### Create a new feed

```js
var Podcast = require('podcast');
import Podcast from 'podcast';

var feed = new Podcast(feedOptions);
const feed = new Podcast(feedOptions);
```

#### `feedOptions`

* `title` **string** Title of your site or feed
* `description` _optional_ **string** A short description of the feed.
* `generator` _optional_ **string** Feed generator.
* `feed_url` **url string** Url to the rss feed.
* `site_url` **url string** Url to the site that the feed is for.
* `image_url` _optional_ **url string* Small image for feed readers to use.
* `feedUrl` **url string** Url to the rss feed.
* `siteUrl` **url string** Url to the site that the feed is for.
* `imageUrl` _optional_ **url string* Small image for feed readers to use.
* `docs` _optional_ **url string** Url to documentation on this feed.
* `author` **string** Who owns this feed.
* `managingEditor` _optional_ **string** Who manages content in this feed.
Expand All @@ -40,14 +40,16 @@ var feed = new Podcast(feedOptions);
* `itunesExplicit` _optional_ **boolean** (iTunes specific) specifies if the podcast contains explicit content
* `itunesCategory` _optional_ **array of objects** (iTunes specific) Categories for iTunes ( [{text:String, subcats:[{text:String, subcats:Array}]}] )
* `itunesImage` _optional_ **string** (iTunes specific) link to an image for the podcast
* `customNamespaces` _optional_ **object** Put additional namespaces in <rss> element (without 'xmlns:' prefix)
* `customElements` _optional_ **array** Put additional elements in the feed (node-xml syntax)

### Add items to a feed

An item can be used for a blog entry, project update, log entry, etc. Your RSS feed
an have any number of items. Most feeds use 20 or fewer items.

```js
feed.item(itemOptions);
feed.addItem(itemOptions);
```

#### itemOptions
Expand All @@ -73,20 +75,21 @@ feed.item(itemOptions);
information.
* `size` _optional_ **number** Number of bytes in the file. The length field will defualt to 0 if the
`size` or `file` fields have not been set.
* `mime` _optional_ **string** Mime type of the file. Will be guessed from the url if this parameter is
* `type` _optional_ **string** Mime type of the file. Will be guessed from the url if this parameter is
not set.
* `itunesAuthor` _optional_ **string** (iTunes specific) author of the podcast
* `itunesExplicit` _optional_ **boolean** (iTunes specific) specifies if the podcast contains explicit content
* `itunesSubtitle` _optional_ **string** (iTunes specific) subtitle for iTunes listing
* `itunesSummary` _optional_ **string** (iTunes specific) summary for iTunes listing
* `itunesDuration` _optional_ **number** (iTunes specific) duration of the podcast item in seconds
* `itunesKeywords` _optional_ **array of string** (iTunes specific) keywords of the podcast
* `itunesKeywords` _optional_ **array of strings** (iTunes specific) keywords of the podcast
* `itunesImage` _optional_ **string** (iTunes specific) link to an image for the item
* `customElements` _optional_ **array** Put additional elements in the item (node-xml syntax)

#### Feed XML

```js
var xml = feed.xml(indent);
const xml = feed.xml(indent);
```

This returns the XML as a string.
Expand All @@ -97,10 +100,10 @@ This returns the XML as a string.
## Example Usage

```js
var Podcast = require('podcast');
import Podcast from 'podcast';

/* lets create an rss feed */
var feed = new Podcast({
const feed = new Podcast({
title: 'title',
description: 'description',
feed_url: 'http://example.com/rss.xml',
Expand Down Expand Up @@ -130,7 +133,7 @@ var feed = new Podcast({
});

/* loop over data and add to feed */
feed.item({
feed.addItem({
title: 'item title',
description: 'use this for the content. It can include html.',
url: 'http://example.com/article4?this&that', // link to the item
Expand All @@ -150,26 +153,14 @@ feed.item({
});

// cache the xml to send to clients
var xml = feed.xml();
const xml = feed.xml();
```

## Tests

Tests included use Mocha. Use `npm test` to run the tests.

$ npm test

## Notes
* You do not need to escape anything. This module will escape characters when necessary.
* This module is very fast but you might as well cache the output of xml() and serve
it until something changes.

# History

I started this module over two years ago (April 2011) because there weren't any Node modules
for creating RSS. Besides these [25 modules](https://npmjs.org/browse/depended/rss)
I would love to know what other projects are using it.

# Contributing

Contributions to the project are welcome. Feel free to fork and improve.
Expand All @@ -180,7 +171,7 @@ are included.

(The MIT License)

Copyright (c) 2011-2013 Dylan Greene <[email protected]>
Copyright (c) 2013-2017 Max Nowack <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
22 changes: 22 additions & 0 deletions src/buildiTunesCategories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function buildiTunesCategories(categories) {
const arr = [];
if (Array.isArray(categories)) {
categories.forEach((category) => {
if (category.subcats) {
const elements = [
{ _attr: { text: category.text } },
];
const cats = buildiTunesCategories(category.subcats);
cats.forEach((cat) => {
elements.push(cat);
});
arr.push({ 'itunes:category': elements });
} else {
arr.push({ 'itunes:category': { _attr: { text: category.text } } });
}
});
}
return arr;
}

export default buildiTunesCategories;
52 changes: 52 additions & 0 deletions src/deprecate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const warnedPositions = {};

function deprecate({
type,
name,
version,
alternative,
}) {
const stack = new Error().stack || '';
let at = (stack.match(/(?:\s+at\s.+){2}\s+at\s(.+)/) || [undefined, ''])[1];

if (/\)$/.test(at)) {
[at] = at.match(/[^(]+(?=\)$)/);
} else {
at = at.trim();
}
if (at in warnedPositions) {
return;
}
warnedPositions[at] = true;
let message;
switch (type) {
case 'class':
message = 'Class';
break;
case 'property':
message = 'Property';
break;
case 'method':
message = 'Method';
break;
case 'function':
message = 'Function';
break;
default: message = '';
}
message += ` \`${name}\` has been deprecated`;
if (version) {
message += ` since version ${version}`;
}
if (alternative) {
message += `, use \`${alternative}\` instead`;
}
message += '.';
if (at) {
message += `\n at ${at}`;
}

console.warn(message); // eslint-disable-line no-console
}

export default deprecate;
Loading

0 comments on commit 331d393

Please sign in to comment.