poe-api-manager
Version:
poe.ninja and poe.watch API
35 lines (34 loc) • 1.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const watchFetch_1 = __importDefault(require("../fetch/watchFetch"));
const propertyFilter_1 = __importDefault(require("../../../mainfunctions/propertyFilter"));
/**
* Retrieves data from the specified URL, optionally filtering based on requested properties.
*
* @param league - The league from which the data will be fetched.
* @param type - The type of data to be fetched.
* @param requestedProperties - An optional array of property names to filter the data.
* @returns - A promise that resolves to the fetched or filtered data.
* @throws - Throws an error if there is an issue fetching or filtering the data.
*/
async function getData(league, type, requestedProperties) {
try {
const fetchedData = await (0, watchFetch_1.default)(league, type);
// If requestedProperties are specified, filter the data based on those properties
if (requestedProperties && requestedProperties.length > 0) {
const result = (0, propertyFilter_1.default)(fetchedData, requestedProperties);
return result;
}
else {
// If no specific properties are requested, return the entire fetched data
return fetchedData;
}
}
catch (error) {
throw new Error(`Error fetching data: ${error.message}`);
}
}
exports.default = getData;