UNPKG

@airplanegobrr/jackett-api

Version:
23 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Commons = void 0; const constants_1 = require("./constants"); const urlJoin = require("url-join"); class Commons { static buildUrl(path, connectSetting, data) { const url = urlJoin(connectSetting.baseUrl, path.prefix, `?${constants_1.Constants.jackettAPI.apiParam}=${connectSetting.apiKey}`, path.suffix !== undefined ? `&${path.suffix}` : ""); return data ? this.buildPlaceHolders(url, data) : url; } /** * Replaces placeholders in input string with matching params from data object. * * @param input string to replace its placeholders with data. Each placeholder should have a prefix & suffix of "%". Ex. "%PLACEHOLDER%" * @param data Object that contains the source of data to fill the placeholders on the input string. Each parameter key should have a prefix & suffix of "%". Ex. "%PLACEHOLDER%" * @return input Parsed string of the input & data. */ static buildPlaceHolders(input, data) { return input.replace(/%\w+%/g, (all) => (all in data ? data[all] : all)); } } exports.Commons = Commons; //# sourceMappingURL=commons.js.map