<commit_before>/**
 * GitUrlParse
 * Parses a Git url.
 *
 * @name GitUrlParse
 * @function
 * @param {String} url The Git url to parse.
 * @return {GitUrl} The `GitUrl` object containing:
 *
 *  - `protocol` (String): The url protocol.
 *  - `source` (String): The Git provider (e.g. `"github.com"`).
 *  - `owner` (String): The repository owner.
 *  - `name` (String): The repository name.
 *  - `_` (String): The original url which was parsed.
 *  - `toString` (Function): A function to stringify the parsed url into another url type.
 */
function GitUrlParse(url) {

    if (typeof url !== "string") {
        throw new Error("The url must be a string.");
    }

    var urlInfo = {
            protocol: null
          , source: null
          , owner: null
          , name: null
          , _: url
          , toString: function (type) {
                return GitUrlParse.stringify(this, type);
            }
        }
      , match = null
      ;

    // SSH protocol
    check_git: if (/^git\@/.test(url)) {
        match = url.match(/^git@(.*):(.*)\/(.*).git$/);
        if (!match) { break check_git; }
        urlInfo.source = match[1];
        urlInfo.owner = match[2];
        urlInfo.name = match[3];
        urlInfo.protocol = "ssh";
    } else

    // HTTP(S) protocol
    check_https: if (/^https?:\/\//.test(url)) {
        url = url.replace(/(\/|\.git)$/, "");
        match = url.match(/^(https?):\/\/(.*)\/(.*)\/(.*)\/?$/);
        if (!match) { break check_https; }
        urlInfo.protocol = match[1];
        urlInfo.source = match[2];
        urlInfo.owner = match[3];
        urlInfo.name = match[4];
    } else {
        urlInfo.protocol = "file";
        // Feel free to add more parsers
    }

    return urlInfo;
}

/**
 * stringify
 * Stringifies a `GitUrl` object.
 *
 * @name stringify
 * @function
 * @param {GitUrl} obj The parsed Git url object.
 * @param {String} type The type of the stringified url (default `obj.protocol`).
 * @return {String} The stringified url.
 */
GitUrlParse.stringify = function (obj, type) {
    type = type || obj.protocol;
    switch (type) {
        case "ssh":
            return "git@" + obj.source + ":" + obj.owner + "/" + obj.name + ".git";
        case "http":
        case "https":
            return type + "://" + obj.source + "/" + obj.owner + "/" + obj.name + ".git";
        default:<commit_msg>Handle the git+ssh protocol<commit_after>/**
 * GitUrlParse
 * Parses a Git url.
 *
 * @name GitUrlParse
 * @function
 * @param {String} url The Git url to parse.
 * @return {GitUrl} The `GitUrl` object containing:
 *
 *  - `protocol` (String): The url protocol.
 *  - `source` (String): The Git provider (e.g. `"github.com"`).
 *  - `owner` (String): The repository owner.
 *  - `name` (String): The repository name.
 *  - `_` (String): The original url which was parsed.
 *  - `toString` (Function): A function to stringify the parsed url into another url type.
 */
function GitUrlParse(url) {

    if (typeof url !== "string") {
        throw new Error("The url must be a string.");
    }

    var urlInfo = {
            protocol: null
          , source: null
          , owner: null
          , name: null
          , _: url
          , toString: function (type) {
                return GitUrlParse.stringify(this, type);
            }
        }
      , match = null
      ;

    // SSH protocol
    check_git: if (/^git\@/.test(url)) {
        match = url.match(/^git@(.*):(.*)\/(.*).git$/);
        if (!match) { break check_git; }
        urlInfo.source = match[1];
        urlInfo.owner = match[2];
        urlInfo.name = match[3];
        urlInfo.protocol = "ssh";
    } else

    // HTTP(S) protocol
    check_https: if (/^https?:\/\//.test(url)) {
        url = url.replace(/(\/|\.git)$/, "");
        match = url.match(/^(https?):\/\/(.*)\/(.*)\/(.*)\/?$/);
        if (!match) { break check_https; }
        urlInfo.protocol = match[1];
        urlInfo.source = match[2];
        urlInfo.owner = match[3];
        urlInfo.name = match[4];
    } else

    // git+ssh protocol
    check_gitssh: if (/^git\+ssh:\/\/git\@/.test(url)) {
        url = url.replace(/\.git$/, "");
        match = url.match(/^git\+ssh:\/\/git\@(.*)\/(.*)\/(.*)\/?$/);
        if (!match) { break check_gitssh; }
        urlInfo.protocol = "git+ssh";
        urlInfo.source = match[1];
        urlInfo.owner = match[2];
        urlInfo.name = match[3];
    } else {
        urlInfo.protocol = "file";
        // Feel free to add more parsers
    }

    return urlInfo;
}

/**
 * stringify
 * Stringifies a `GitUrl` object.
 *
 * @name stringify
 * @function
 * @param {GitUrl} obj The parsed Git url object.
 * @param {String} type The type of the stringified url (default `obj.protocol`).
 * @return {String} The stringified url.
 */
GitUrlParse.stringify = function (obj, type) {
    type = type || obj.protocol;
    switch (type) {
        case "ssh":
            return "git@" + obj.source + ":" + obj.owner + "/" + obj.name + ".git";
        case "http":
        case "https":
            return type + "://" + obj.source + "/" + obj.owner + "/" + obj.name + ".git";
        default:
{'fraction_non_alphanumeric': 0.18063639891346528, 'fraction_numerical': 0.0032984090027163367, 'mean_word_length': 1.9814921920185078, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6664391', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1641, 'n_words': 444}