Merge pull request #17861 from dolanmiu/google-images

Typings for google-images
This commit is contained in:
Ryan Cavanaugh 2017-07-13 16:31:55 -07:00 committed by GitHub
commit d04c4eac62
4 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,27 @@
import * as GoogleImages from "google-images";
const client = new GoogleImages('CSE ID', 'API KEY');
client.search('Steve Angello')
.then(images => {
/*
[{
"url": "http://steveangello.com/boss.jpg",
"type": "image/jpeg",
"width": 1024,
"height": 768,
"size": 102451,
"thumbnail": {
"url": "http://steveangello.com/thumbnail.jpg",
"width": 512,
"height": 512
}
}]
*/
});
// paginate results
client.search('Steve Angello', {page: 2});
// search for certain size
client.search('Steve Angello', {size: 'large'});

42
types/google-images/index.d.ts vendored Normal file
View File

@ -0,0 +1,42 @@
// Type definitions for google-images 2.1
// Project: https://github.com/vadimdemedes/google-images
// Definitions by: Dolan Miu <https://github.com/dolanmiu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = GoogleImages;
declare namespace GoogleImages {
type SearchImageSize = "icon" | "small" | "medium" | "large" | "xlarge" | "xxlarge" | "huge";
type SearchImageType = "clipart" | "face" | "lineart" | "news" | "photo";
type SearchDominantColor = "black" | "blue" | "brown" | "gray" | "green" | "pink" | "purple" | "teal" | "white" | "yellow";
type SearchColorType = "color" | "gray" | "mono";
type SearchSafe = "high" | "medium" | "off";
interface SearchOptions {
page?: number;
size?: SearchImageSize;
type?: SearchImageType;
dominantColor?: SearchDominantColor;
colorType?: SearchColorType;
safe?: SearchSafe;
}
interface Image {
url: string;
type: string;
width: number;
height: number;
size: number;
thumbnail: {
url: string,
width: number,
height: number
};
}
}
declare class GoogleImages {
constructor(engineId: string, apiKey: string);
search(searchTerm: string, options?: GoogleImages.SearchOptions): Promise<GoogleImages.Image[]>;
}

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"google-images-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }