From 8023a934f5b299fe2d0dd7ae42d0b2b17b7b56f5 Mon Sep 17 00:00:00 2001 From: Dong Nguyen Date: Thu, 28 Jul 2022 17:42:40 +0700 Subject: [PATCH] v6.0.0rc4 - Add default value to all keys --- README.md | 2 +- dist/cjs/feed-reader.js | 82 ++++++++++++++++++++------------------ dist/cjs/package.json | 2 +- package.json | 6 +-- src/utils/normalizer.js | 2 +- src/utils/parseAtomFeed.js | 32 ++++++++------- src/utils/parseJsonFeed.js | 29 ++++++++------ src/utils/parseRssFeed.js | 25 +++++++----- 8 files changed, 97 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index dd7fb94..d7051a8 100755 --- a/README.md +++ b/README.md @@ -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) diff --git a/dist/cjs/feed-reader.js b/dist/cjs/feed-reader.js index aab60de..e76281a 100644 --- a/dist/cjs/feed-reader.js +++ b/dist/cjs/feed-reader.js @@ -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; @@ -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 = { @@ -14641,6 +14637,10 @@ var parseJson = (data) => { items: item = [] } = data; const items = (0, import_bellajs5.isArray)(item) ? item : [item]; + const { + includeFullContent, + convertPubDateToISO + } = getReaderOptions(); return { title, link: homepageUrl, @@ -14648,7 +14648,9 @@ var parseJson = (data) => { language, published: "", generator: "", - entries: items.map(transform) + entries: items.map((item2) => { + return transform(item2, includeFullContent, convertPubDateToISO); + }) }; }; var parseJsonFeed_default = (data) => { @@ -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 = { @@ -14691,6 +14689,10 @@ var parseRss = (data) => { item = [] } = data.rss.channel; const items = (0, import_bellajs6.isArray)(item) ? item : [item]; + const { + includeFullContent, + convertPubDateToISO + } = getReaderOptions(); return { title, link, @@ -14698,7 +14700,9 @@ var parseRss = (data) => { language, generator, published: toISODateString(lastBuildDate), - entries: items.map(transform2) + entries: items.map((item2) => { + return transform2(item2, includeFullContent, convertPubDateToISO); + }) }; }; var parseRssFeed_default = (data) => { @@ -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); @@ -14753,7 +14753,7 @@ var transform3 = (item) => { }; var parseAtom = (data) => { const { - id, + id = "", title = "", link = "", subtitle = "", @@ -14763,6 +14763,10 @@ 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), @@ -14770,7 +14774,9 @@ var parseAtom = (data) => { language, generator, published: toISODateString(updated), - entries: items.map(transform3) + entries: items.map((item2) => { + return transform3(item2, includeFullContent, convertPubDateToISO); + }) }; }; var parseAtomFeed_default = (data) => { diff --git a/dist/cjs/package.json b/dist/cjs/package.json index 6f52999..63e19c4 100644 --- a/dist/cjs/package.json +++ b/dist/cjs/package.json @@ -1,5 +1,5 @@ { "name": "feed-reader-cjs", - "version": "6.0.0rc3", + "version": "6.0.0rc4", "main": "./feed-reader.js" } \ No newline at end of file diff --git a/package.json b/package.json index 34e78ae..994b43e 100755 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/utils/normalizer.js b/src/utils/normalizer.js index 217650e..5fac219 100644 --- a/src/utils/normalizer.js +++ b/src/utils/normalizer.js @@ -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, ' ') } diff --git a/src/utils/parseAtomFeed.js b/src/utils/parseAtomFeed.js index 087b8b5..0194b4a 100644 --- a/src/utils/parseAtomFeed.js +++ b/src/utils/parseAtomFeed.js @@ -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 @@ -73,7 +68,7 @@ const transform = (item) => { const parseAtom = (data) => { const { - id, + id = '', title = '', link = '', subtitle = '', @@ -85,6 +80,11 @@ const parseAtom = (data) => { const items = isArray(item) ? item : [item] + const { + includeFullContent, + convertPubDateToISO + } = getReaderOptions() + return { title: getText(title), link: getLink(link, id), @@ -92,7 +92,9 @@ const parseAtom = (data) => { language, generator, published: toISODateString(updated), - entries: items.map(transform) + entries: items.map((item) => { + return transform(item, includeFullContent, convertPubDateToISO) + }) } } diff --git a/src/utils/parseJsonFeed.js b/src/utils/parseJsonFeed.js index 688ed77..3026cf6 100644 --- a/src/utils/parseJsonFeed.js +++ b/src/utils/parseJsonFeed.js @@ -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, @@ -50,6 +46,11 @@ const parseJson = (data) => { const items = isArray(item) ? item : [item] + const { + includeFullContent, + convertPubDateToISO + } = getReaderOptions() + return { title, link: homepageUrl, @@ -57,7 +58,9 @@ const parseJson = (data) => { language, published: '', generator: '', - entries: items.map(transform) + entries: items.map((item) => { + return transform(item, includeFullContent, convertPubDateToISO) + }) } } diff --git a/src/utils/parseRssFeed.js b/src/utils/parseRssFeed.js index b03a888..0313fc2 100644 --- a/src/utils/parseRssFeed.js +++ b/src/utils/parseRssFeed.js @@ -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), @@ -52,6 +48,11 @@ const parseRss = (data) => { const items = isArray(item) ? item : [item] + const { + includeFullContent, + convertPubDateToISO + } = getReaderOptions() + return { title, link, @@ -59,7 +60,9 @@ const parseRss = (data) => { language, generator, published: toISODateString(lastBuildDate), - entries: items.map(transform) + entries: items.map((item) => { + return transform(item, includeFullContent, convertPubDateToISO) + }) } }