diff --git a/types/giphy-api/giphy-api-tests.ts b/types/giphy-api/giphy-api-tests.ts new file mode 100644 index 0000000000..6168ece7ac --- /dev/null +++ b/types/giphy-api/giphy-api-tests.ts @@ -0,0 +1,34 @@ +import giphyApi = require('giphy-api'); + +const cb = (err: Error, res: any) => {}; + +giphyApi('API KEY HERE'); +giphyApi({ https: true }); +giphyApi({ timeout: 60 }); +giphyApi({ apiKey: 'API KEY' }); + +const giphy = giphyApi(); +giphy.search('pokemon', cb); +giphy.search('pokemon').then(res => {}); +giphy.search({ q: 'pokemon', rating: 'g' }, cb); +giphy.search({ q: 'pokemon', rating: 'g' }).then(res => {}); + +giphy.id('feqkVgjJpYtjy', cb); +giphy.id('feqkVgjJpYtjy').then(res => {}); +giphy.id(['feqkVgjJpYtjy'], cb); +giphy.id(['feqkVgjJpYtjy']).then(res => {}); + +giphy.translate('superman', cb); +giphy.translate('superman').then(res => {}); +giphy.translate({ s: 'superman', rating: 'g', fmt: 'html' }, cb); +giphy.translate({ s: 'superman', rating: 'g' }).then(res => {}); + +giphy.random('superman', cb); +giphy.random('superman').then(res => {}); +giphy.random({ tag: 'superman', rating: 'g' }, cb); +giphy.random({ tag: 'superman', rating: 'g' }).then(res => {}); + +giphy.trending(cb); +giphy.trending().then(res => {}); +giphy.trending({ limit: 2, rating: 'g' }); +giphy.trending({ limit: 2, rating: 'g' }).then(res => {}); diff --git a/types/giphy-api/index.d.ts b/types/giphy-api/index.d.ts new file mode 100644 index 0000000000..e179e2b99b --- /dev/null +++ b/types/giphy-api/index.d.ts @@ -0,0 +1,189 @@ +// Type definitions for giphy-api 2.0 +// Project: https://github.com/austinkelleher/giphy-api +// Definitions by: Christian Rackerseder +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +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; +} + +interface RandomOptions extends BaseOptions { + tag: string; +} + +interface TrendingOptions extends BaseOptions { + limit?: number; +} + +interface BaseImage { + url: string; + width: string; + height: string; +} + +interface Result { + data: [ + { + type: "gif"; + id: string; + slug: string; + url: string; + bitly_gif_url: string; + bitly_url: string; + embed_url: string; + username: string; + source: string; + rating: Rating; + content_url: string; + source_tld: string; + source_post_url: string; + is_sticker: number; + import_datetime: string; + trending_datetime: string; + images: { + fixed_height_still: BaseImage; + original_still: BaseImage; + fixed_width: BaseImage & { + size: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + fixed_height_small_still: BaseImage; + fixed_height_downsampled: BaseImage & { + size: string; + webp: string; + webp_size: string; + }; + preview: { + width: string; + height: string; + mp4: string; + mp4_size: string; + }; + fixed_height_small: BaseImage & { + size: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + downsized_still: BaseImage & { + size: string; + }; + downsized: BaseImage & { + size: string; + }; + downsized_large: BaseImage & { + size: string; + }; + fixed_width_small_still: BaseImage; + preview_webp: BaseImage & { + size: string; + }; + fixed_width_still: BaseImage; + fixed_width_small: BaseImage & { + size: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + downsized_small: { + width: string; + height: string; + mp4: string; + mp4_size: string; + }; + fixed_width_downsampled: BaseImage & { + size: string; + webp: string; + webp_size: string; + }; + downsized_medium: BaseImage & { + size: string; + }; + original: BaseImage & { + size: string; + frames: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + fixed_height: BaseImage & { + size: string; + mp4: string; + mp4_size: string; + webp: string; + webp_size: string; + }; + looping: { mp4: string; mp4_size: string }; + original_mp4: { + width: string; + height: string; + mp4: string; + mp4_size: string; + }; + preview_gif: BaseImage & { + size: string; + }; + title: string; + _score: number; + analytics: { + onload: { url: string }; + onclick: { url: string }; + onsent: { url: 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; diff --git a/types/giphy-api/tsconfig.json b/types/giphy-api/tsconfig.json new file mode 100644 index 0000000000..e8d707c5fb --- /dev/null +++ b/types/giphy-api/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "giphy-api-tests.ts" + ] +} diff --git a/types/giphy-api/tslint.json b/types/giphy-api/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/giphy-api/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }