Skip to content

Commit

Permalink
Merge pull request #18 from ndaidong/refactor
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
ndaidong authored Nov 23, 2021
2 parents 774fa9a + c80bda0 commit ccdf0e8
Show file tree
Hide file tree
Showing 36 changed files with 839 additions and 1,170 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# GitHub actions
# https://docs.github.com/en/free-pro-team@latest/actions

name: ci-test

on: [push, pull_request]

jobs:
test:

runs-on: ubuntu-20.04

strategy:
matrix:
node_version: [10.14.2, 14.x, 15.x, 16.x, 17.x]

steps:
- uses: actions/checkout@v2

- name: setup Node.js v${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node_version }}

- name: run npm scripts
run: |
npm i -g standard
npm install
npm run lint
npm run build --if-present
npm run test
- name: sync to coveralls
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: cache node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

99 changes: 72 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,99 @@
# feed-reader
A node package for handling ATOM/RSS resources and normalize to JSON object.

Parse RSS/ATOM data from given feed url.

[![NPM](https://badge.fury.io/js/feed-reader.svg)](https://badge.fury.io/js/feed-reader)
[![Build Status](https://travis-ci.org/ndaidong/feed-reader.svg?branch=master)](https://travis-ci.org/ndaidong/feed-reader)
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/feed-reader/badge.svg?branch=master)](https://coveralls.io/github/ndaidong/feed-reader?branch=master)
![Dependency Status](https://david-dm.org/ndaidong/feed-reader.svg)
[![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)
![CI test](https://github.com/ndaidong/feed-reader/workflows/ci-test/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/feed-reader/badge.svg)](https://coveralls.io/github/ndaidong/feed-reader)
[![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)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

### API & Usage

```
### Usage

```bash
npm install feed-reader
```

This module provides only one method:
Then

- .parse(String feedURL)
```js
const {
parse
} = require('feed-reader')

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

For example:

```
var reader = require('feed-reader');
reader.parse(SOME_RSS_URL);
parse(url).then((feed) => {
console.log(feed)
}).catch((err) => {
console.log(err)
})
```

Result is a Promise. View the example below for more detail:
## APIs

```
var parse = require('feed-reader').parse;
This lib provides only method `parse()`.

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

parse(url).then((feed) => {
console.log(feed);
}).catch((err) => {
console.log(err);
}).finally(() => {
console.log('Everything done');
});
Return: a Promise

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

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

const getFeedData = async (url) => {
try {
console.log(`Get feed data from ${url}`)
const data = await parse(url)
console.log(data)
return data
} catch (err) {
console.trace(err)
}
}

getFeedData('https://news.google.com/rss')
getFeedData('https://news.google.com/atom')
```

Example feed data:

```json
{
"title": "Top stories - Google News",
"link": "https://news.google.com/atom?hl=en-US&gl=US&ceid=US%3Aen",
"description": "Google News",
"generator": "NFE/5.0",
"language": "",
"updated": "Tue, Nov 23, 2021 05:58:17 PM",
"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...",
"pubDate": "Tue, Nov 23, 2021 05:34:00 PM"
},
// ...
]
}
```


## Test

```

```bash
git clone https://github.com/ndaidong/feed-reader.git
cd feed-reader
npm install

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

Expand Down
14 changes: 14 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Type definitions

export function parse(url: string): Promise<FeedData>;


export interface FeedData {
link?: string;
title?: string;
description?: string;
generator?: string;
language?: string;
updated?: date;
entries?: array;
}
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
* Starting app
* @ndaidong
**/
exports = module.exports = require('./src/main');
exports.version = require('./package').version;

const main = require('./src/main')
main.version = require('./package.json').version

module.exports = main
44 changes: 16 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
{
"version": "1.1.6",
"version": "3.0.0",
"name": "feed-reader",
"description": "Handle ATOM and RSS feed",
"description": "Parse ATOM/RSS data from given feed url",
"homepage": "https://www.npmjs.com/package/feed-reader",
"repository": {
"type": "git",
"url": "https://github.com/ndaidong/feed-reader"
"url": "git@github.com:ndaidong/feed-reader.git"
},
"author": "@ndaidong",
"main": "./index.js",
"types": "./index.d.ts",
"engines": {
"node": ">= 6.0"
"node": ">= 10.14.2"
},
"scripts": {
"lint": "eslint .",
"nsp": "nsp check --output checkstyle",
"tape": "nyc tape test/start.js | tap-spec",
"report": "nyc report --reporter=lcov",
"pretest": "npm run lint && npm run nsp",
"test": "npm run tape",
"posttest": "npm run report",
"coveralls": "npm test && cat ./coverage/lcov.info | coveralls",
"lint": "standard .",
"pretest": "npm run lint",
"test": "jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles",
"eval": "DEBUG=*:* node run",
"reset": "node reset"
},
"dependencies": {
"bella-date": "^1.1.2",
"bellajs": "^7.2.0",
"friendly-xml": "^1.0.2",
"html-entities": "^1.2.1",
"node-fetch": "^2.1.2",
"promise-wtf": "^1.2.4",
"xml2json": "^0.11.2"
"bellajs": "^9.3.0",
"debug": "^4.3.2",
"fast-xml-parser": "^4.0.0-beta.2",
"got": "^11.8.3",
"html-entities": "^2.3.2"
},
"devDependencies": {
"debug": "^3.1.0",
"coveralls": "^3.0.0",
"eslint": "^4.19.1",
"eslint-config-goes": "^1.0.0",
"nock": "^9.2.3",
"nsp": "^3.2.1",
"nyc": "^11.6.0",
"tap-spec": "^4.1.1",
"tape": "^4.9.0"
"jest": "^27.3.1",
"nock": "^13.1.4"
},
"keywords": [
"extractor",
Expand Down
24 changes: 14 additions & 10 deletions reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@

const {
existsSync,
unlinkSync,
} = require('fs');
unlinkSync
} = require('fs')

const exec = require('child_process').execSync;
const { execSync } = require('child_process')

const dirs = [
'dist',
'docs',
'.nyc_output',
'coverage',
'node_modules',
];
'.nuxt'
]

const files = [
'yarn.lock',
'pnpm-lock.yaml',
'package-lock.json',
'coverage.lcov',
];
'coverage.lcov'
]

dirs.forEach((d) => {
exec(`rm -rf ${d}`);
});
execSync(`rm -rf ${d}`)
})

files.forEach((f) => {
if (existsSync(f)) {
unlinkSync(f);
unlinkSync(f)
}
});
})
36 changes: 36 additions & 0 deletions run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { readFileSync, writeFileSync, existsSync } = require('fs')

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

const extractFromUrl = async (url) => {
try {
const art = await parse(url)
console.log(art)
writeFileSync('./output.json', JSON.stringify(art), 'utf8')
} catch (err) {
console.trace(err)
}
}

const extractFromFile = async (fpath) => {
try {
const xml = readFileSync(fpath, 'utf8')
const art = await parse(xml)
console.log(art)
writeFileSync('./output.json', JSON.stringify(art), 'utf8')
} catch (err) {
console.trace(err)
}
}

const init = (argv) => {
if (argv.length === 3) {
const input = argv[2]
const isUrl = isValidUrl(input)
return isUrl ? extractFromUrl(input) : existsSync(input) ? extractFromFile(input) : false
}
return 'Nothing to do!'
}

init(process.argv)
Loading

0 comments on commit ccdf0e8

Please sign in to comment.