Check if a passed string is a valid GitHub URL
Unlike is-git-url, is-github-url is a domain-specific validator. It returns true
if passed URL is a part of github.com
domain only.
$ npm install is-github-url --save
var isGithubUrl = require('is-github-url');
// Valid examples
isGithubUrl('https://github.com/facebook');
// => true
isGithubUrl('https://github.com/facebook/react');
// => true
isGithubUrl('https://github.com/facebook/react/releases/tag/v0.14.0');
// => true
isGithubUrl('[email protected]:facebook/react.git');
// => true
isGithubUrl('git:https://github.com/facebook/react.git#gh-pages');
// => true
// Invalid examples
isGithubUrl('https://google.com');
// => false
isGithubUrl('unknown:https://github.com');
// => false
isGithubUrl('https://facebook.github.io/');
// => false
// Repository mode can be used to check whether a passed URL
// is a valid repository URL
isGithubUrl('https://github.com/facebook/react', { repository: true });
// => true
isGithubUrl('https://github.com/facebook', { repository: true });
// => false
isGithubUrl('https://github.com/facebook/react/releases/tag/v0.14.0', {
repository: true
});
// => false
// Strict mode is used to validate URLs before cloning
// Strict mode turns on automatically if URL contains git protocol
isGithubUrl('https://github.com/facebook/react.git', { strict: true });
// => true
isGithubUrl('https://github.com/facebook/react', { strict: true });
// => false
Check if a passed string is a valid GitHub URL
- String
url
: A string to be validated - Object
options
: An object containing the following fields:strict
(Boolean): Match only URLs ending with .gitrepository
(Boolean): Match only valid GitHub repo URLs
MIT © Philipp Alferov