UNPKG

duck-duck-scrape

Version:

Search from DuckDuckGo and use it's spice APIs.

113 lines (112 loc) 3.89 kB
import { NeedleOptions } from 'needle'; import { DuckbarImageResult } from '../types'; import { SafeSearchType, SearchTimeType } from '../util'; import { NewsResult } from './news'; import { VideoResult } from './videos'; /** The options for {@link search}. */ export interface SearchOptions { /** The safe search type of the search. */ safeSearch?: SafeSearchType; /** The time range of the searches, can be a SearchTimeType or a date range ("2021-03-16..2021-03-30") */ time?: SearchTimeType | string; /** The locale(?) of the search. Defaults to "en-us". */ locale?: string; /** The region of the search. Defaults to "wt-wt" or all regions. */ region?: string; /** The market region(?) of the search. Defaults to "US". */ marketRegion?: string; /** The number to offset the results to. */ offset?: number; /** * The string that acts like a key to a search. * Set this if you made a search with the same query. */ vqd?: string; } /** * The search results from {@link search}. * `images`, `news`, `videos` and `related` only show up if the query * shows elements of these in a webpage search. */ export interface SearchResults { /** Whether there were no results found. */ noResults: boolean; /** The VQD of the search query. */ vqd: string; /** The web results of the search. */ results: SearchResult[]; /** The image results of the search. */ images?: DuckbarImageResult[]; /** The news article results of the search. */ news?: NewsResult[]; /** The video results of the search. */ videos?: VideoResult[]; /** The related searches of the query. */ related?: RelatedResult[]; } /** A web search result. */ export interface SearchResult { /** The hostname of the website. (i.e. "google.com") */ hostname: string; /** The URL of the result. */ url: string; /** The title of the result. */ title: string; /** * The sanitized description of the result. * Bold tags will still be present in this string. */ description: string; /** The description of the result. */ rawDescription: string; /** The icon of the website. */ icon: string; /** The ddg!bang information of the website, if any. */ bang?: SearchResultBang; } export interface SearchResultBang { /** The prefix of the bang. (i.e. "w" for !w) */ prefix: string; /** The title of the bang. */ title: string; /** The domain of the bang. */ domain: string; } export interface RelatedResult { text: string; raw: string; } /** * Search something. * @category Search * @param query The query to search with * @param options The options of the search * @param needleOptions The options of the HTTP request * @returns Search results */ export declare function search(query: string, options?: SearchOptions, needleOptions?: NeedleOptions): Promise<SearchResults>; /** An auto-complete term. */ export interface AutocompleteTerm { /** The phrase of the auto-completed term. */ phrase: string; } /** An auto-complete bang. */ export interface AutocompleteBang { /** The image of the bang */ image: string; /** The prefix of the bang. */ phrase: string; score: number; /** The title of the bang. */ snippet: string; } export declare type AutocompleteResult = AutocompleteTerm | AutocompleteBang; /** * Get auto-complete terms from a query. * @category Search * @param query The query to search * @param region The region to search as * @param needleOptions The options of the HTTP request * @returns Autocomplete terms */ export declare function autocomplete(query: string, region?: string, needleOptions?: NeedleOptions): Promise<AutocompleteResult[]>;