Giter Site home page Giter Site logo

a7ul / rss-parser-browser Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 3.0 1.21 MB

A simple, light-weight RSS parser for browser. Parse strings, URLs and get a JS object back

License: MIT License

JavaScript 100.00%
rss rss-reader browser rss-parser npm openlibrary

rss-parser-browser's Introduction

rss-parser-browser

Build Status

This is a direct clone from https://github.com/bobby-brennan/rss-parser

I have removed the node dependencies so that it works with webpack in browser.

All credits should go to bobby-brennan.

Installation

You can install via npm:

npm install --save rss-parser-browser
# or
yarn add rss-parser-browser

Usage

You can parse RSS from a URL or a string.

  • parseString(xml, [options,], callback)

  • parseURL(url, [options,] callback)

Output

Check out the full output format in test/output/reddit.json

Notes:
  • The dc: prefix will be removed from all fields
  • Both dc:date and pubDate will be available in ISO 8601 format as isoDate
  • If author is specified, but not dc:creator, creator will be set to author (see article)

Usage

var parser = require('rss-parser-browser');

parser.parseURL('https://www.reddit.com/.rss', function(err, parsed) {
  console.log(parsed.feed.title);
  parsed.feed.entries.forEach(function(entry) {
    console.log(entry.title + ':' + entry.link);
  })
})

Redirects

By default, parseURL will follow up to one redirect. You can change this with options.maxRedirects.

parser.parseURL('https://reddit.com/.rss', {maxRedirects: 3}, function(err, parsed) {
  console.log(parsed.feed.title);
});

Custom Fields

If your RSS feed contains fields that aren't currently returned, you can access them using the customFields option.

var options = {
  customFields: {
    feed: ['otherTitle', 'extendedDescription'],
    item: ['coAuthor','subtitle'],
  }
}
parser.parseURL('https://www.reddit.com/.rss', options, function(err, parsed) {
  console.log(parsed.feed.extendedDescription);

  parsed.feed.entries.forEach(function(entry) {
    console.log(entry.coAuthor + ':' + entry.subtitle);
  })
})

To rename fields, you can pass in an array with two items, in the format [fromField, toField]:

var options = {
  customFields: {
    item: [
      ['dc:coAuthor', 'coAuthor'],
    ]
  }
}

Contributing

Contributions welcome!

Running Tests

The tests run the RSS parser for several sample RSS feeds in test/input and outputs the resulting JSON into test/output. If there are any changes to the output files the tests will fail.

To check if your changes affect the output of any test cases, run

npm test

To update the output files with your changes, run

WRITE_GOLDEN=true npm test

Publishing Releases

# change version in package.json
grunt build
git commit -a -m "vX.X.X"
git tag vX.X.X
npm publish
git push --follow-tags

rss-parser-browser's People

Contributors

a7ul avatar briri avatar cbreish avatar jbjorge avatar joshbeckman avatar krazyjakee avatar manuel-di-iorio avatar rbren avatar rub1e avatar vivekiran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rss-parser-browser's Issues

Uncaught TypeError: Cannot read property 'channel' of undefined

Hi, I'm getting the below error in production. How to resolve this issue ?

When the URL is not found, I'm getting this error.

If the URL is not found, how can I handle this error?

Uncaught TypeError: Cannot read property 'channel' of undefined
at E (index.js:125)
at index.js:252
at n. (xml2js.js:489)
at n.a.emit (events.js:81)
at n.onclosetag (xml2js.js:447)
at v (sax.js:624)
at m (sax.js:629)
at V (sax.js:889)
at n.S [as write] (sax.js:1436)
at n.parseString (xml2js.js:508)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.