Skip to content

Commit

Permalink
Merge pull request #22 from ndaidong/v4.0.0
Browse files Browse the repository at this point in the history
v4.0.0
  • Loading branch information
ndaidong authored Dec 23, 2021
2 parents 5618bd7 + c5c8506 commit c1f7dda
Show file tree
Hide file tree
Showing 27 changed files with 2,809 additions and 68 deletions.
Empty file modified .github/workflows/ci-test.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
55 changes: 40 additions & 15 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# feed-reader

Parse RSS/ATOM data from given feed url.
Load and parse RSS/ATOM data from given feed url.

[![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 All @@ -19,12 +19,12 @@ Then

```js
const {
parse
read
} = require('feed-reader')

const url = 'https://news.google.com/rss'

parse(url).then((feed) => {
read(url).then((feed) => {
console.log(feed)
}).catch((err) => {
console.log(err)
Expand All @@ -33,23 +33,24 @@ parse(url).then((feed) => {

## APIs

This lib provides only method `parse()`.
- [.read(String url)](#readstring-url)
- [Configuration methods](#configuration-methods)

#### parse(String url)
#### read(String url)

Return: a Promise
Load and extract feed data from given RSS/ATOM source. Return a Promise object.

Here is how we can use `feed-reader`:
Example:

```js
import {
parse
read
} from 'feed-reader'

const getFeedData = async (url) => {
try {
console.log(`Get feed data from ${url}`)
const data = await parse(url)
const data = await read(url)
console.log(data)
return data
} catch (err) {
Expand All @@ -61,7 +62,7 @@ getFeedData('https://news.google.com/rss')
getFeedData('https://news.google.com/atom')
```

Example feed data:
Feed data object retuned by `read()` method should look like below:

```json
{
Expand All @@ -70,19 +71,42 @@ Example feed data:
"description": "Google News",
"generator": "NFE/5.0",
"language": "",
"published": "Tue, Nov 23, 2021 05:58:17 PM",
"published": "2021-12-23T15:01:12.000Z",
"entries": [
{
"title": "Lone suspect in Waukesha parade crash to appear in court today, as Wisconsin reels from tragedy that left 5 dead and dozens more injured - CNN",
"link": "https://news.google.com/__i/rss/rd/articles/CBMiTmh0dHBzOi8vd3d3LmNubi5jb20vMjAyMS8xMS8yMy91cy93YXVrZXNoYS1jYXItcGFyYWRlLWNyb3dkLXR1ZXNkYXkvaW5kZXguaHRtbNIBUmh0dHBzOi8vYW1wLmNubi5jb20vY25uLzIwMjEvMTEvMjMvdXMvd2F1a2VzaGEtY2FyLXBhcmFkZS1jcm93ZC10dWVzZGF5L2luZGV4Lmh0bWw?oc=5",
"description": "Lone suspect in Waukesha parade crash to appear in court today, as Wisconsin reels from tragedy that left 5 dead and dozens more injured    CNN Waukesha Christmas parade attack: 5 dead, 48 injured, Darrell Brooks named as...",
"published": "Tue, Nov 23, 2021 05:34:00 PM"
"published": "2021-12-21T22:30:00.000Z"
},
// ...
]
}
```

#### Configuration methods

In addition, this lib provides some methods to customize default settings. Don't touch them unless you have reason to do that.

- getRequestOptions()
- setRequestOptions(Object requestOptions)

#### Object `requestOptions`:

```js
{
headers: {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0',
accept: 'text/html; charset=utf-8'
},
responseType: 'text',
responseEncoding: 'utf8',
timeout: 6e4,
maxRedirects: 3
}
```
Read [axios' request config](https://axios-http.com/docs/req_config) for more info.


## Test

Expand All @@ -92,12 +116,13 @@ git clone https://github.com/ndaidong/feed-reader.git
cd feed-reader
npm install

# evaluation
# quick evaluation
npm run eval https://news.google.com/rss
npm test
```


# License

## License
The MIT License (MIT)

---
6 changes: 3 additions & 3 deletions run.js → eval.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { readFileSync, writeFileSync, existsSync } = require('fs')

const isValidUrl = require('./src/utils/isValidUrl')
const { parse } = require('./index')
const { read } = require('./index')

const extractFromUrl = async (url) => {
try {
const art = await parse(url)
const art = await read(url)
console.log(art)
writeFileSync('./output.json', JSON.stringify(art), 'utf8')
} catch (err) {
Expand All @@ -16,7 +16,7 @@ const extractFromUrl = async (url) => {
const extractFromFile = async (fpath) => {
try {
const xml = readFileSync(fpath, 'utf8')
const art = await parse(xml)
const art = await read(xml)
console.log(art)
writeFileSync('./output.json', JSON.stringify(art), 'utf8')
} catch (err) {
Expand Down
Empty file modified index.d.ts
100644 → 100755
Empty file.
Empty file modified index.js
100644 → 100755
Empty file.
16 changes: 8 additions & 8 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "3.1.0",
"version": "4.0.0",
"name": "feed-reader",
"description": "Parse ATOM/RSS data from given feed url",
"description": "Load and parse ATOM/RSS data from given feed url",
"homepage": "https://www.npmjs.com/package/feed-reader",
"repository": {
"type": "git",
Expand All @@ -17,18 +17,18 @@
"lint": "standard .",
"pretest": "npm run lint",
"test": "jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles",
"eval": "DEBUG=*:* node run",
"eval": "DEBUG=*:* node eval",
"reset": "node reset"
},
"dependencies": {
"bellajs": "^9.3.0",
"debug": "^4.3.2",
"fast-xml-parser": "^4.0.0-beta.2",
"got": "^11.8.3",
"axios": "^0.24.0",
"bellajs": "^10.0.2",
"debug": "^4.3.3",
"fast-xml-parser": "^4.0.0-beta.8",
"html-entities": "^2.3.2"
},
"devDependencies": {
"jest": "^27.3.1",
"jest": "^27.4.5",
"nock": "^13.2.1"
},
"keywords": [
Expand Down
Loading

0 comments on commit c1f7dda

Please sign in to comment.