From abe4e8758f79b1615ab159daf3f51bc327405ac8 Mon Sep 17 00:00:00 2001 From: cherryblossom000 <31467609+cherryblossom000@users.noreply.github.com> Date: Fri, 27 Mar 2020 04:57:25 +1100 Subject: [PATCH] Add types for yt-search (#43336) --- types/yt-search/index.d.ts | 142 +++++++++++++++++++++++++++++ types/yt-search/tsconfig.json | 24 +++++ types/yt-search/tslint.json | 1 + types/yt-search/yt-search-tests.ts | 33 +++++++ 4 files changed, 200 insertions(+) create mode 100644 types/yt-search/index.d.ts create mode 100644 types/yt-search/tsconfig.json create mode 100644 types/yt-search/tslint.json create mode 100644 types/yt-search/yt-search-tests.ts diff --git a/types/yt-search/index.d.ts b/types/yt-search/index.d.ts new file mode 100644 index 0000000000..8467dc947c --- /dev/null +++ b/types/yt-search/index.d.ts @@ -0,0 +1,142 @@ +// Type definitions for yt-search 1.1 +// Project: https://github.com/talmobi/yt-search#readme +// Definitions by: cherryblossom +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Minimum TypeScript Version: 3.5 + +export = search; + +declare function search(query: string | search.Options, callback: (err: Error, data: search.SearchResult) => void): void; +declare function search(query: string | search.Options): Promise; + +declare function search(query: search.VideoMetadataOptions, callback: (err: Error, data: search.VideoMetadataResult) => void): void; +declare function search(query: search.VideoMetadataOptions): Promise; + +declare function search(query: search.PlaylistMetadataOptions, callback: (err: Error, data: search.PlaylistMetadataResult) => void): void; +declare function search(query: search.PlaylistMetadataOptions): Promise; + +declare namespace search { + interface BaseOptions { + pageStart?: number; + pageEnd?: number; + } + + interface OptionsWithQuery extends BaseOptions { query: string; } + interface OptionsWithSearch extends BaseOptions { search: string; } + + type Options = OptionsWithQuery | OptionsWithSearch; + + interface VideoMetadataOptions { videoId: string; } + interface PlaylistMetadataOptions { listId: string; } + + interface Author { + name: string; + id: string; + url: string; + userId: string; + userUrl: string; + userName: string; + channelId: string; + channelUrl: string; + channelName: string; + } + + interface PlaylistAuthor extends Omit { + userText: string; + channelText: string; + } + + interface VideoSearchResult { + type: 'video'; + title: string; + description: string; + url: string; + videoId: string; + seconds: number; + timestamp: string; + duration: { + seconds: number; + timestamp: string; + }; + views: number; + thumbnail: string; + image: string; + ago: string; + author: Author; + } + + interface PlaylistSearchResult { + type: 'list'; + title: string; + url: string; + listId: string; + videoCountLabel: string; + videoCount: number; + thumbnail: string; + image: string; + author: Author; + } + + interface ChannelSearchResult { + type: 'channel'; + title: string; + description: string; + url: string; + videoCountLabel: string; + videoCount: number; + thumbnail: string; + name: string; + id: string; + } + + interface SearchResult { + videos: VideoSearchResult[]; + playlists: PlaylistSearchResult[]; + lists: PlaylistSearchResult[]; + accounts: ChannelSearchResult[]; + channels: ChannelSearchResult[]; + } + + interface VideoMetadataResult { + title: string; + description: string; + url: string; + videoId: string; + seconds: number; + timestamp: string; + duration: { + seconds: number; + timestamp: string; + }; + views: number; + genre: string; + uploadDate: string; + ago: string; + thumbnail: string; + image: string; + author: Author; + } + + interface PlaylistItem { + title: string; + videoId: string; + listId: string; + url: string; + thumbnailUrl: string; + thumbnailUrlHQ: string; + owner: string; + author: PlaylistAuthor; + } + + interface PlaylistMetadataResult { + title: string; + listId: string; + url: string; + videoCount: number; + views: number; + lastUpdate: string; + thumbnail: string; + items: PlaylistItem[]; + author: PlaylistAuthor; + } +} diff --git a/types/yt-search/tsconfig.json b/types/yt-search/tsconfig.json new file mode 100644 index 0000000000..0ee4423f53 --- /dev/null +++ b/types/yt-search/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "esModuleInterop": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "yt-search-tests.ts" + ] +} diff --git a/types/yt-search/tslint.json b/types/yt-search/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/yt-search/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/yt-search/yt-search-tests.ts b/types/yt-search/yt-search-tests.ts new file mode 100644 index 0000000000..43009b0a37 --- /dev/null +++ b/types/yt-search/yt-search-tests.ts @@ -0,0 +1,33 @@ +import yts from 'yt-search'; + +// $ExpectType Promise +yts(''); + +// $ExpectType void +yts('', (err, data) => { + // $ExpectType Error + err; + // $ExpectType SearchResult + data; +}); + +// $ExpectType Promise +yts({ query: '' }); + +// $ExpectType Promise +yts({ search: '', pageStart: 2, pageEnd: 5 }); + +// $ExpectType Promise +yts({ videoId: '' }); + +// $ExpectType Promise +yts({ listId: '' }); + +// $ExpectError +yts(); + +// $ExpectError +yts({}); + +// $ExpectError +yts({ query: '', videoId: '' });