# feedme

> RSS/Atom/JSON feed parser

Latest version **2.0.2** (published 2020-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install feedme
pnpm add feedme
yarn add feedme
bun add feedme
```

## Health

**Score 33/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2020-12-11 |
| First published | 2011-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/feedme) |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 2 |
| Unpacked size | 36 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 166 |
| Author | fent |
| Maintainers | fent |
| Keywords | feed, rss, atom, json, parser |

## Links

- npm: https://www.npmjs.com/package/feedme
- Repository: https://github.com/fent/feedme.js
- Homepage: https://github.com/fent/feedme.js#readme
- Issues: https://github.com/fent/feedme.js/issues
- npm.io page: https://npm.io/package/feedme

## Dependencies (2)

- [sax](https://npm.io/package/sax.md) ^1.2.4
- [clarinet](https://npm.io/package/clarinet.md) ^0.12.4

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.2 (latest) — 2020-12-11
- 2.0.1 — 2020-11-22
- 2.0.0 — 2020-11-21
- 1.2.0 — 2018-02-25
- 1.1.2 — 2018-01-24
- 1.1.1 — 2018-01-12
- 1.1.0 — 2017-10-29
- 1.0.1 — 2017-08-10
- 1.0.0 — 2017-03-02
- 0.3.3 — 2016-12-05
- 0.3.2 — 2016-07-16
- 0.3.1 — 2016-07-16
- 0.3.0 — 2015-09-26
- 0.2.7 — 2013-08-25
- 0.2.6 — 2013-04-13
- … 11 more at https://npm.io/package/feedme/versions

## README

# FeedMe.js


feedme.js is an RSS/Atom/JSON feed parser. How is this different from the other few feed parsers? It uses [sax-js](https://github.com/isaacs/sax-js) for xml parsing and [clarinet](https://github.com/dscape/clarinet) for json parsing. That means it is coded in pure Javascript and thus more deployable. I needed a parser that wouldn't require me to install external dependencies or to compile anything.

![Depfu](https://img.shields.io/depfu/fent/feedme.js)
[![codecov](https://codecov.io/gh/fent/feedme.js/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/feedme.js)


# Usage

```js
const FeedMe = require('feedme');
const http = require('http');

http.get('http://www.npr.org/rss/rss.php?id=1001', (res) => {
  if (res.statusCode != 200) {
    console.error(new Error(`status code ${res.statusCode}`));
    return;
  }
  let parser = new FeedMe();
  parser.on('title', (title) => {
    console.log('title of feed is', title);
  });
  parser.on('item', (item) => {
    console.log();
    console.log('news:', item.title);
    console.log(item.description);
  });
  res.pipe(parser);
});
```


# API

### new FeedMe([buffer])
Creates a new instance of the FeedMe parser. `buffer` can be `true` if you want the parser to buffer the entire feed document as a JSON object, letting you use the `FeedMe#done()` method.

### parser.write(xml)
Write to the parser.

### parser.done()
Can only be used if `buffer` is `true`. It returns the feed as a Javascript object, should be called after `end` is emitted from the parser. Subelements are put as children objects with their names as keys. When one object has more than one child of the same name, they are put into an array. Items are always put into an array.

```js
const FeedMe = require('feedme');
const http = require('http');

http.get('https://nodejs.org/en/feed/blog.xml', (res) => {
  let parser = new FeedMe(true);
  res.pipe(parser);
  parser.on('finish', () => {
    console.log(parser.done());
  });
});
```

An example of what `parser.done()` could return.

```js
{
  type: 'rss 2.0',
  title: 'Liftoff News',
  link: 'http://liftoff.msfc.nasa.gov/',
  description: 'Liftoff to Space Exploration.',
  language: 'en-us',
  pubdate: 'Tue, 10 Jun 2003 04:00:00 GMT',
  lastbuilddate: 'Tue, 10 Jun 2003 09:41:01 GMT',
  docs: 'http://blogs.law.harvard.edu/tech/rss',
  generator: 'Weblog Editor 2.0',
  managingeditor: 'editor@example.com',
  webmaster: 'webmaster@example.com',
  items:  [
    {
      title: 'Star City',
      link: 'http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp',
      description: 'How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia\'s <a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm">Star City</a>.',
      pubdate: 'Tue, 03 Jun 2003 09:39:21 GMT',
      guid: 'http://liftoff.msfc.nasa.gov/2003/06/03.html#item573'
    },
    {
      description: 'Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a <a href="http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm">partial eclipse of the Sun</a> on Saturday, May 31st.',
      pubdate: 'Fri, 30 May 2003 11:06:42 GMT',
      guid: 'http://liftoff.msfc.nasa.gov/2003/05/30.html#item572'    },
    {
      title: 'The Engine That Does More',
      link: 'http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp',
      description: 'Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly.  The proposed VASIMR engine would do that.',
      pubdate: 'Tue, 27 May 2003 08:37:32 GMT',
      guid: 'http://liftoff.msfc.nasa.gov/2003/05/27.html#item571'    },
    {
      title: 'Astronauts\' Dirty Laundry',
      link: 'http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp',
      description: 'Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them.  Instead, astronauts have other options.',
      pubdate: 'Tue, 20 May 2003 08:56:02 GMT',
      guid: 'http://liftoff.msfc.nasa.gov/2003/05/20.html#item570'    }
  ]
}
```


### Event: 'item'
* `Object` - Item from the feed.

Emitted whenever the parser finds a new feed item. An item can be inside an `<item>` or <entry>` tag.

### Event: `tagname`
* `Object` - The object containing the value of the tag found.

Emitted whenever a tag on the root of the document is finished parsing. The root being the `<channel>` or `<feed>` tag. Example:

```js
parser.on('description', (d) => {
  // do something
});
```

### Event: 'type'
* `string` - Type of feed. Example: atom, rss 2.0, json.

### Event: 'error'
* `Error`

Emitted when there is an error parsing the document.


# Install

    npm install feedme


# Tests
Tests are written with [mocha](https://mochajs.org)

```bash
npm test
```

---
_Source: https://npm.io/package/feedme · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
