Skip to content

Commit

Permalink
Namespace for apple (#9)
Browse files Browse the repository at this point in the history
* update channel meta tags

* channel tag

* update channel tag

* include function for creating owner info

* fix errors

* for apple namespace

* remove deprecated code

* refine logic

* eslint config for spread

* return obj in function

* updating
  • Loading branch information
markerberg authored and yuliy committed Sep 7, 2018
1 parent 88b1e89 commit 72fd39b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
27 changes: 22 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,41 @@ function feedMetaTags({ title, description, link, copyright, generator, docs, op
};
}

/**
* Remove falsy values from an object
*
* @param {Object} obj
* @returns {Object}
*/
function cleanNullValues(obj) {
for (let propName in obj) {
if (!obj[propName]) {
delete obj[propName];
}
}

return obj;
}

/**
* Wraps content in top level RSS and Channel tags
*
* @param {Array} data
* @param {Object} attr
* @return {Object}
*/
function wrapInTopLevel(data, attr) {
const defaultAttr = {
function wrapInTopLevel(data, attr = {}) {
const defaultNamespaces = {
version: '2.0',
'xmlns:content': 'http://purl.org/rss/1.0/modules/content/',
'xmlns:media': 'http://search.yahoo.com/mrss/',
'xmlns:mi': 'http://schemas.ingestion.microsoft.com/common/',
'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
'xmlns:mi': 'http://schemas.ingestion.microsoft.com/common/'
'xmlns:media': 'http://search.yahoo.com/mrss/'
};

return {
rss: [{
_attr: Object.assign(defaultAttr, attr)
_attr: cleanNullValues(Object.assign(defaultNamespaces, attr))
}, {
channel: data
}]
Expand Down Expand Up @@ -144,4 +160,5 @@ module.exports.wrapInItem = wrapInItem;
module.exports.wrapInTopLevel = wrapInTopLevel;
module.exports.feedMetaTags = feedMetaTags;
module.exports.elevateCategory = elevateCategory;
module.exports.cleanNullValues = cleanNullValues;
module.exports.setLog = (fake) => log = fake;
9 changes: 9 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ describe(_.startCase(filename), function () {
});
});

describe('cleanNullValues', function () {
const fn = lib[this.title];

it('filters out falsy values from an object', function () {
expect(fn({ foo: 'bar', baz: false, barbaz: null, bazfoo: undefined, foobaz: ''}))
.to.eql({ foo: 'bar' });
});
});

describe('wrapInTopLevel', function () {
const fn = lib[this.title],
val = fn('foo'),
Expand Down

0 comments on commit 72fd39b

Please sign in to comment.