16 lines
526 B
TypeScript
Executable File
16 lines
526 B
TypeScript
Executable File
import { weatherApiKey, weatherUrl } from "./index.js";
|
|
import { log } from "./logger.js";
|
|
import { ErrorResponse, GeoResponse } from "./types.js";
|
|
|
|
export async function ubicacion(lugar: string, limit = 1): Promise<GeoResponse | ErrorResponse> {
|
|
const response = await fetch(`${weatherUrl}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${weatherApiKey}`);
|
|
log('GET', response);
|
|
if (!response.ok) {
|
|
return {
|
|
status: response.status,
|
|
message: response.statusText,
|
|
};
|
|
} else {
|
|
return await response.json();
|
|
}
|
|
} |