Skip to content

Commit

Permalink
Merge pull request #46 from ndaidong/v6.x.x
Browse files Browse the repository at this point in the history
v6.0.0rc4
  • Loading branch information
ndaidong authored Jul 28, 2022
2 parents 169981a + 8023a93 commit 3c6970f
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# feed-reader

Load and parse ATOM/RSS/JSON data from given feed url.
To read & normalize RSS/ATOM/JSON feed data.

[![NPM](https://badge.fury.io/js/feed-reader.svg)](https://badge.fury.io/js/feed-reader)
![CI test](https://github.com/ndaidong/feed-reader/workflows/ci-test/badge.svg)
Expand Down
82 changes: 44 additions & 38 deletions dist/cjs/feed-reader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// feed-reader@6.0.0rc3, by @ndaidong - built with esbuild at 2022-07-28T09:42:29.894Z - published under MIT license
// feed-reader@6.0.0rc4, by @ndaidong - built with esbuild at 2022-07-28T10:42:35.368Z - published under MIT license
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
Expand Down Expand Up @@ -14602,23 +14602,19 @@ var toISODateString = (dstr) => {
};
var buildDescription = (val) => {
const { descriptionMaxLen } = getReaderOptions();
const stripped = (0, import_bellajs4.stripTags)(val);
const stripped = (0, import_bellajs4.stripTags)(String(val));
return (0, import_bellajs4.truncate)(stripped, descriptionMaxLen).replace(/\n+/g, " ");
};

// src/utils/parseJsonFeed.js
var transform = (item) => {
var transform = (item, includeFullContent, convertPubDateToISO) => {
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions();
const {
title,
url: link,
date_published: pubDate,
summary,
content_html: htmlContent,
content_text: textContent
title = "",
url: link = "",
date_published: pubDate = "",
summary = "",
content_html: htmlContent = "",
content_text: textContent = ""
} = item;
const published = convertPubDateToISO ? toISODateString(pubDate) : pubDate;
const entry = {
Expand All @@ -14641,14 +14637,20 @@ var parseJson = (data) => {
items: item = []
} = data;
const items = (0, import_bellajs5.isArray)(item) ? item : [item];
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions();
return {
title,
link: homepageUrl,
description,
language,
published: "",
generator: "",
entries: items.map(transform)
entries: items.map((item2) => {
return transform(item2, includeFullContent, convertPubDateToISO);
})
};
};
var parseJsonFeed_default = (data) => {
Expand All @@ -14657,16 +14659,12 @@ var parseJsonFeed_default = (data) => {

// src/utils/parseRssFeed.js
var import_bellajs6 = __toESM(require_bella(), 1);
var transform2 = (item) => {
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions();
var transform2 = (item, includeFullContent, convertPubDateToISO) => {
const {
title,
link,
pubDate,
description
title = "",
link = "",
pubDate = "",
description = ""
} = item;
const published = convertPubDateToISO ? toISODateString(pubDate) : pubDate;
const entry = {
Expand All @@ -14691,14 +14689,20 @@ var parseRss = (data) => {
item = []
} = data.rss.channel;
const items = (0, import_bellajs6.isArray)(item) ? item : [item];
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions();
return {
title,
link,
description,
language,
generator,
published: toISODateString(lastBuildDate),
entries: items.map(transform2)
entries: items.map((item2) => {
return transform2(item2, includeFullContent, convertPubDateToISO);
})
};
};
var parseRssFeed_default = (data) => {
Expand All @@ -14724,19 +14728,15 @@ var getLink = (val = [], id = "") => {
};
return (0, import_bellajs7.isString)(val) ? getText(val) : (0, import_bellajs7.isObject)(val) && (0, import_bellajs7.hasProperty)(val, "href") ? getText(val.href) : (0, import_bellajs7.isObject)(val) && (0, import_bellajs7.hasProperty)(val, "@_href") ? getText(val["@_href"]) : (0, import_bellajs7.isObject)(val) && (0, import_bellajs7.hasProperty)(val, "_attributes") ? getText(val._attributes.href) : (0, import_bellajs7.isArray)(val) ? getEntryLink(val) : null;
};
var transform3 = (item) => {
var transform3 = (item, includeFullContent, convertPubDateToISO) => {
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions();
const {
id,
title,
updated,
published,
link,
summary,
content
id = "",
title = "",
updated = "",
published = "",
link = "",
summary = "",
content = ""
} = item;
const pubDate = updated || published;
const htmlContent = getText(content);
Expand All @@ -14753,7 +14753,7 @@ var transform3 = (item) => {
};
var parseAtom = (data) => {
const {
id,
id = "",
title = "",
link = "",
subtitle = "",
Expand All @@ -14763,14 +14763,20 @@ var parseAtom = (data) => {
entry: item = []
} = data.feed;
const items = (0, import_bellajs7.isArray)(item) ? item : [item];
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions();
return {
title: getText(title),
link: getLink(link, id),
description: subtitle,
language,
generator,
published: toISODateString(updated),
entries: items.map(transform3)
entries: items.map((item2) => {
return transform3(item2, includeFullContent, convertPubDateToISO);
})
};
};
var parseAtomFeed_default = (data) => {
Expand Down
2 changes: 1 addition & 1 deletion dist/cjs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "feed-reader-cjs",
"version": "6.0.0rc3",
"version": "6.0.0rc4",
"main": "./feed-reader.js"
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "6.0.0rc3",
"version": "6.0.0rc4",
"name": "feed-reader",
"description": "Load and parse ATOM/RSS data from given feed url",
"description": "To read and normalize RSS/ATOM/JSON feed data",
"homepage": "https://www.npmjs.com/package/feed-reader",
"repository": {
"type": "git",
Expand All @@ -17,7 +17,7 @@
"scripts": {
"lint": "standard .",
"pretest": "npm run lint",
"test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles",
"test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --verbose --coverage=true",
"build": "node build src/main.js",
"eval": "node eval",
"eval:cjs": "node cjs-eval",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/normalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export const toISODateString = (dstr) => {

export const buildDescription = (val) => {
const { descriptionMaxLen } = getReaderOptions()
const stripped = stripTags(val)
const stripped = stripTags(String(val))
return truncate(stripped, descriptionMaxLen).replace(/\n+/g, ' ')
}
32 changes: 17 additions & 15 deletions src/utils/parseAtomFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,15 @@ const getLink = (val = [], id = '') => {
: isArray(val) ? getEntryLink(val) : null
}

const transform = (item) => {
const transform = (item, includeFullContent, convertPubDateToISO) => {
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions()

const {
id,
title,
updated,
published,
link,
summary,
content
id = '',
title = '',
updated = '',
published = '',
link = '',
summary = '',
content = ''
} = item

const pubDate = updated || published
Expand All @@ -73,7 +68,7 @@ const transform = (item) => {

const parseAtom = (data) => {
const {
id,
id = '',
title = '',
link = '',
subtitle = '',
Expand All @@ -85,14 +80,21 @@ const parseAtom = (data) => {

const items = isArray(item) ? item : [item]

const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions()

return {
title: getText(title),
link: getLink(link, id),
description: subtitle,
language,
generator,
published: toISODateString(updated),
entries: items.map(transform)
entries: items.map((item) => {
return transform(item, includeFullContent, convertPubDateToISO)
})
}
}

Expand Down
29 changes: 16 additions & 13 deletions src/utils/parseJsonFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ import {

import { getReaderOptions } from '../config.js'

const transform = (item) => {
const transform = (item, includeFullContent, convertPubDateToISO) => {
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions()

const {
title,
url: link,
date_published: pubDate,
summary,
content_html: htmlContent,
content_text: textContent
title = '',
url: link = '',
date_published: pubDate = '',
summary = '',
content_html: htmlContent = '',
content_text: textContent = ''
} = item

const published = convertPubDateToISO ? toISODateString(pubDate) : pubDate

const entry = {
title,
link,
Expand All @@ -50,14 +46,21 @@ const parseJson = (data) => {

const items = isArray(item) ? item : [item]

const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions()

return {
title,
link: homepageUrl,
description,
language,
published: '',
generator: '',
entries: items.map(transform)
entries: items.map((item) => {
return transform(item, includeFullContent, convertPubDateToISO)
})
}
}

Expand Down
25 changes: 14 additions & 11 deletions src/utils/parseRssFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@ import { purify as purifyUrl } from './linker.js'

import { getReaderOptions } from '../config.js'

const transform = (item) => {
const transform = (item, includeFullContent, convertPubDateToISO) => {
const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions()

const {
title,
link,
pubDate,
description
title = '',
link = '',
pubDate = '',
description = ''
} = item

const published = convertPubDateToISO ? toISODateString(pubDate) : pubDate

const entry = {
title,
link: purifyUrl(link),
Expand All @@ -52,14 +48,21 @@ const parseRss = (data) => {

const items = isArray(item) ? item : [item]

const {
includeFullContent,
convertPubDateToISO
} = getReaderOptions()

return {
title,
link,
description,
language,
generator,
published: toISODateString(lastBuildDate),
entries: items.map(transform)
entries: items.map((item) => {
return transform(item, includeFullContent, convertPubDateToISO)
})
}
}

Expand Down

0 comments on commit 3c6970f

Please sign in to comment.