# xfp

> Universal feed parser - RSS1/2, Atom, JSON, HTML

Latest version **0.2.18** (published 2023-07-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.18 |
| Published | 2023-07-14 |
| First published | 2023-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16 |
| Dependencies | 10 |
| Unpacked size | 23.8 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Goran Spasojevic |
| Maintainers | gorango |
| Keywords | feed, parser, xml, rss, atom, json, html |

## Links

- npm: https://www.npmjs.com/package/xfp
- Repository: https://github.com/gorango/xfp
- Homepage: https://github.com/gorango/xfp#readme
- Issues: https://github.com/gorango/xfp/issues
- npm.io page: https://npm.io/package/xfp

## Dependencies (10)

- [unified](https://npm.io/package/unified.md) ^10.1.2
- [entities](https://npm.io/package/entities.md) ^4.5.0
- [rehype-parse](https://npm.io/package/rehype-parse.md) ^8.0.4
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^4.2.5
- [rehype-sanitize](https://npm.io/package/rehype-sanitize.md) ^5.0.1
- [rehype-stringify](https://npm.io/package/rehype-stringify.md) ^9.0.3
- [hast-util-to-text](https://npm.io/package/hast-util-to-text.md) ^3.1.2
- [rehype-extract-meta](https://npm.io/package/rehype-extract-meta.md) ^2.1.0
- [rehype-extract-posts](https://npm.io/package/rehype-extract-posts.md) ^0.0.4
- [rehype-preset-minify](https://npm.io/package/rehype-preset-minify.md) ^6.0.0

## 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

- 0.2.18 (latest) — 2023-07-14
- 0.2.17 — 2023-07-14
- 0.2.16 — 2023-07-14
- 0.2.14 — 2023-07-09
- 0.2.13 — 2023-07-08
- 0.2.11 — 2023-07-08
- 0.2.10 — 2023-07-07
- 0.2.9 — 2023-07-02
- 0.2.8 — 2023-06-30
- 0.2.7 — 2023-06-30
- 0.2.6 — 2023-06-30
- 0.2.5 — 2023-06-30
- 0.2.4 — 2023-06-28
- 0.2.3 — 2023-06-27
- 0.2.2 — 2023-06-26
- … 6 more at https://npm.io/package/xfp/versions

## README

# (X) Feed Parser

[![Types][types-badge]][types-link]
[![Size][size-badge]][size-link]

Parse [RSS](#parseXmlFeedstr), [Atom](#parseXmlFeedstr), [JSON Feed](#parseJsonFeedstr), and [HTML](#parseHtmlFeedstr) into a common JSON format. Complete with XML decoding, HTML sanitization, date standardization, media and metadata extraction.

This project is based on the [rbren/rss-parser][rss-parser] upgraded to [ESM][esm] with [JSDoc][jsdoc] types and the addition of features above.

## Install

```sh
npm install xfp
```

## Usage

```js
import { parse } from 'xfp'

let rawFeedString // XML (RSS/Atom), JSON Feed, or HTML
const feed = parse(rawFeedString)
```

Running the code above with a valid `rawFeedString` returns a response with the following [schema][types]:

```
{
	type: 'rss' | 'atom' | 'json' | 'html'
	lang?: string
	title?: string
	description?: string
	feedUrl?: string
	siteUrl?: string
	imageUrl?: string
	etag?: string
	updatedAt?: string
	items?: [{
		id?: string
		url?: string
		lang?: string
		title?: string
		summary?: string
		author?: string
		content?: string
		snippet?: string
		categories?: string[]
		commentsUrl?: string
		imageUrl?: string
		media?: [{
			url: string
			length?: number
			type?: string
		}]
		createdAt?: string
		updatedAt?: string
	}]
	meta?: {
		[key: string]: any // youtube, itunes metadata
	}
}
```

See the [`test/`](test/) folder for complete usage examples.

## API

This library exports the [`parse`](#parse) function, which is a thin wrapper for [`parseXmlFeed`](#parseXmlFeedstr), [`parseJsonFeed`](#parseJsonFeedstr), and [`parseHtmlFeed`](#parseHtmlFeedstr).

### `parse(str)`

Identifies the filetype (`xml`, `json`, or `html`) and assigns the appropriate parser.

```js
import { parse } from 'xfp'
```

### `parseXmlFeed(str)`

Handler for [RSS][rss] (v0.9 - v2.0) and [Atom][atom] feeds.

```js
import { parseXmlFeed } from 'xfp'
```

### `parseJsonFeed(str)`

Handler for [JSON feeds][json] (v1).

```js
import { parseJsonFeed } from 'xfp'
```

### `parseHtmlFeed(str)`

**WIP!** Extracts feed data from an HTML document using [rehype-extract-meta][rehype-meta] and [rehype-extract-posts][rehype-posts].

```js
import { parseHtmlFeed } from 'xfp'
```

## License

[MIT][license] © [Goran Spasojevic][author]



<!-- Definitions -->

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[jsdoc]: https://github.com/jsdoc/jsdoc
[types-badge]: https://badgen.net/npm/types/xfp
[types-link]: https://www.npmjs.com/package/xfp
[size-badge]: https://packagephobia.com/badge?p=xfp
[size-link]: https://packagephobia.com/result?p=xfp
[rss-parser]: https://github.com/rbren/rss-parser
[types]: ./types.ts
[json]: https://www.jsonfeed.org/version/1/
[rss]: https://validator.w3.org/feed/docs/rss2.html
[atom]: https://validator.w3.org/feed/docs/atom.html
[rehype-meta]: https://www.npmjs.com/package/rehype-extract-meta
[rehype-posts]: https://www.npmjs.com/package/rehype-extract-posts
[license]: license
[author]: https://github.com/gorango

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