UNPKG

@minilibs/ip2geo

Version:

Ip to Geo location instantly ⚡

66 lines (62 loc) 2.73 kB
'use strict'; var CheckVersion = require('../helpers/CheckVersion.js'); var Constants = require('../data/Constants.js'); var Http = require('../helpers/Http.js'); /** * Get geo information from an IP address. * * The function fetches detailed geographical and connection-related information * for a given IP address. The returned data includes properties such as continent, * country, city, timezone, ASN details, and completion time. * * @param ip - The IP address to retrieve geo information for. * @returns A Promise resolving to an object of type `Ip` containing geo and connection details, or `null` if no data is found or something goes wrong. * * @typedef Ip * @property ip - The IP address or null if unavailable. * @property success - Whether the request was successful. * @property type - The type of IP (e.g., IPv4, IPv6) or null. * @property is_eu - Whether the IP is located in the European Union or null. * @property continent - Continent information: * - name - The continent name or null. * - code - The continent code or null. * - country - Country information: * - name - The country name or null. * - code - The country code or null. * - phone_code - The country phone code or null. * - capital - The capital city or null. * - tld - The country top-level domain or null. * - city - City information: * - name - The city name or null. * - latitude - The city's latitude coordinate or null. * - longitude - The city's longitude coordinate or null. * - postal_code - The postal code or null. * - timezone - Timezone information: * - name - The timezone name or null. * - time_now - The current time in the timezone or null. * - flag - Country flag information: * - img - The URL of the flag image or null. * - emoji - The flag emoji or null. * - emoji_unicode - The Unicode representation of the flag emoji or null. * - currency - Currency information: * - name - The currency name or null. * - code - The currency code or null. * - symbol - The currency symbol or null. * @property asn - Autonomous system number information: * - number - The ASN number or null. * - name - The ASN name or null. * @property completion_time - Request completion time: * - miliseconds - Time in milliseconds or null. * - seconds - Time in seconds or null. */ const GetGeoFromIP = async (ip) => { CheckVersion(); const ipLink = `${Constants.API_ENDPOINT}/${ip}`; const ipResponse = await Http(ipLink); if (ipResponse) { const instance = ipResponse; return instance; } return null; }; module.exports = GetGeoFromIP;