{"_id":"@cao-mei-you-ren/rss-parser","name":"@cao-mei-you-ren/rss-parser","dist-tags":{"latest":"3.14.0"},"versions":{"3.14.0":{"name":"@cao-mei-you-ren/rss-parser","version":"3.14.0","main":"index.js","types":"index.d.ts","scripts":{"test":"mocha --reporter-option maxDiffSize=0 --exit","build":"./scripts/build.sh"},"author":{"name":"CaoMeiYouRen"},"contributors":[{"name":"Bobby Brennan"},{"name":"CaoMeiYouRen"}],"license":"MIT","devDependencies":{"@babel/core":"^7.21.4","@babel/preset-env":"^7.21.4","@types/xml2js":"^0.4.3","babel-core":"^6.26.3","babel-loader":"^8.0.4","babel-preset-env":"^1.7.0","chai":"^3.4.1","express":"^4.16.3","mocha":"^10.2.0","puppeteer":"^5.5.0"},"dependencies":{"entities":"^2.0.3","webpack":"^5.90.1","webpack-cli":"^5.1.4","xml2js":"^0.5.0"},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/CaoMeiYouRen/rss-parser.git"},"bugs":{"url":"https://github.com/CaoMeiYouRen/rss-parser/issues"},"homepage":"https://github.com/CaoMeiYouRen/rss-parser#readme","description":"A lightweight RSS parser, for Node and the browser","keywords":["RSS","RSS to JSON","RSS reader","RSS parser","RSS to JS","Feed reader"],"publishConfig":{"access":"public"},"_id":"@cao-mei-you-ren/rss-parser@3.14.0","gitHead":"45859c7ed4bbc4cd1300e0d98091894eef1e08ec","_nodeVersion":"20.10.0","_npmVersion":"10.5.0","dist":{"integrity":"sha512-IVvsCXjRyxBR4+7t3CqqmasvEcAhrsL9ow0l4xJ/NJO/S3l5wIsdmSq4TEUgxKUS92vdbgUBozFpEsc7yGKAew==","shasum":"a45b792f0f4001b9e8a77df732de7637d514b04c","tarball":"https://registry.npmjs.org/@cao-mei-you-ren/rss-parser/-/rss-parser-3.14.0.tgz","fileCount":17,"unpackedSize":1875372,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDyJwo5luTHEAfoV/sF/YL7y6vQtlS2S2mka+pv/Gy4kQIgC3tNfyLTH7dGSTqRCERccDmhkvrPzMpdbFtoO1c8k6o="}]},"_npmUser":{"name":"cao-mei-you-ren","email":"caomeiyouren@qq.com"},"maintainers":[{"name":"cao-mei-you-ren","email":"caomeiyouren@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rss-parser_3.14.0_1720368852915_0.9832459360922574"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-07T16:14:12.777Z","3.14.0":"2024-07-07T16:14:13.141Z","modified":"2024-07-07T16:14:13.392Z"},"maintainers":[{"name":"cao-mei-you-ren","email":"caomeiyouren@qq.com"}],"description":"A lightweight RSS parser, for Node and the browser","homepage":"https://github.com/CaoMeiYouRen/rss-parser#readme","keywords":["RSS","RSS to JSON","RSS reader","RSS parser","RSS to JS","Feed reader"],"repository":{"type":"git","url":"git+https://github.com/CaoMeiYouRen/rss-parser.git"},"contributors":[{"name":"Bobby Brennan"},{"name":"CaoMeiYouRen"}],"author":{"name":"CaoMeiYouRen"},"bugs":{"url":"https://github.com/CaoMeiYouRen/rss-parser/issues"},"license":"MIT","readme":"# rss-parser\n\n[![Version][npm-image]][npm-link]\n[![Build Status][build-image]][build-link]\n[![Downloads][downloads-image]][npm-link]\n\n[downloads-image]: https://img.shields.io/npm/dm/rss-parser.svg\n[npm-image]: https://img.shields.io/npm/v/rss-parser.svg\n[npm-link]: https://npmjs.org/package/rss-parser\n[build-image]: https://github.com/rbren/rss-parser/workflows/tests/badge.svg\n[build-link]: https://github.com/rbren/rss-parser/actions\n\nA small library for turning RSS XML feeds into JavaScript objects.\n\n## Installation\n```bash\nnpm install --save rss-parser\n```\n\n## Usage\nYou can parse RSS from a URL (`parser.parseURL`) or an XML string (`parser.parseString`).\n\nBoth callbacks and Promises are supported.\n\n### NodeJS\nHere's an example in NodeJS using Promises with async/await:\n\n```js\nlet Parser = require('rss-parser');\nlet parser = new Parser();\n\n(async () => {\n\n  let feed = await parser.parseURL('https://www.reddit.com/.rss');\n  console.log(feed.title);\n\n  feed.items.forEach(item => {\n    console.log(item.title + ':' + item.link)\n  });\n\n})();\n```\n\n### TypeScript\nWhen using TypeScript, you can set a type to control the custom fields:\n\n```typescript\nimport Parser from 'rss-parser';\n\ntype CustomFeed = {foo: string};\ntype CustomItem = {bar: number};\n\nconst parser: Parser<CustomFeed, CustomItem> = new Parser({\n  customFields: {\n    feed: ['foo', 'baz'],\n    //            ^ will error because `baz` is not a key of CustomFeed\n    item: ['bar']\n  }\n});\n\n(async () => {\n  const parser = new Parser();\n  const feed = await parser.parseURL('https://www.reddit.com/.rss');\n  console.log(feed.title); // feed will have a `foo` property, type as a string\n\n  feed.items.forEach(item => {\n    console.log(item.title + ':' + item.link) // item will have a `bar` property type as a number\n  });\n})();\n```\n\n### Web\n> We recommend using a bundler like [webpack](https://webpack.js.org/), but we also provide\n> pre-built browser distributions in the `dist/` folder. If you use the pre-built distribution,\n> you'll need a [polyfill](https://github.com/taylorhakes/promise-polyfill) for Promise support.\n\nHere's an example in the browser using callbacks:\n\n```html\n<script src=\"/node_modules/rss-parser/dist/rss-parser.min.js\"></script>\n<script>\n\n// Note: some RSS feeds can't be loaded in the browser due to CORS security.\n// To get around this, you can use a proxy.\nconst CORS_PROXY = \"https://cors-anywhere.herokuapp.com/\"\n\nlet parser = new RSSParser();\nparser.parseURL(CORS_PROXY + 'https://www.reddit.com/.rss', function(err, feed) {\n  if (err) throw err;\n  console.log(feed.title);\n  feed.items.forEach(function(entry) {\n    console.log(entry.title + ':' + entry.link);\n  })\n})\n\n</script>\n```\n\n### Upgrading from v2 to v3\nA few minor breaking changes were made in v3. Here's what you need to know:\n\n* You need to construct a `new Parser()` before calling `parseString` or `parseURL`\n* `parseFile` is no longer available (for better browser support)\n* `options` are now passed to the Parser constructor\n* `parsed.feed` is now just `feed` (top-level object removed)\n* `feed.entries` is now `feed.items` (to better match RSS XML)\n\n\n## Output\nCheck out the full output format in [test/output/reddit.json](test/output/reddit.json)\n\n```yaml\nfeedUrl: 'https://www.reddit.com/.rss'\ntitle: 'reddit: the front page of the internet'\ndescription: \"\"\nlink: 'https://www.reddit.com/'\nitems:\n    - title: 'The water is too deep, so he improvises'\n      link: 'https://www.reddit.com/r/funny/comments/3skxqc/the_water_is_too_deep_so_he_improvises/'\n      pubDate: 'Thu, 12 Nov 2015 21:16:39 +0000'\n      creator: \"John Doe\"\n      content: '<a href=\"http://example.com\">this is a link</a> &amp; <b>this is bold text</b>'\n      contentSnippet: 'this is a link & this is bold text'\n      guid: 'https://www.reddit.com/r/funny/comments/3skxqc/the_water_is_too_deep_so_he_improvises/'\n      categories:\n          - funny\n      isoDate: '2015-11-12T21:16:39.000Z'\n```\n\n##### Notes:\n* The `contentSnippet` field strips out HTML tags and unescapes HTML entities\n* The `dc:` prefix will be removed from all fields\n* Both `dc:date` and `pubDate` will be available in ISO 8601 format as `isoDate`\n* If `author` is specified, but not `dc:creator`, `creator` will be set to `author` ([see article](http://www.lowter.com/blogs/2008/2/9/rss-dccreator-author))\n* Atom's `updated` becomes `lastBuildDate` for consistency\n\n## XML Options\n\n### Custom Fields\nIf your RSS feed contains fields that aren't currently returned, you can access them using the `customFields` option.\n\n```js\nlet parser = new Parser({\n  customFields: {\n    feed: ['otherTitle', 'extendedDescription'],\n    item: ['coAuthor','subtitle'],\n  }\n});\n\nparser.parseURL('https://www.reddit.com/.rss', function(err, feed) {\n  console.log(feed.extendedDescription);\n\n  feed.items.forEach(function(entry) {\n    console.log(entry.coAuthor + ':' + entry.subtitle);\n  })\n})\n```\n\nTo rename fields, you can pass in an array with two items, in the format `[fromField, toField]`:\n\n```js\nlet parser = new Parser({\n  customFields: {\n    item: [\n      ['dc:coAuthor', 'coAuthor'],\n    ]\n  }\n})\n```\n\nTo pass additional flags, provide an object as the third array item. Currently there is one such flag:\n\n* `keepArray (false)` - set to `true` to return *all* values for fields that can have multiple entries.\n* `includeSnippet (false)` - set to `true` to add an additional field, `${toField}Snippet`, with HTML stripped out\n\n```js\nlet parser = new Parser({\n  customFields: {\n    item: [\n      ['media:content', 'media:content', {keepArray: true}],\n    ]\n  }\n})\n```\n\n### Default RSS version\nIf your RSS Feed doesn't contain a `<rss>` tag with a `version` attribute,\nyou can pass a `defaultRSS` option for the Parser to use:\n```js\nlet parser = new Parser({\n  defaultRSS: 2.0\n});\n```\n\n\n### xml2js passthrough\n`rss-parser` uses [xml2js](https://github.com/Leonidas-from-XIV/node-xml2js)\nto parse XML. You can pass [these options](https://github.com/Leonidas-from-XIV/node-xml2js#options)\nto `new xml2js.Parser()` by specifying `options.xml2js`:\n\n```js\nlet parser = new Parser({\n  xml2js: {\n    emptyTag: '--EMPTY--',\n  }\n});\n```\n\n## HTTP Options\n\n### Timeout\nYou can set the amount of time (in milliseconds) to wait before the HTTP request times out (default 60 seconds):\n\n```js\nlet parser = new Parser({\n  timeout: 1000,\n});\n```\n\n### Headers\nYou can pass headers to the HTTP request:\n```js\nlet parser = new Parser({\n  headers: {'User-Agent': 'something different'},\n});\n```\n\n### Redirects\nBy default, `parseURL` will follow up to five redirects. You can change this\nwith `options.maxRedirects`.\n\n```js\nlet parser = new Parser({maxRedirects: 100});\n```\n\n### Request passthrough\n`rss-parser` uses [http](https://nodejs.org/docs/latest/api/http.html#http_http_get_url_options_callback)/[https](https://nodejs.org/docs/latest/api/https.html#https_https_get_url_options_callback) module\nto do requests. You can pass [these options](https://nodejs.org/docs/latest/api/https.html#https_https_request_options_callback)\nto `http.get()`/`https.get()` by specifying `options.requestOptions`:\n\ne.g. to allow unauthorized certificate\n```js\nlet parser = new Parser({\n  requestOptions: {\n    rejectUnauthorized: false\n  }\n});\n```\n\n## Contributing\nContributions are welcome! If you are adding a feature or fixing a bug, please be sure to add a [test case](https://github.com/bobby-brennan/rss-parser/tree/master/test/input)\n\n### Running Tests\nThe 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.\n\nTo check if your changes affect the output of any test cases, run\n\n`npm test`\n\nTo update the output files with your changes, run\n\n`WRITE_GOLDEN=true npm test`\n\n### Publishing Releases\n```bash\nnpm run build\ngit commit -a -m \"Build distribution\"\nnpm version minor # or major/patch\nnpm publish\ngit push --follow-tags\n```\n","readmeFilename":"README.md"}