smartstring/dist/smartstring.git.js

46 lines
3.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* ---------------------------------------------- *
* ------------------ classes ------------------- *
* ---------------------------------------------- */
class GitRepo {
constructor(stringArg, tokenArg) {
let regexMatches = gitRegex(stringArg);
this.host = regexMatches[1];
this.user = regexMatches[2];
this.repo = regexMatches[3];
this.accessToken = tokenArg;
this.sshUrl = gitLink(this.host, this.user, this.repo, this.accessToken, 'ssh');
this.httpsUrl = gitLink(this.host, this.user, this.repo, this.accessToken, 'https');
}
}
exports.GitRepo = GitRepo;
/* ---------------------------------------------- *
* ------------------ helpers ------------------- *
* ---------------------------------------------- */
let gitRegex = function (stringArg) {
let regexString = /([a-zA-Z0-9\-\.]*)(?:\/|\:)([a-zA-Z0-9\-\.]*)(?:\/)([a-zA-Z0-9\-\.]*)(?:\.git)/;
let regexMatches = regexString.exec(stringArg);
return regexMatches;
};
let gitLink = function (hostArg, userArg, repoArg, tokenArg = '', linkTypeArg) {
let returnString;
if (tokenArg !== '') {
tokenArg = tokenArg + '@';
}
switch (linkTypeArg) {
case 'https':
returnString = 'https://' +
tokenArg + hostArg + '/' + userArg + '/' + repoArg + '.git';
break;
case 'ssh':
returnString = 'git@' +
hostArg + ':' + userArg + '/' + repoArg + '.git';
break;
default:
console.error('Link Type ' + linkTypeArg + ' not known');
break;
}
return returnString;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuZ2l0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuZ2l0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7O29EQUVvRDtBQUNwRDtJQU9FLFlBQWEsU0FBaUIsRUFBRSxRQUFpQjtRQUMvQyxJQUFJLFlBQVksR0FBRyxRQUFRLENBQUMsU0FBUyxDQUFDLENBQUE7UUFDdEMsSUFBSSxDQ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