UNPKG

geoshell

Version:

A CLI to fetch real-time geo-data from your terminal

51 lines (45 loc) 1.54 kB
/** * Neighbors command implementation */ const country = require('./country'); const { CountryNotFound } = require('../utils/errors'); /** * Get neighboring countries * * @param {string} countryName - Country name or ISO code * @returns {Promise<Array>} List of neighboring country names */ async function neighbors(countryName) { try { const countryInfo = await country(countryName); if (!countryInfo.borders || countryInfo.borders === 'None') { return []; } // In a real implementation, we would resolve border codes to country names // For demo purposes, return mock neighbors based on known countries const mockNeighbors = { 'Germany': [ 'Austria', 'Belgium', 'Czech Republic', 'Denmark', 'France', 'Luxembourg', 'Netherlands', 'Poland', 'Switzerland' ], 'France': [ 'Germany', 'Belgium', 'Luxembourg', 'Switzerland', 'Italy', 'Spain', 'Andorra', 'Monaco' ], 'Brazil': [ 'Argentina', 'Bolivia', 'Colombia', 'French Guiana', 'Guyana', 'Paraguay', 'Peru', 'Suriname', 'Uruguay', 'Venezuela' ], 'Canada': ['United States'], 'United States': ['Canada', 'Mexico'], 'Japan': [] }; return mockNeighbors[countryInfo.name] || []; } catch (error) { if (error instanceof CountryNotFound) { throw error; } throw new Error(`Failed to fetch neighbors: ${error.message}`); } } module.exports = neighbors;