diff --git a/types/giphy-api/giphy-api-tests.ts b/types/giphy-api/giphy-api-tests.ts index 6168ece7ac..c5fc86870e 100644 --- a/types/giphy-api/giphy-api-tests.ts +++ b/types/giphy-api/giphy-api-tests.ts @@ -2,15 +2,17 @@ import giphyApi = require('giphy-api'); const cb = (err: Error, res: any) => {}; +const apiOptions: giphyApi.GiphyOptions = { https: true }; giphyApi('API KEY HERE'); -giphyApi({ https: true }); +giphyApi(apiOptions); giphyApi({ timeout: 60 }); giphyApi({ apiKey: 'API KEY' }); -const giphy = giphyApi(); +const searchOptions: giphyApi.SearchOptions = { q: 'pokemon', rating: 'g' }; +const giphy: giphyApi.Giphy = giphyApi(); giphy.search('pokemon', cb); giphy.search('pokemon').then(res => {}); -giphy.search({ q: 'pokemon', rating: 'g' }, cb); +giphy.search(searchOptions, cb); giphy.search({ q: 'pokemon', rating: 'g' }).then(res => {}); giphy.id('feqkVgjJpYtjy', cb); diff --git a/types/giphy-api/index.d.ts b/types/giphy-api/index.d.ts index f6174543eb..d121eff979 100644 --- a/types/giphy-api/index.d.ts +++ b/types/giphy-api/index.d.ts @@ -7,23 +7,11 @@ type Rating = "y" | "g" | "pg" | "pg-13" | "r"; type Format = "html" | "json"; -interface GiphyOptions { - https?: boolean; - timeout?: number; - apiKey?: string; -} - interface BaseOptions { rating: Rating; fmt?: Format; } -interface SearchOptions extends BaseOptions { - q: string; - limit?: number; - offset?: number; -} - interface TranslateOptions extends BaseOptions { s: string; } @@ -42,136 +30,150 @@ interface BaseImage { height: string; } -interface Result { - data: [ - { - type: string; - id: string; - slug: string; - url: string; - bitly_url: string; - embed_url: string; - username: string; - source: string; - rating: Rating; - content_url: string; - user?: { - avatar_url: string; - banner_url: string; - profile_url: string; +type Callback = (err: Error, res: giphyApi.Result) => void; + +declare function giphyApi(apiKeyOrOptions?: string | giphyApi.GiphyOptions): giphyApi.Giphy; + +declare namespace giphyApi { + interface GiphyOptions { + https?: boolean; + timeout?: number; + apiKey?: string; + } + + interface SearchOptions extends BaseOptions { + q: string; + limit?: number; + offset?: number; + } + + interface Giphy { + search(queryOrOptions: string | SearchOptions, cb: Callback): void; + search(queryOrOptions: string | SearchOptions): Promise; + id(ids: string | string[], cb: Callback): void; + id(ids: string | string[]): Promise; + translate(termOrOptions: string | TranslateOptions, cb: Callback): void; + translate(termOrOptions: string | TranslateOptions): Promise; + random(tagOrOptions: string | RandomOptions, cb: Callback): void; + random(tagOrOptions: string | RandomOptions): Promise; + trending(options: TrendingOptions, cb: Callback): void; + trending(cb: Callback): void; + trending(options?: TrendingOptions): Promise; + } + + interface Result { + data: [ + { + type: string; + id: string; + slug: string; + url: string; + bitly_url: string; + embed_url: string; username: string; - display_name: string; - twitter: string; - }, - source_tld: string; - source_post_url: string; - update_datetime: string; - create_datetime: string; - import_datetime: string; - trending_datetime: string; - title: string; - images: { - fixed_height: BaseImage & { - size: string; - mp4: string; - mp4_size: string; - webp: string; - webp_size: string; + source: string; + rating: Rating; + content_url: string; + user?: { + avatar_url: string; + banner_url: string; + profile_url: string; + username: string; + display_name: string; + twitter: string; + }, + source_tld: string; + source_post_url: string; + update_datetime: string; + create_datetime: string; + import_datetime: string; + trending_datetime: string; + title: string; + images: { + fixed_height: BaseImage & { + size: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + fixed_height_still: BaseImage; + fixed_height_downsampled: BaseImage & { + size: string; + webp: string; + webp_size: string; + }; + fixed_width: BaseImage & { + size: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + original_still: BaseImage; + fixed_width_still: BaseImage; + fixed_width_downsampled: BaseImage & { + size: string; + webp: string; + webp_size: string; + }; + fixed_height_small: BaseImage & { + size: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + fixed_height_small_still: BaseImage; + fixed_width_small: BaseImage & { + size: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + fixed_width_small_still: BaseImage; + downsized: BaseImage & { + size: string; + }; + downsized_still: BaseImage; + downsized_large: BaseImage & { + size: string; + }; + downsized_medium: BaseImage & { + size: string; + }; + downsized_small: BaseImage & { + size: string; + }; + original: BaseImage & { + size: string; + frames: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + looping: { mp4: string; }; + preview: { + width: string; + height: string; + mp4: string; + mp4_size: string; + }; + preview_gif: BaseImage & { + size: string; + }; }; - fixed_height_still: BaseImage; - fixed_height_downsampled: BaseImage & { - size: string; - webp: string; - webp_size: string; - }; - fixed_width: BaseImage & { - size: string; - mp4: string; - mp4_size: string; - webp: string; - webp_size: string; - }; - original_still: BaseImage; - fixed_width_still: BaseImage; - fixed_width_downsampled: BaseImage & { - size: string; - webp: string; - webp_size: string; - }; - fixed_height_small: BaseImage & { - size: string; - mp4: string; - mp4_size: string; - webp: string; - webp_size: string; - }; - fixed_height_small_still: BaseImage; - fixed_width_small: BaseImage & { - size: string; - mp4: string; - mp4_size: string; - webp: string; - webp_size: string; - }; - fixed_width_small_still: BaseImage; - downsized: BaseImage & { - size: string; - }; - downsized_still: BaseImage; - downsized_large: BaseImage & { - size: string; - }; - downsized_medium: BaseImage & { - size: string; - }; - downsized_small: BaseImage & { - size: string; - }; - original: BaseImage & { - size: string; - frames: string; - mp4: string; - mp4_size: string; - webp: string; - webp_size: string; - }; - looping: { mp4: string; }; - preview: { - width: string; - height: string; - mp4: string; - mp4_size: string; - }; - preview_gif: BaseImage & { - size: string; - }; - }; - } - ]; - pagination: { total_count: number; count: number; offset: number }; - meta: { - status: number; - msg: string; - response_id: string; - }; + } + ]; + pagination: { total_count: number; count: number; offset: number }; + meta: { + status: number; + msg: string; + response_id: string; + }; + } } -type Callback = (err: Error, res: Result) => void; - -interface Giphy { - search(queryOrOptions: string | SearchOptions, cb: Callback): void; - search(queryOrOptions: string | SearchOptions): Promise; - id(ids: string | string[], cb: Callback): void; - id(ids: string | string[]): Promise; - translate(termOrOptions: string | TranslateOptions, cb: Callback): void; - translate(termOrOptions: string | TranslateOptions): Promise; - random(tagOrOptions: string | RandomOptions, cb: Callback): void; - random(tagOrOptions: string | RandomOptions): Promise; - trending(options: TrendingOptions, cb: Callback): void; - trending(cb: Callback): void; - trending(options?: TrendingOptions): Promise; -} - -declare function giphyApi(apiKeyOrOptions?: string | GiphyOptions): Giphy; - export = giphyApi;