"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.githubPathAdapter = void 0;
function githubPathAdapter(path) {
    const githubusercontent = 'https://raw.githubusercontent.com/';
    const githubcom = 'https://github.com/';
    const datapackage = '/datapackage.json';
    const dotgit = '.git';
    const howManySlashes = (str) => (str.match(/\//g) || []).length;
    if (path.startsWith(githubusercontent)) {
        if (path.endsWith(datapackage)) {
            path = path.replace(datapackage, '');
        }
        if (path.endsWith('/')) {
            path = path.replace(/.$/, '');
        }
        if (howManySlashes(path) === 4) {
            path = path + '/master';
        }
        return path;
    }
    else if (path.startsWith(githubcom)) {
        if (path.endsWith(dotgit)) {
            path = path.replace(dotgit, '');
        }
        if (path.endsWith(datapackage)) {
            path = path.replace(datapackage, '');
        }
        if (path.endsWith('/')) {
            path = path.replace(/.$/, '');
        }
        path = path.replace(githubcom, githubusercontent);
        if (path.includes('/blob')) {
            path = path.replace('/blob', '');
        }
        if (howManySlashes(path) === 4) {
            path = path + '/master';
        }
        return path;
    }
    else {
        return path;
    }
}
exports.githubPathAdapter = githubPathAdapter;
//# sourceMappingURL=github-path-adapter.js.map