Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
parse-github-url
Advanced tools
The parse-github-url npm package is a utility for parsing GitHub repository URLs into their component parts. It helps in extracting information such as the owner, repository name, branch, and file path from a given GitHub URL.
Parse GitHub URL
This feature allows you to parse a GitHub URL and extract its components such as the owner, repository name, and more. The code sample demonstrates how to use the package to parse a GitHub URL and log the parsed components.
const parse = require('parse-github-url');
const parsed = parse('https://github.com/IonicaBizau/parse-github-url');
console.log(parsed);
Extract Owner and Repository
This feature allows you to specifically extract the owner and repository name from a GitHub URL. The code sample shows how to parse the URL and log the owner and repository name.
const parse = require('parse-github-url');
const { owner, name } = parse('https://github.com/IonicaBizau/parse-github-url');
console.log(`Owner: ${owner}, Repository: ${name}`);
Handle Different URL Formats
This feature demonstrates the package's ability to handle different GitHub URL formats, including those with different protocols and extensions. The code sample shows how to parse a URL with the 'git+' protocol and '.git' extension.
const parse = require('parse-github-url');
const parsed = parse('git+https://github.com/IonicaBizau/parse-github-url.git');
console.log(parsed);
The github-url-to-object package converts GitHub URLs to objects containing useful information like owner, name, and branch. It is similar to parse-github-url but also includes additional properties like API URLs and HTTPS URLs.
The parse-repo package parses repository URLs from various hosting services, including GitHub. It provides a more generalized solution compared to parse-github-url, which is specific to GitHub.
The git-url-parse package parses Git URLs and supports multiple Git hosting services, including GitHub, GitLab, and Bitbucket. It offers a broader range of functionality compared to parse-github-url, which is focused solely on GitHub.
Parse a github URL into an object.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
$ npm install --save parse-github-url
Why another GitHub URL parser library?
Seems like every lib I've found does too much, like both stringifying and parsing, or converts the URL from one format to another, only returns certain segments of the URL except for what I need, yields inconsistent results or has poor coverage.
var gh = require('parse-github-url');
gh('https://github.com/jonschlinkert/micromatch');
Results in:
{
"owner": "jonschlinkert",
"name": "micromatch",
"repo": "jonschlinkert/micromatch",
"branch": "master"
}
Generated results from test fixtures:
// assemble/verb#1.2.3
Url {
protocol: null,
slashes: null,
auth: null,
host: 'github.com',
port: null,
hostname: null,
hash: '#1.2.3',
search: null,
query: null,
pathname: 'assemble/verb',
path: 'assemble/verb',
href: 'assemble/verb#1.2.3',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: '1.2.3',
repository: 'assemble/verb' }
// assemble/verb#branch
Url {
protocol: null,
slashes: null,
auth: null,
host: 'github.com',
port: null,
hostname: null,
hash: '#branch',
search: null,
query: null,
pathname: 'assemble/verb',
path: 'assemble/verb',
href: 'assemble/verb#branch',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'branch',
repository: 'assemble/verb' }
// assemble/verb
Url {
protocol: null,
slashes: null,
auth: null,
host: 'github.com',
port: null,
hostname: null,
hash: null,
search: null,
query: null,
pathname: 'assemble/verb',
path: 'assemble/verb',
href: 'assemble/verb',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git+https://github.com/assemble/verb.git
Url {
protocol: 'git+https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'git+https://github.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git+ssh://github.com/assemble/verb.git
Url {
protocol: 'git+ssh:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'git+ssh://github.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git://gh.pages.com/assemble/verb.git
Url {
protocol: 'git:',
slashes: true,
auth: null,
host: 'gh.pages.com',
port: null,
hostname: 'gh.pages.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'git://gh.pages.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git://github.assemble.com/assemble/verb.git
Url {
protocol: 'git:',
slashes: true,
auth: null,
host: 'github.assemble.com',
port: null,
hostname: 'github.assemble.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'git://github.assemble.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git://github.assemble.two.com/assemble/verb.git
Url {
protocol: 'git:',
slashes: true,
auth: null,
host: 'github.assemble.two.com',
port: null,
hostname: 'github.assemble.two.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'git://github.assemble.two.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git://github.com/assemble/verb
Url {
protocol: 'git:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb',
path: 'assemble/verb',
href: 'git://github.com/assemble/verb',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git://github.com/assemble/verb.git
Url {
protocol: 'git:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'git://github.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git@gh.pages.com:assemble/verb.git
Url {
protocol: null,
slashes: null,
auth: null,
host: 'gh.pages.com',
port: null,
hostname: null,
hash: null,
search: null,
query: null,
pathname: 'git@gh.pages.com:assemble/verb.git',
path: 'git@gh.pages.com:assemble/verb.git',
href: 'git@gh.pages.com:assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// git@github.com:assemble/verb.git#1.2.3
Url {
protocol: null,
slashes: null,
auth: null,
host: 'github.com',
port: null,
hostname: null,
hash: '#1.2.3',
search: null,
query: null,
pathname: 'git@github.com:assemble/verb.git',
path: 'git@github.com:assemble/verb.git',
href: 'git@github.com:assemble/verb.git#1.2.3',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: '1.2.3',
repository: 'assemble/verb' }
// git@github.com:assemble/verb.git#v1.2.3
Url {
protocol: null,
slashes: null,
auth: null,
host: 'github.com',
port: null,
hostname: null,
hash: '#v1.2.3',
search: null,
query: null,
pathname: 'git@github.com:assemble/verb.git',
path: 'git@github.com:assemble/verb.git',
href: 'git@github.com:assemble/verb.git#v1.2.3',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'v1.2.3',
repository: 'assemble/verb' }
// git@github.com:assemble/verb.git
Url {
protocol: null,
slashes: null,
auth: null,
host: 'github.com',
port: null,
hostname: null,
hash: null,
search: null,
query: null,
pathname: 'git@github.com:assemble/verb.git',
path: 'git@github.com:assemble/verb.git',
href: 'git@github.com:assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// github:assemble/verb
Url {
protocol: 'github:',
slashes: null,
auth: null,
host: 'assemble',
port: null,
hostname: 'assemble',
hash: null,
search: null,
query: null,
pathname: 'verb',
path: 'verb',
href: 'github:assemble/verb',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// http://github.com/assemble
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble',
path: 'assemble',
href: 'http://github.com/assemble',
filepath: null,
owner: 'assemble',
name: null,
repo: null,
branch: 'master',
repository: null }
// http://github.com/assemble/verb
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb',
path: 'assemble/verb',
href: 'http://github.com/assemble/verb',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// http://github.com/assemble/verb.git
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'http://github.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// http://github.com/assemble/verb/tree
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/tree',
path: 'assemble/verb/tree',
href: 'http://github.com/assemble/verb/tree',
filepath: null,
branch: 'tree',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb' }
// http://github.com/assemble/verb/tree/master
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/tree/master',
path: 'assemble/verb/tree/master',
href: 'http://github.com/assemble/verb/tree/master',
filepath: null,
branch: 'master',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb' }
// http://github.com/assemble/verb/tree/master/foo/bar
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/tree/master/foo/bar',
path: 'assemble/verb/tree/master/foo/bar',
href: 'http://github.com/assemble/verb/tree/master/foo/bar',
filepath: null,
branch: 'master',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb' }
// https://assemble.github.com/assemble/verb/somefile.tar.gz
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'assemble.github.com',
port: null,
hostname: 'assemble.github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/somefile.tar.gz',
path: 'assemble/verb/somefile.tar.gz',
href: 'https://assemble.github.com/assemble/verb/somefile.tar.gz',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'somefile.tar.gz',
repository: 'assemble/verb' }
// https://assemble.github.com/assemble/verb/somefile.zip
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'assemble.github.com',
port: null,
hostname: 'assemble.github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/somefile.zip',
path: 'assemble/verb/somefile.zip',
href: 'https://assemble.github.com/assemble/verb/somefile.zip',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'somefile.zip',
repository: 'assemble/verb' }
// https://assemble@github.com/assemble/verb.git
Url {
protocol: 'https:',
slashes: true,
auth: 'assemble',
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'https://assemble@github.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// https://gh.pages.com/assemble/verb.git
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'gh.pages.com',
port: null,
hostname: 'gh.pages.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'https://gh.pages.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// https://github.com/assemble/verb
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb',
path: 'assemble/verb',
href: 'https://github.com/assemble/verb',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// https://github.com/assemble/verb.git
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb.git',
path: 'assemble/verb.git',
href: 'https://github.com/assemble/verb.git',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'master',
repository: 'assemble/verb' }
// https://github.com/assemble/verb/blob/1.2.3/README.md
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/blob/1.2.3/README.md',
path: 'assemble/verb/blob/1.2.3/README.md',
href: 'https://github.com/assemble/verb/blob/1.2.3/README.md',
filepath: 'README.md',
branch: '1.2.3',
blob: '1.2.3/README.md',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb' }
// https://github.com/assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md',
path: 'assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md',
href: 'https://github.com/assemble/verb/blob/249b21a86400b38969cee3d5df6d2edf8813c137/README.md',
filepath: '249b21a86400b38969cee3d5df6d2edf8813c137/README.md',
blob: '249b21a86400b38969cee3d5df6d2edf8813c137/README.md',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'blob',
repository: 'assemble/verb' }
// https://github.com/assemble/verb/blob/master/assemble/index.js
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/blob/master/assemble/index.js',
path: 'assemble/verb/blob/master/assemble/index.js',
href: 'https://github.com/assemble/verb/blob/master/assemble/index.js',
filepath: 'assemble/index.js',
branch: 'master',
blob: 'master/assemble/index.js',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb' }
// https://github.com/assemble/verb/tree/1.2.3
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/tree/1.2.3',
path: 'assemble/verb/tree/1.2.3',
href: 'https://github.com/assemble/verb/tree/1.2.3',
filepath: null,
branch: '1.2.3',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb' }
// https://github.com/assemble/verb/tree/feature/1.2.3
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'assemble/verb/tree/feature/1.2.3',
path: 'assemble/verb/tree/feature/1.2.3',
href: 'https://github.com/assemble/verb/tree/feature/1.2.3',
filepath: null,
branch: 'feature',
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
repository: 'assemble/verb' }
// https://github.com/repos/assemble/verb/tarball
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'repos/assemble/verb/tarball',
path: 'assemble/verb/tarball',
href: 'https://github.com/repos/assemble/verb/tarball',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'tarball',
repository: 'assemble/verb' }
// https://github.com/repos/assemble/verb/zipball
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'github.com',
port: null,
hostname: 'github.com',
hash: null,
search: null,
query: null,
pathname: 'repos/assemble/verb/zipball',
path: 'assemble/verb/zipball',
href: 'https://github.com/repos/assemble/verb/zipball',
filepath: null,
owner: 'assemble',
name: 'verb',
repo: 'assemble/verb',
branch: 'zipball',
repository: 'assemble/verb' }
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
You might also be interested in these projects:
v1.0.3 - 2024-06-26
url.parse
deprecation warning #30
#15
#27
#16
06c2423
e764de9
auto-changelog
12b542f
10b3f6c
6da7b67
1a7063e
4d46f90
abcd683
FAQs
Parse a github URL into an object.
The npm package parse-github-url receives a total of 835,572 weekly downloads. As such, parse-github-url popularity was classified as popular.
We found that parse-github-url demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.