"use strict";
const url = require("url");
const assert = require("assert");
const semverRegex = require("semver-regex");
const parseUrl = url.parse;
function default_1(url) {
    assert(url, 'url is required');
    assert(typeof url === 'string', 'url should be a string');
    const urlObject = parseUrl(url);
    const pkg = urlObject.path && parsePath(urlObject.path);
    if (!pkg || !urlObject.host)
        return null;
    return {
        host: urlObject.host,
        pkg,
    };
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
function parsePath(path) {
    const name = getName(path);
    if (!name)
        return null;
    const version = getVersion(path);
    if (!version)
        return null;
    return { name, version };
}
function getName(path) {
    const parts = path.split('/-/');
    if (parts.length !== 2)
        return null;
    return parts[0] && parts[0].substr(1);
}
function getVersion(path) {
    const pathWithNoExtension = path.replace(/\.tgz$/, '');
    const matches = pathWithNoExtension.match(semverRegex());
    return matches && matches[matches.length - 1];
}
//# sourceMappingURL=index.js.map