UNPKG

enka-network-api

Version:

Enka-network API wrapper for Genshin Impact.

46 lines (45 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImageAssets = void 0; class ImageAssets { constructor(name, enka, maxPriority = Number.POSITIVE_INFINITY) { var _a; this.enka = enka; this.name = name !== "" ? name : null; this.imageBaseUrl = (_a = enka.options.imageBaseUrls .filter(url => url.priority <= maxPriority) .sort((a, b) => b.priority - a.priority) .find(url => { if (this.name === null) return false; if (!url.regexList.some(regex => regex.test(this.name))) return false; if ("customParser" in url) { if (url.customParser(this.name) == null) return false; } return true; })) !== null && _a !== void 0 ? _a : null; this.url = (() => { if (this.name === null || this.imageBaseUrl == null) return null; if ("customParser" in this.imageBaseUrl) { const filePath = this.imageBaseUrl.customParser(this.name); if (filePath == null) return null; return `${this.imageBaseUrl.url}/${filePath}`; } return `${this.imageBaseUrl.url}/${this.name}.${this.imageBaseUrl.format.toLowerCase()}`; })(); this.isAvailable = this.url !== null && this.url !== undefined && this.url !== ""; } /** * @returns a new instance of ImageAssets with the another imageBaseUrl */ nextSource() { if (this.imageBaseUrl == null) return null; return new ImageAssets(this.name, this.enka, this.imageBaseUrl.priority - 1); } } exports.ImageAssets = ImageAssets;