🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

git-url-parse

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-url-parse - npm Package Compare versions

Comparing version

to
15.0.0

85

lib/index.js

@@ -12,2 +12,6 @@ "use strict";

* @param {String} url The Git url to parse.
* @param {Array} refs An array of strings representing the refs. This is
* helpful in the context of the URLs that contain branches with slashes.
* If user wants to identify the branch, he should pass all branch names
* of the project as part of refs parameter
* @return {GitUrl} The `GitUrl` object containing:

@@ -37,3 +41,4 @@ *

*/
function gitUrlParse(url) {
function gitUrlParse(url, refs) {
refs = refs || [];

@@ -44,2 +49,8 @@ if (typeof url !== "string") {

if (!refs.every(function (item) {
return typeof item === "string";
})) {
throw new Error("The refs should contain only strings");
}
var shorthandRe = /^([a-z\d-]{1,39})\/([-\.\w]{1,100})$/i;

@@ -64,3 +75,3 @@

urlInfo.git_suffix = /\.git$/.test(urlInfo.pathname);
urlInfo.name = decodeURIComponent((urlInfo.pathname || urlInfo.href).replace(/(^\/)|(\/$)/g, '').replace(/\.git$/, ""));
urlInfo.name = decodeURIComponent((urlInfo.pathname || urlInfo.href).replace(/(^\/)|(\/$)/g, "").replace(/\.git$/, ""));
urlInfo.owner = decodeURIComponent(urlInfo.user);

@@ -76,3 +87,3 @@

// Handle VSTS SSH URLs
if (urlInfo.resource === 'vs-ssh.visualstudio.com') {
if (urlInfo.resource === "vs-ssh.visualstudio.com") {
splits = urlInfo.name.split("/");

@@ -83,3 +94,3 @@ if (splits.length === 4) {

urlInfo.name = splits[3];
urlInfo.full_name = splits[2] + '/' + splits[3];
urlInfo.full_name = splits[2] + "/" + splits[3];
}

@@ -92,12 +103,12 @@ break;

urlInfo.name = splits[1];
urlInfo.full_name = '_git/' + urlInfo.name;
urlInfo.full_name = "_git/" + urlInfo.name;
} else if (splits.length === 3) {
urlInfo.name = splits[2];
if (splits[0] === 'DefaultCollection') {
if (splits[0] === "DefaultCollection") {
urlInfo.owner = splits[2];
urlInfo.organization = splits[0];
urlInfo.full_name = urlInfo.organization + '/_git/' + urlInfo.name;
urlInfo.full_name = urlInfo.organization + "/_git/" + urlInfo.name;
} else {
urlInfo.owner = splits[0];
urlInfo.full_name = urlInfo.owner + '/_git/' + urlInfo.name;
urlInfo.full_name = urlInfo.owner + "/_git/" + urlInfo.name;
}

@@ -108,3 +119,3 @@ } else if (splits.length === 4) {

urlInfo.name = splits[3];
urlInfo.full_name = urlInfo.organization + '/' + urlInfo.owner + '/_git/' + urlInfo.name;
urlInfo.full_name = urlInfo.organization + "/" + urlInfo.owner + "/_git/" + urlInfo.name;
}

@@ -117,3 +128,3 @@ break;

case "azure.com":
if (urlInfo.resource === 'ssh.dev.azure.com') {
if (urlInfo.resource === "ssh.dev.azure.com") {
splits = urlInfo.name.split("/");

@@ -132,12 +143,12 @@ if (splits.length === 4) {

urlInfo.name = splits[4];
urlInfo.full_name = '_git/' + urlInfo.name;
urlInfo.full_name = "_git/" + urlInfo.name;
} else if (splits.length === 3) {
urlInfo.name = splits[2];
if (splits[0] === 'DefaultCollection') {
if (splits[0] === "DefaultCollection") {
urlInfo.owner = splits[2];
urlInfo.organization = splits[0];
urlInfo.full_name = urlInfo.organization + '/_git/' + urlInfo.name;
urlInfo.full_name = urlInfo.organization + "/_git/" + urlInfo.name;
} else {
urlInfo.owner = splits[0];
urlInfo.full_name = urlInfo.owner + '/_git/' + urlInfo.name;
urlInfo.full_name = urlInfo.owner + "/_git/" + urlInfo.name;
}

@@ -148,10 +159,10 @@ } else if (splits.length === 4) {

urlInfo.name = splits[3];
urlInfo.full_name = urlInfo.organization + '/' + urlInfo.owner + '/_git/' + urlInfo.name;
urlInfo.full_name = urlInfo.organization + "/" + urlInfo.owner + "/_git/" + urlInfo.name;
}
if (urlInfo.query && urlInfo.query['path']) {
urlInfo.filepath = urlInfo.query['path'].replace(/^\/+/g, ''); // Strip leading slash (/)
if (urlInfo.query && urlInfo.query["path"]) {
urlInfo.filepath = urlInfo.query["path"].replace(/^\/+/g, ""); // Strip leading slash (/)
}
if (urlInfo.query && urlInfo.query['version']) {
if (urlInfo.query && urlInfo.query["version"]) {
// version=GB<branch>
urlInfo.ref = urlInfo.query['version'].replace(/^GB/, ''); // remove GB
urlInfo.ref = urlInfo.query["version"].replace(/^GB/, ""); // remove GB
}

@@ -174,3 +185,3 @@ break;

urlInfo.owner = splits.slice(0, nameIndex).join('/');
urlInfo.owner = splits.slice(0, nameIndex).join("/");
urlInfo.name = splits[nameIndex];

@@ -191,3 +202,3 @@ if (commitIndex && issuesIndex < 0) {

if (splits.length > offsetNameIndex + 3) {
urlInfo.filepath = splits.slice(offsetNameIndex + 3).join('/');
urlInfo.filepath = splits.slice(offsetNameIndex + 3).join("/");
}

@@ -232,3 +243,3 @@ }

if (splits.length > 2) {
urlInfo.filepath = splits.slice(2).join('/');
urlInfo.filepath = splits.slice(2).join("/");
}

@@ -247,2 +258,8 @@ } else if (splits[1] === "commits" && splits.length > 2) {

}
if (refs.length !== 0 && urlInfo.ref) {
urlInfo.ref = findLongestMatchingSubstring(urlInfo.href, refs) || urlInfo.ref;
urlInfo.filepath = urlInfo.href.split(urlInfo.ref + "/")[1];
}
return urlInfo;

@@ -262,5 +279,5 @@ }

gitUrlParse.stringify = function (obj, type) {
type = type || (obj.protocols && obj.protocols.length ? obj.protocols.join('+') : obj.protocol);
var port = obj.port ? ":" + obj.port : '';
var user = obj.user || 'git';
type = type || (obj.protocols && obj.protocols.length ? obj.protocols.join("+") : obj.protocol);
var port = obj.port ? ":" + obj.port : "";
var user = obj.user || "git";
var maybeGitSuffix = obj.git_suffix ? ".git" : "";

@@ -277,3 +294,3 @@ switch (type) {

case "https":
var auth = obj.token ? buildToken(obj) : obj.user && (obj.protocols.includes('http') || obj.protocols.includes('https')) ? obj.user + "@" : "";
var auth = obj.token ? buildToken(obj) : obj.user && (obj.protocols.includes("http") || obj.protocols.includes("https")) ? obj.user + "@" : "";
return type + "://" + auth + obj.resource + port + "/" + buildPath(obj) + maybeGitSuffix;

@@ -309,5 +326,5 @@ default:

// Note: Re-encode the repository and owner names for hosting services that allow whitespace characters
var encoded_full_name = obj.full_name.split('/').map(function (x) {
var encoded_full_name = obj.full_name.split("/").map(function (x) {
return encodeURIComponent(x);
}).join('/');
}).join("/");

@@ -318,2 +335,14 @@ return encoded_full_name;

function findLongestMatchingSubstring(string, array) {
var longestMatch = "";
array.forEach(function (item) {
if (string.includes(item) && item.length > longestMatch.length) {
longestMatch = item;
}
});
return longestMatch;
}
module.exports = gitUrlParse;
{
"name": "git-url-parse",
"version": "14.1.0",
"version": "15.0.0",
"description": "A high level git url parser for common git providers.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -176,3 +176,3 @@ <!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->

### `gitUrlParse(url)`
### `gitUrlParse(url, refs)`
Parses a Git url.

@@ -183,2 +183,5 @@

- **String** `url`: The Git url to parse.
- **Array** `refs`: An array of strings representing the refs. This is helpful in the context of the URLs that contain branches with slashes.
If user wants to identify the branch, he should pass all branch names
of the project as part of refs parameter

@@ -373,6 +376,7 @@ #### Return

- `@navabi/react-native-ssl-pinning`
- `@npm_fluentco/adflow-react-native-sdk`
- `@nuxt/telemetry`
- `@nuxt/ui-pro`
- `@nuxthq/studio`
- `@oiti/rn-liveness2d`
- `@oumi/block-sdk`
- `@oumi/cli-ui`

@@ -423,2 +427,3 @@ - `@pageshare/cli`

- `@strapi/strapi`
- `@tahul/ui-fix`
- `@taingo97/react-native-rsa-expo`

@@ -516,3 +521,2 @@ - `@taingo97/react-native-sunmi-printer`

- `gitlab-ci-variables-cli`
- `griffin-ui-library`
- `gtni`

@@ -591,2 +595,3 @@ - `harry-reporter`

- `react-native-fedlight-dsm`
- `react-native-flyy`
- `react-native-ghn-ekyc`

@@ -611,3 +616,2 @@ - `react-native-innity-remaster`

- `react-native-nice-learning`
- `react-native-package-demo-yash-tech`
- `react-native-paynow-generator`

@@ -614,0 +618,0 @@ - `react-native-payu-payment-testing`