"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseIndexDir = parseIndexDir;
exports.normalizeRootRelativeUrls = normalizeRootRelativeUrls;
exports.getLatestVersion = getLatestVersion;
const array_1 = require("../../../util/array");
const regex_1 = require("../../../util/regex");
const compare_1 = require("../../versioning/maven/compare");
const linkRegExp = /(?<=href=['"])[^'"]*(?=\/['"])/gi;
function parseIndexDir(content, filterFn = (x) => !(0, regex_1.regEx)(/^\.+/).test(x)) {
    const unfiltered = (0, array_1.coerceArray)(content.match(linkRegExp));
    return unfiltered.filter(filterFn);
}
function normalizeRootRelativeUrls(content, rootUrl) {
    const rootRelativePath = new URL(rootUrl.toString()).pathname;
    return content.replace(linkRegExp, (href) => href.replace(rootRelativePath, ''));
}
function getLatestVersion(versions) {
    if (versions?.length) {
        return versions.reduce((latestVersion, version) => (0, compare_1.compare)(version, latestVersion) === 1 ? version : latestVersion);
    }
    return null;
}
//# sourceMappingURL=util.js.map