diff --git a/types/rss/index.d.ts b/types/rss/index.d.ts index b40cc96529b78d..966aca606a16ca 100644 --- a/types/rss/index.d.ts +++ b/types/rss/index.d.ts @@ -3,10 +3,7 @@ // Definitions by: Second Datke // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare var factory: NodeRSS.RSSFactory; -export = factory; - -declare namespace NodeRSS { +declare namespace RSS { interface FeedOptions { /** * Title of your site or feed. @@ -172,36 +169,38 @@ declare namespace NodeRSS { */ indent?: boolean | string | undefined; } +} - interface RSS { - /** - * Add an item to a feed. An item can be used for a blog - * entry, project update, log entry, etc. - * @param {ItemOptions} itemOptions - * @returns {RSS} - */ - item(itemOptions: ItemOptions): RSS; - /** - * Generate XML and return as a string for this feed. - * @returns {string} - */ - xml(): string; - /** - * Generate XML and return as a string for this feed. - * - * @param {XmlOptions} xmlOptions - You can use indent - * option to specify the tab character to use. - * @returns {string} - */ - xml(xmlOptions: XmlOptions): string; - } +// export declare class RSS { +declare class RSS { + /** + * Create an RSS feed with options. + * @param {FeedOptions} feedOptions - Options for the RSS feed. + * @param {ItemOptions[]} feedItems - Array of items for the RSS feed. + * @returns {RSS} + */ + constructor(feedOptions: RSS.FeedOptions, feedItems?: RSS.ItemOptions[]); - interface RSSFactory { - /** - * Create an RSS feed with options. - * @param {FeedOptions} feedOptions - Options for the RSS feed. - * @returns {RSS} - */ - new(feedOptions: FeedOptions): RSS; - } + /** + * Add an item to a feed. An item can be used for a blog + * entry, project update, log entry, etc. + * @param {ItemOptions} itemOptions + * @returns {RSS} + */ + item(itemOptions: RSS.ItemOptions): RSS; + /** + * Generate XML and return as a string for this feed. + * @returns {string} + */ + xml(): string; + /** + * Generate XML and return as a string for this feed. + * + * @param {XmlOptions} xmlOptions - You can use indent + * option to specify the tab character to use. + * @returns {string} + */ + xml(xmlOptions: RSS.XmlOptions): string; } + +export = RSS; diff --git a/types/rss/rss-tests.ts b/types/rss/rss-tests.ts index 3dc5574c1c4e46..eb42f968ac659f 100644 --- a/types/rss/rss-tests.ts +++ b/types/rss/rss-tests.ts @@ -1,13 +1,7 @@ -// this test is copied from https://github.com/dylang/node-rss -// it basically: -// -// * creates an RSS feed with some attributes, -// * add an item to it -// * then generates XML string - +// this test is adapted from https://github.com/dylang/node-rss import RSS = require('rss'); -var feed = new RSS({ +const feedOptions = { title: 'title', description: 'description', feed_url: 'http://example.com/rss.xml', @@ -18,11 +12,11 @@ var feed = new RSS({ webMaster: 'Dylan Greene', copyright: '2013 Dylan Greene', language: 'en', - categories: ['Category 1','Category 2','Category 3'], + categories: ['Category 1', 'Category 2', 'Category 3'], pubDate: 'May 20, 2012 04:00:00 GMT', ttl: 60, custom_namespaces: { - 'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd' + itunes: 'http://www.itunes.com/dtds/podcast-1.0.dtd', }, custom_elements: [ { 'itunes:subtitle': 'A show about everything' }, @@ -35,35 +29,50 @@ var feed = new RSS({ }, { 'itunes:image': { _attr: { - href: 'http://example.com/podcasts/everything/AllAboutEverything.jpg' - } - } - } - ] -}); + href: 'http://example.com/podcasts/everything/AllAboutEverything.jpg', + }, + }, + }, + ], +}; -feed.item({ +const feedItem = { title: 'item title', description: 'use this for the content. It can include html.', url: 'http://example.com/article4?this&that', guid: '1123', - categories: ['Category 1','Category 2','Category 3','Category 4'], + categories: ['Category 1', 'Category 2', 'Category 3', 'Category 4'], author: 'Guest Author', date: 'May 27, 2012', lat: 33.417974, long: -111.933231, - enclosure: { url:'...', file:'path-to-file' }, + enclosure: { url: '...', file: 'path-to-file' }, custom_elements: [ { 'itunes:author': 'John Doe' }, { 'itunes:subtitle': 'A short primer on table spices' }, - { 'itunes:image': { + { + 'itunes:image': { _attr: { - href: 'http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg' - } - } + href: 'http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg', + }, + }, }, - { 'itunes:duration': '7:04' } - ] -}); + { 'itunes:duration': '7:04' }, + ], +}; + +// creates an RSS feed with some attributes, +const feed = new RSS(feedOptions); // $ExpectType RSS + +// add an item to the feed +feed.item(feedItem); // $ExpectType RSS + +// generate an XML string from the feed +const xml = feed.xml(); // $ExpectType string + +// creates an RSS feed with some attributes and items +const feedWithItems = new RSS(feedOptions, [feedItem]); // $ExpectType RSS +feedWithItems.xml(); // $ExpectType string -var xml = feed.xml(); +// test type exports +type Types = typeof RSS | RSS | RSS.FeedOptions | RSS.EnclosureObject | RSS.ItemOptions | RSS.XmlOptions;