UNPKG

google-places-core

Version:

A lightweight Google Places API logic library.

105 lines (99 loc) 2.9 kB
interface GooglePlacePredictionT { place_id: string; description: string; structured_formatting: { main_text: string; secondary_text: string; }; types: string[]; } interface GooglePlaceDetailsT { geometry: { location: { lat: number; lng: number; }; viewport?: { south: number; west: number; north: number; east: number; }; }; formatted_address: string; name?: string; place_id: string; address_components?: Array<{ long_name: string; short_name: string; types: string[]; }>; types?: string[]; } interface GooglePlacesServiceT { fetchPredictions(input: string): Promise<GooglePlacePredictionT[]>; fetchPlaceDetails(placeId: string): Promise<GooglePlaceDetailsT>; } interface GooglePlacesManagerState { predictions: GooglePlacePredictionT[]; isLoading: boolean; error: Error | null; } declare class GooglePlacesManager { private state; private subscribers; private placesService; private debouncedGetPredictions; constructor(service: GooglePlacesServiceT, debounceTime?: number); private setState; private fetchPredictionsInternal; updateSearchInput(input: string): void; getPlaceDetails(placeId: string): Promise<GooglePlaceDetailsT>; subscribe(callback: (state: GooglePlacesManagerState) => void): () => void; getState(): GooglePlacesManagerState; destroy(): void; } interface StrategyConfig { countryRestrictions?: string[]; locationBias?: { center: { latitude: number; longitude: number; }; radius: number; }; languageCode?: string; } interface GooglePlacesConfig extends StrategyConfig { apiKey: string; enableLogging?: boolean; } declare class GooglePlacesService implements GooglePlacesServiceT { private apiKey; private config; private placeDetailsStrategy; private enableLogging; constructor(config: GooglePlacesConfig); fetchPredictions(input: string): Promise<GooglePlacePredictionT[]>; fetchPlaceDetails(placeId: string): Promise<GooglePlaceDetailsT>; private getLocationBias; private getRegionRestriction; private handleApiError; private transformPredictions; private log; } declare function createGooglePlacesManager(apiKey: string, options?: { debounceTime?: number; countryRestrictions?: string[]; locationBias?: { center: { latitude: number; longitude: number; }; radius: number; }; languageCode?: string; enableLogging?: boolean; }): GooglePlacesManager; export { GooglePlacesManager, GooglePlacesService, createGooglePlacesManager }; export type { GooglePlaceDetailsT, GooglePlacePredictionT, GooglePlacesManagerState };