UNPKG

aiwebfinances

Version:

Display pricing that covers country inflation

24 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchInflationData = fetchInflationData; async function fetchInflationData(countryCode) { const WORLD_BANK_INFLATION_API = `https://api.worldbank.org/v2/country/${countryCode}/indicator/FP.CPI.TOTL.ZG?format=json`; try { const response = await fetch(WORLD_BANK_INFLATION_API); // Check if the response is okay (status 200) if (!response.ok) { throw new Error(`Error fetching inflation data: ${response.statusText}`); } // Parse the JSON response const data = await response.json(); // The most recent data for Ireland is in data[1][0] const inflationData = data[1][0]; const inflationRate = inflationData.value; return inflationRate; // Return the inflation rate } catch (error) { console.error("Error fetching inflation data:", error); throw new Error("Failed to fetch inflation data"); } } //# sourceMappingURL=InflationFetcher.js.map