Skip to content

Commit d50ee28

Browse files
committed
feat: add type definitions
1 parent 39ec647 commit d50ee28

File tree

7 files changed

+321
-0
lines changed

7 files changed

+321
-0
lines changed

.gitignore

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
.npmignore
10+
11+
# Coverage directory used by tools like istanbul
12+
coverage
13+
*.lcov
14+
15+
# Dependency directories
16+
node_modules/
17+
jspm_packages/
18+
19+
# TypeScript cache
20+
*.tsbuildinfo
21+
22+
# Optional npm cache directory
23+
.npm
24+
25+
# Optional eslint cache
26+
.eslintcache
27+
28+
# Optional stylelint cache
29+
.stylelintcache
30+
31+
# Output of 'npm pack'
32+
*.tgz
33+
34+
# Yarn Integrity file
35+
.yarn-integrity
36+
37+
# dotenv environment variable files
38+
.env
39+
.env.development.local
40+
.env.test.local
41+
.env.production.local
42+
.env.local
43+
44+
# yarn v2
45+
.yarn/cache
46+
.yarn/unplugged
47+
.yarn/build-state.yml
48+
.yarn/install-state.gz
49+
.pnp.*

tsconfig.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"emitDeclarationOnly": true,
5+
"allowJs": true,
6+
"outDir": "./typings",
7+
"lib": ["ESNext"],
8+
"target": "ESNext",
9+
"moduleResolution": "node"
10+
},
11+
"include": [
12+
"./lib/**/*.js",
13+
"./index.js"
14+
],
15+
"exclude": [
16+
"node_modules",
17+
"**/*.d.ts"
18+
]
19+
}

typings/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const _exports: typeof import("./lib/googlethis");
2+
export = _exports;

typings/lib/constants.d.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
export namespace URLS {
2+
const GIS: string;
3+
const GOOGLE: string;
4+
const W_GOOGLE: string;
5+
const GOOGLE_NEWS: string;
6+
const FAVICONKIT: string;
7+
}
8+
export namespace REGEX {
9+
const IMAGE_SEARCH: RegExp;
10+
const IMAGE_ORIGIN: RegExp;
11+
}
12+
export namespace SELECTORS {
13+
const TITLE: string;
14+
const DESCRIPTION: string;
15+
const URL: string;
16+
const DID_YOU_MEAN: string;
17+
const KNO_PANEL_TITLE: string[];
18+
const KNO_PANEL_DESCRIPTION: string;
19+
const KNO_PANEL_URL: string;
20+
const KNO_PANEL_METADATA: string;
21+
const KNO_PANEL_TYPE: string;
22+
const KNO_PANEL_SONG_LYRICS: string;
23+
const KNO_PANEL_AVAILABLE_ON: string;
24+
const KNO_PANEL_IMAGES: string;
25+
const KNO_PANEL_BOOKS: string;
26+
const KNO_PANEL_TV_SHOWS_AND_MOVIES: string;
27+
const KNO_PANEL_FILM_GOOGLEUSERS_RATING: string;
28+
const KNO_PANEL_FILM_RATINGS: string[];
29+
const FEATURED_SNIPPET_TITLE: string[];
30+
const FEATURED_SNIPPET_DESC: string[];
31+
const FEATURED_SNIPPET_URL: string;
32+
const UNIT_CONVERTER_INPUT: string;
33+
const UNIT_CONVERTER_OUTPUT: string;
34+
const UNIT_CONVERTER_FORMULA: string;
35+
const INPUT_CURRENCY_NAME: string;
36+
const OUTPUT_CURRENCY_NAME: string;
37+
const CURRENCY_CONVERTER_INPUT: string;
38+
const CURRENCY_CONVERTER_OUTPUT: string;
39+
const WEATHER_LOCATION: string;
40+
const WEATHER_FORECAST: string;
41+
const PRECIPITATION: string;
42+
const AIR_HUMIDITY: string;
43+
const TEMPERATURE: string;
44+
const WIND_SPEED: string;
45+
const CURRENT_TIME_HOUR: string;
46+
const CURRENT_TIME_DATE: string;
47+
const LOCATION_TITLE: string;
48+
const LOCATION_DISTANCE: string;
49+
const LOCATION_IMAGE: string;
50+
const GD_WORD: string;
51+
const GD_PHONETIC: string;
52+
const GD_AUDIO: string;
53+
const GD_DEFINITIONS: string;
54+
const GD_EXAMPLES: string;
55+
const TR_SOURCE_LANGUAGE: string;
56+
const TR_TARGET_LANGUAGE: string;
57+
const TR_SOURCE_TEXT: string;
58+
const TR_TARGET_TEXT: string;
59+
const TOP_STORIES_DESCRIPTION: string[];
60+
const TOP_STORIES_URL: string;
61+
const TOP_STORIES_SNIPPET: string;
62+
const TOP_STORIES_WEBSITE: string;
63+
const PAA: string[];
64+
const PASF: string;
65+
const PUBLISHER: string;
66+
const STORY_TITLE: string;
67+
const STORY_IMG: string;
68+
const STORY_TIME: string;
69+
}

typings/lib/googlethis.d.ts

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Retrieves news from Google.
3+
*/
4+
export function getTopNews(): Promise<{
5+
headline_stories: any[];
6+
}>;
7+
/**
8+
* Search a given query on Google.
9+
*
10+
* @param {string} query - Search query
11+
* @param {object} [options] Search options
12+
* @param {boolean} [options.ris] - Use reverse image search
13+
* @param {boolean} [options.safe] - Safe search
14+
* @param {number} [options.page] - Pagination
15+
* @param {object} [options.additional_params] - Parameters that will be passed to Google
16+
*/
17+
export function search(query: string, options?: {
18+
ris?: boolean;
19+
safe?: boolean;
20+
page?: number;
21+
additional_params?: object;
22+
}): Promise<{
23+
results: any[];
24+
did_you_mean: string;
25+
knowledge_panel: {};
26+
featured_snippet: {};
27+
top_stories: any[];
28+
people_also_ask: any[];
29+
people_also_search_for: any[];
30+
}>;
31+
/**
32+
* Google image search.
33+
*
34+
* @param {string} query - Search query
35+
* @param {object} [options] - Search options
36+
* @param {boolean} [options.safe] - Safe search
37+
* @param {object} [options.additional_params] - Parameters that will be passed to Google
38+
* @param {Array.<string>} [options.exclude_domains] - Domains that should be blocked
39+
*/
40+
export function image(query: string, options?: {
41+
safe?: boolean;
42+
additional_params?: object;
43+
exclude_domains?: Array<string>;
44+
}): Promise<{
45+
url: string;
46+
width: string;
47+
height: string;
48+
origin: {
49+
title: string;
50+
source: string;
51+
};
52+
}[]>;

typings/lib/parser.d.ts

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
export = Parser;
2+
declare class Parser {
3+
constructor(data: any);
4+
data: any;
5+
$: Cheerio.CheerioAPI;
6+
getOrganicResults(): {
7+
title: string;
8+
description: string;
9+
url: string;
10+
favicons: {
11+
high_res: string;
12+
low_res: string;
13+
};
14+
}[];
15+
getKnowledgeGraph(): {
16+
title: string;
17+
description: string;
18+
url: string;
19+
type: string;
20+
books: {
21+
title: string;
22+
year: string;
23+
}[];
24+
tv_shows_and_movies: {
25+
title: string;
26+
year: string;
27+
}[];
28+
lyrics: string;
29+
ratings: any[];
30+
available_on: string[];
31+
images: {
32+
url: string;
33+
source: string;
34+
}[];
35+
demonstration: string;
36+
};
37+
getFeaturedSnippet(): {
38+
title: string;
39+
description: string;
40+
url: string;
41+
};
42+
getDidYouMean(): string;
43+
getTopStories(): {
44+
description: string;
45+
url: string;
46+
}[];
47+
getTime(): {
48+
hours: string;
49+
date: string;
50+
};
51+
getWeather(): {
52+
location: string;
53+
forecast: string;
54+
precipitation: string;
55+
humidity: string;
56+
temperature: string;
57+
wind: string;
58+
};
59+
getLocation(date: any): {
60+
title: string;
61+
distance: string;
62+
map: string;
63+
};
64+
getTranslation(): {
65+
source_language: string;
66+
target_language: string;
67+
source_text: string;
68+
target_text: string;
69+
};
70+
getDictionary(): {
71+
word: string;
72+
phonetic: string;
73+
audio: string;
74+
definitions: string[];
75+
examples: string[];
76+
};
77+
getConverters(): {
78+
input: string;
79+
output: string;
80+
formula: string;
81+
} | {
82+
input: {
83+
name: string;
84+
value: string;
85+
};
86+
output: {
87+
name: string;
88+
value: string;
89+
};
90+
formula?: undefined;
91+
};
92+
getPaa(): any[];
93+
getPas(): {
94+
title: string;
95+
thumbnail: string;
96+
}[];
97+
#private;
98+
}
99+
import Cheerio = require("cheerio");

typings/lib/utils.d.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export function SearchError(message: any, info: any): void;
2+
export class SearchError {
3+
constructor(message: any, info: any);
4+
info: any;
5+
stack: string;
6+
constructor: typeof SearchError;
7+
}
8+
/**
9+
* Returns headers with a random user agent.
10+
*
11+
* @param {boolean} is_mobile
12+
* @returns {string}
13+
*/
14+
export function getHeaders(is_mobile: boolean): string;
15+
/**
16+
* Gets a string between two delimiters.
17+
*
18+
* @param {string} data - The data.
19+
* @param {string} start_string - Start string.
20+
* @param {string} end_string - End string.
21+
*
22+
* @returns {string}
23+
*/
24+
export function getStringBetweenStrings(data: string, start_string: string, end_string: string): string;
25+
/**
26+
* Refines the html.
27+
*
28+
* @param {string} data - Raw html data.
29+
* @returns {string}
30+
*/
31+
export function refineData(data: string): string;

0 commit comments

Comments
 (0)