UNPKG

poe-api-manager

Version:
35 lines (34 loc) 1.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fetchData_1 = __importDefault(require("../fetch/fetchData")); /** * Retrieves quick currency data for a specific currency in a given league and type. * @param league - The league for which to fetch currency data. * @param typeName - The type of currency data to fetch. * @param type - The type of currency data to fetch. * @param currencyTypeName - The currencyTypeName of the currency to fetch data for. * @returns {Promise<{currencyTypeName: string, chaosEquivalent: number}>} An object containing the currency type name and its chaos equivalent. * @throws Throws an error if the currency data cannot be fetched or if the currency is not found. */ async function getQuickCurrency(league, typeName, type, currencyTypeName) { try { const fetchedData = await (0, fetchData_1.default)(league, typeName, type); //find the currencyTypeName in the fetchedData for (const data of fetchedData) { if (data.currencyTypeName === currencyTypeName) { return { currencyTypeName: data.currencyTypeName, chaosEquivalent: data.chaosEquivalent, }; } } throw new Error("Currency not found"); } catch (error) { throw new Error(`Error fetching currency data: ${error.message}`); } } exports.default = getQuickCurrency;