From bd4617c11ec89a33b532a5ec8427a4c0109c5fdd Mon Sep 17 00:00:00 2001 From: Malo Bourgon Date: Wed, 10 Jul 2019 12:34:47 -0700 Subject: [PATCH] Update podcast type declarations (#36770) --- types/podcast/index.d.ts | 147 +++++++++++++++++---------------- types/podcast/podcast-tests.ts | 65 +++++++++------ types/podcast/tsconfig.json | 2 +- types/podcast/tslint.json | 79 +----------------- 4 files changed, 116 insertions(+), 177 deletions(-) diff --git a/types/podcast/index.d.ts b/types/podcast/index.d.ts index 0a48ca432b..d7afe11d29 100644 --- a/types/podcast/index.d.ts +++ b/types/podcast/index.d.ts @@ -1,86 +1,89 @@ -// Type definitions for podcast v0.1.0 +// Type definitions for podcast 1.1 // Project: https://github.com/maxnowack/node-podcast // Definitions by: Niklas Mollenhauer +// Malo Bourgon // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.7 -interface PodcastStatic -{ - new(options: IFeedOptions): PodcastStatic; +export = Podcast; - item(options: IItemOptions): void; - xml(indent?: string): string; +declare class Podcast { + constructor(options?: Podcast.FeedOptions, items?: ReadonlyArray); + + addItem(item: Podcast.Item): void; + buildXml(indent?: boolean | string): string; } -interface IFeedOptions -{ - title: string; - description?: string; - generator?: string; - feed_url: string; - site_url: string; - image_url?: string; - docs?: string; - author: string; - managingEditor?: string; - webMaster?: string; - copyright?: string; - language?: string; - categories?: string[]; - pubDate?: Date; - ttl?: number; - itunesAuthor?: string; - itunesSubtitle?: string; - itunesSummary?: string; - itunesOwner?: IItunesOwner; - itunesExplicit?: boolean; - itunesCategory?: IItunesCategory; - itunesImage?: string; -} +declare namespace Podcast { + interface BaseFeedOptions { + title?: string; + description?: string; + generator?: string; + docs?: string; + author: string; + managingEditor?: string; + webMaster?: string; + copyright?: string; + language?: string; + categories?: string[]; + pubDate?: Date | string; + ttl?: number; + itunesAuthor?: string; + itunesSubtitle?: string; + itunesSummary?: string; + itunesOwner?: FeedItunesOwner; + itunesExplicit?: boolean; + itunesCategory?: FeedItunesCategory[]; + itunesImage?: string; + itunesType?: "episodic" | "serial"; + customNamespaces?: object; + customElements?: object[]; + } -interface IItunesOwner -{ - name: string; - email: string; -} -interface IItunesCategory -{ - name: string; - subcats: IItunesSubCategory[] -} -interface IItunesSubCategory -{ - name: string; - subcat: string[] /* ? */ -} + interface FeedItunesOwner { + name: string; + email: string; + } -interface IItemOptions -{ - title: string; - description: string; - url: string; - guid: string; - categories?: string[]; - author?: string; - date: Date; - lat?: number; - long?: number; - enclosure?: { + interface FeedItunesCategory { + text: string; + subcats?: FeedItunesCategory[]; + } + + type FeedOptions = BaseFeedOptions & + ({ feedUrl: string } | { feed_url: string }) & + ({ siteUrl: string } | { site_url: string }) & + ({ imageUrl?: string } | { image_url?: string }); + + interface Item { + title?: string; + description?: string; + url: string; + guid?: string; + categories?: string[]; + author?: string; + date: Date | string; + lat?: number; + long?: number; + enclosure?: ItemEnclosure; + content?: string; + itunesAuthor?: string; + itunesExplicit?: boolean; + itunesSubtitle?: string; + itunesSummary?: string; + itunesDuration?: number; + itunesImage?: string; + itunesSeason?: number; + itunesEpisode?: number; + itunesTitle?: string; + itunesEpisodeType?: 'full' | 'trailer' | 'bonus'; + customElements?: object[]; + } + + interface ItemEnclosure { url: string; file?: string; size?: number; - mime?: string; + type?: string; } - itunesAuthor?: string; - itunesExplicit?: boolean; - itunesSubtitle?: string; - itunesSummary?: string; - itunesDuration?: number; - itunesKeywords?: string[]; -} - -declare var Podcast: PodcastStatic; - -declare module "podcast" -{ - export = Podcast; } diff --git a/types/podcast/podcast-tests.ts b/types/podcast/podcast-tests.ts index 8b19ac631f..648e7c443c 100644 --- a/types/podcast/podcast-tests.ts +++ b/types/podcast/podcast-tests.ts @@ -1,11 +1,12 @@ import Podcast = require('podcast'); -/* lets create an rss feed */ -var feed = new Podcast({ +// Adapted from example provided in module readme + +const feedOptions: Podcast.FeedOptions = { title: 'title', description: 'description', feed_url: 'http://example.com/rss.xml', - site_url: 'http://example.com', + siteUrl: 'http://example.com', image_url: 'http://example.com/icon.png', docs: 'http://example.com/rss/docs.html', author: 'Dylan Greene', @@ -13,42 +14,54 @@ var feed = new Podcast({ webMaster: 'Dylan Greene', copyright: '2013 Dylan Greene', language: 'en', - categories: ['Category 1','Category 2','Category 3'], - pubDate: new Date('May 20, 2012 04:00:00 GMT'), + categories: ['Category 1', 'Category 2', 'Category 3'], + pubDate: 'May 20, 2012 04:00:00 GMT', ttl: 60, itunesAuthor: 'Max Nowack', itunesSubtitle: 'I am a sub title', itunesSummary: 'I am a summary', - itunesOwner: { name: 'Max Nowack', email:'max@unsou.de' }, + itunesOwner: { name: 'Max Nowack', email: 'max@unsou.de' }, itunesExplicit: false, - itunesCategory: { - "name": "Entertainment", - "subcats": null - }, - itunesImage: 'http://link.to/image.png' -}); + itunesCategory: [{ + text: 'Entertainment', + subcats: [{ + text: 'Television' + }] + }], + itunesImage: 'http://link.to/image.png', + itunesType: 'serial', +}; -/* loop over data and add to feed */ -feed.item({ +const feedItem: Podcast.Item = { title: 'item title', description: 'use this for the content. It can include html.', - url: 'http://example.com/article4?this&that', // link to the item - guid: '1123', // optional - defaults to url - categories: ['Category 1','Category 2','Category 3','Category 4'], // optional - array of item categories - author: 'Guest Author', // optional - defaults to feed author property + url: 'http://example.com/article4?this&that', + guid: '1123', + categories: ['Category 1', 'Category 2', 'Category 3', 'Category 4'], + author: 'Guest Author', date: new Date('May 27, 2012'), - lat: 33.417974, //optional latitude field for GeoRSS - long: -111.933231, //optional longitude field for GeoRSS - enclosure : {url:'...', file:'path-to-file'}, // optional enclosure + lat: 33.417974, + long: -111.933231, + enclosure: { url: '...', file: 'path-to-file' }, itunesAuthor: 'Max Nowack', itunesExplicit: false, itunesSubtitle: 'I am a sub title', itunesSummary: 'I am a summary', itunesDuration: 12345, - itunesKeywords: ['javascript','podcast'] -}); + itunesImage: 'http://link.to/image.png', + itunesSeason: 2, + itunesEpisode: 1, + itunesTitle: 'iTunes Title', + itunesEpisodeType: 'bonus', +}; -// cache the xml to send to clients -var xml = feed.xml(); +const feed1 = new Podcast(feedOptions); +feed1.addItem(feedItem); +const feed1Xml = feed1.buildXml(); -console.log(xml); +const feed2 = new Podcast(feedOptions, [feedItem]); +const feed2Xml1 = feed2.buildXml(); +const feed2Xml2 = feed2.buildXml(true); +const feed2Xml3 = feed2.buildXml(' '); + +console.log(feed1Xml, feed2Xml1, feed2Xml2, feed2Xml3); diff --git a/types/podcast/tsconfig.json b/types/podcast/tsconfig.json index 8e4c29f1e9..0af8eef822 100644 --- a/types/podcast/tsconfig.json +++ b/types/podcast/tsconfig.json @@ -21,4 +21,4 @@ "index.d.ts", "podcast-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/podcast/tslint.json b/types/podcast/tslint.json index 3d59f55fda..f93cf8562a 100644 --- a/types/podcast/tslint.json +++ b/types/podcast/tslint.json @@ -1,80 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "npm-naming": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" }