Skip to content

Commit ccdf0e8

Browse files
authored
Merge pull request #18 from ndaidong/refactor
v3.0.0
2 parents 774fa9a + c80bda0 commit ccdf0e8

36 files changed

+839
-1170
lines changed

.coveralls.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/ci-test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# GitHub actions
2+
# https://docs.github.com/en/free-pro-team@latest/actions
3+
4+
name: ci-test
5+
6+
on: [push, pull_request]
7+
8+
jobs:
9+
test:
10+
11+
runs-on: ubuntu-20.04
12+
13+
strategy:
14+
matrix:
15+
node_version: [10.14.2, 14.x, 15.x, 16.x, 17.x]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: setup Node.js v${{ matrix.node_version }}
21+
uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node_version }}
24+
25+
- name: run npm scripts
26+
run: |
27+
npm i -g standard
28+
npm install
29+
npm run lint
30+
npm run build --if-present
31+
npm run test
32+
33+
- name: sync to coveralls
34+
uses: coverallsapp/github-action@v1.1.2
35+
with:
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: cache node modules
39+
uses: actions/cache@v2
40+
with:
41+
path: ~/.npm
42+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
43+
restore-keys: |
44+
${{ runner.os }}-node-
45+
46+
47+

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 72 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,99 @@
11
# feed-reader
2-
A node package for handling ATOM/RSS resources and normalize to JSON object.
2+
3+
Parse RSS/ATOM data from given feed url.
34

45
[![NPM](https://badge.fury.io/js/feed-reader.svg)](https://badge.fury.io/js/feed-reader)
5-
[![Build Status](https://travis-ci.org/ndaidong/feed-reader.svg?branch=master)](https://travis-ci.org/ndaidong/feed-reader)
6-
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/feed-reader/badge.svg?branch=master)](https://coveralls.io/github/ndaidong/feed-reader?branch=master)
7-
![Dependency Status](https://david-dm.org/ndaidong/feed-reader.svg)
8-
[![NSP Status](https://nodesecurity.io/orgs/techpush/projects/e42b6eb4-f3ef-4a91-84d9-86f6dfa245a6/badge)](https://nodesecurity.io/orgs/techpush/projects/e42b6eb4-f3ef-4a91-84d9-86f6dfa245a6)
6+
![CI test](https://github.com/ndaidong/feed-reader/workflows/ci-test/badge.svg)
7+
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/feed-reader/badge.svg)](https://coveralls.io/github/ndaidong/feed-reader)
8+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ndaidong_feed-reader&metric=alert_status)](https://sonarcloud.io/dashboard?id=ndaidong_feed-reader)
9+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
910

10-
### API & Usage
1111

12-
```
12+
### Usage
13+
14+
```bash
1315
npm install feed-reader
1416
```
1517

16-
This module provides only one method:
18+
Then
1719

18-
- .parse(String feedURL)
20+
```js
21+
const {
22+
parse
23+
} = require('feed-reader')
1924

20-
In which, feedURL is the url to RSS or ATOM resource.
25+
const url = 'https://news.google.com/rss'
2126

22-
For example:
23-
24-
```
25-
var reader = require('feed-reader');
26-
reader.parse(SOME_RSS_URL);
27+
parse(url).then((feed) => {
28+
console.log(feed)
29+
}).catch((err) => {
30+
console.log(err)
31+
})
2732
```
2833

29-
Result is a Promise. View the example below for more detail:
34+
## APIs
3035

31-
```
32-
var parse = require('feed-reader').parse;
36+
This lib provides only method `parse()`.
3337

34-
let url = 'https://news.google.com/news/feeds?pz=1&cf=all&ned=us&hl=en&q=nodejs&output=rss';
38+
#### parse(String url)
3539

36-
parse(url).then((feed) => {
37-
console.log(feed);
38-
}).catch((err) => {
39-
console.log(err);
40-
}).finally(() => {
41-
console.log('Everything done');
42-
});
40+
Return: a Promise
41+
42+
Here is how we can use `feed-reader`:
43+
44+
```js
45+
import {
46+
parse
47+
} from 'feed-reader'
48+
49+
const getFeedData = async (url) => {
50+
try {
51+
console.log(`Get feed data from ${url}`)
52+
const data = await parse(url)
53+
console.log(data)
54+
return data
55+
} catch (err) {
56+
console.trace(err)
57+
}
58+
}
59+
60+
getFeedData('https://news.google.com/rss')
61+
getFeedData('https://news.google.com/atom')
62+
```
63+
64+
Example feed data:
65+
66+
```json
67+
{
68+
"title": "Top stories - Google News",
69+
"link": "https://news.google.com/atom?hl=en-US&gl=US&ceid=US%3Aen",
70+
"description": "Google News",
71+
"generator": "NFE/5.0",
72+
"language": "",
73+
"updated": "Tue, Nov 23, 2021 05:58:17 PM",
74+
"entries": [
75+
{
76+
"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",
77+
"link": "https://news.google.com/__i/rss/rd/articles/CBMiTmh0dHBzOi8vd3d3LmNubi5jb20vMjAyMS8xMS8yMy91cy93YXVrZXNoYS1jYXItcGFyYWRlLWNyb3dkLXR1ZXNkYXkvaW5kZXguaHRtbNIBUmh0dHBzOi8vYW1wLmNubi5jb20vY25uLzIwMjEvMTEvMjMvdXMvd2F1a2VzaGEtY2FyLXBhcmFkZS1jcm93ZC10dWVzZGF5L2luZGV4Lmh0bWw?oc=5",
78+
"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...",
79+
"pubDate": "Tue, Nov 23, 2021 05:34:00 PM"
80+
},
81+
// ...
82+
]
83+
}
4384
```
4485

4586

4687
## Test
4788

48-
```
89+
90+
```bash
4991
git clone https://github.com/ndaidong/feed-reader.git
5092
cd feed-reader
5193
npm install
94+
95+
# evaluation
96+
npm run eval https://news.google.com/rss
5297
npm test
5398
```
5499

index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Type definitions
2+
3+
export function parse(url: string): Promise<FeedData>;
4+
5+
6+
export interface FeedData {
7+
link?: string;
8+
title?: string;
9+
description?: string;
10+
generator?: string;
11+
language?: string;
12+
updated?: date;
13+
entries?: array;
14+
}

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
* Starting app
33
* @ndaidong
44
**/
5-
exports = module.exports = require('./src/main');
6-
exports.version = require('./package').version;
5+
6+
const main = require('./src/main')
7+
main.version = require('./package.json').version
8+
9+
module.exports = main

package.json

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,35 @@
11
{
2-
"version": "1.1.6",
2+
"version": "3.0.0",
33
"name": "feed-reader",
4-
"description": "Handle ATOM and RSS feed",
4+
"description": "Parse ATOM/RSS data from given feed url",
55
"homepage": "https://www.npmjs.com/package/feed-reader",
66
"repository": {
77
"type": "git",
8-
"url": "https://github.com/ndaidong/feed-reader"
8+
"url": "git@github.com:ndaidong/feed-reader.git"
99
},
1010
"author": "@ndaidong",
1111
"main": "./index.js",
12+
"types": "./index.d.ts",
1213
"engines": {
13-
"node": ">= 6.0"
14+
"node": ">= 10.14.2"
1415
},
1516
"scripts": {
16-
"lint": "eslint .",
17-
"nsp": "nsp check --output checkstyle",
18-
"tape": "nyc tape test/start.js | tap-spec",
19-
"report": "nyc report --reporter=lcov",
20-
"pretest": "npm run lint && npm run nsp",
21-
"test": "npm run tape",
22-
"posttest": "npm run report",
23-
"coveralls": "npm test && cat ./coverage/lcov.info | coveralls",
17+
"lint": "standard .",
18+
"pretest": "npm run lint",
19+
"test": "jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles",
20+
"eval": "DEBUG=*:* node run",
2421
"reset": "node reset"
2522
},
2623
"dependencies": {
27-
"bella-date": "^1.1.2",
28-
"bellajs": "^7.2.0",
29-
"friendly-xml": "^1.0.2",
30-
"html-entities": "^1.2.1",
31-
"node-fetch": "^2.1.2",
32-
"promise-wtf": "^1.2.4",
33-
"xml2json": "^0.11.2"
24+
"bellajs": "^9.3.0",
25+
"debug": "^4.3.2",
26+
"fast-xml-parser": "^4.0.0-beta.2",
27+
"got": "^11.8.3",
28+
"html-entities": "^2.3.2"
3429
},
3530
"devDependencies": {
36-
"debug": "^3.1.0",
37-
"coveralls": "^3.0.0",
38-
"eslint": "^4.19.1",
39-
"eslint-config-goes": "^1.0.0",
40-
"nock": "^9.2.3",
41-
"nsp": "^3.2.1",
42-
"nyc": "^11.6.0",
43-
"tap-spec": "^4.1.1",
44-
"tape": "^4.9.0"
31+
"jest": "^27.3.1",
32+
"nock": "^13.1.4"
4533
},
4634
"keywords": [
4735
"extractor",

reset.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@
22

33
const {
44
existsSync,
5-
unlinkSync,
6-
} = require('fs');
5+
unlinkSync
6+
} = require('fs')
77

8-
const exec = require('child_process').execSync;
8+
const { execSync } = require('child_process')
99

1010
const dirs = [
11+
'dist',
12+
'docs',
1113
'.nyc_output',
1214
'coverage',
1315
'node_modules',
14-
];
16+
'.nuxt'
17+
]
1518

1619
const files = [
1720
'yarn.lock',
21+
'pnpm-lock.yaml',
1822
'package-lock.json',
19-
'coverage.lcov',
20-
];
23+
'coverage.lcov'
24+
]
2125

2226
dirs.forEach((d) => {
23-
exec(`rm -rf ${d}`);
24-
});
27+
execSync(`rm -rf ${d}`)
28+
})
2529

2630
files.forEach((f) => {
2731
if (existsSync(f)) {
28-
unlinkSync(f);
32+
unlinkSync(f)
2933
}
30-
});
34+
})

0 commit comments

Comments
 (0)