├── .gitattributes ├── .travis.yml ├── .editorconfig ├── index.js ├── .gitignore ├── .verb.md ├── LICENSE ├── package.json ├── test.js ├── README.md └── .eslintrc.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - iojs 9 | - '7' 10 | - '6' 11 | - '5' 12 | - '4' 13 | - '0.8' 14 | - '0.12' 15 | - '0.10' 16 | git: 17 | depth: 10 18 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * is-git-url 3 | * 4 | * Copyright (c) 2014-2015, 2017, Jon Schlinkert. 5 | * Released under the MIT License. 6 | */ 7 | 8 | module.exports = function isGitUrl(str) { 9 | var regex = /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/; 10 | return regex.test(str); 11 | }; 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | var isGitUrl = require('{%= name %}'); 5 | 6 | isGitUrl('git://github.com/jonschlinkert/is-git-url.git'); 7 | //=> true 8 | 9 | isGitUrl('https://github.com/jonschlinkert/'); 10 | //=> false 11 | ``` 12 | 13 | Edit on [debuggex](https://www.debuggex.com/r/WeYxcD7Ghp5ekrPR/0#cheatsheet) 14 | 15 | ![image](https://cloud.githubusercontent.com/assets/383994/2627089/bd37da5c-bdf9-11e3-9c26-d2b02f46bc24.png) 16 | 17 | See for more info. 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2015, 2017, Jon Schlinkert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-git-url", 3 | "description": "Regex to validate that a URL is a git url.", 4 | "version": "1.0.0", 5 | "homepage": "https://github.com/jonschlinkert/is-git-url", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "contributors": [ 8 | "Charlike Mike Reagent (https://i.am.charlike.online)", 9 | "Daniel Cadenas (http://craftedcode.com)", 10 | "Emre Unal (https://github.com/quaertym)", 11 | "Jon Schlinkert (http://twitter.com/jonschlinkert)", 12 | "Loïc Mahieu (http://iGLOO.be)" 13 | ], 14 | "repository": "jonschlinkert/is-git-url", 15 | "bugs": { 16 | "url": "https://github.com/jonschlinkert/is-git-url/issues" 17 | }, 18 | "license": "MIT", 19 | "files": [ 20 | "index.js" 21 | ], 22 | "main": "index.js", 23 | "engines": { 24 | "node": ">=0.8" 25 | }, 26 | "scripts": { 27 | "test": "mocha" 28 | }, 29 | "devDependencies": { 30 | "gulp-format-md": "^0.1.12", 31 | "mocha": "^3.2.0" 32 | }, 33 | "keywords": [ 34 | "git", 35 | "github", 36 | "is", 37 | "regex", 38 | "regexp", 39 | "test", 40 | "url" 41 | ], 42 | "verb": { 43 | "related": { 44 | "list": [ 45 | "git-branch", 46 | "git-repo-name", 47 | "git-username", 48 | "github-contributors", 49 | "parse-github-url" 50 | ] 51 | }, 52 | "toc": false, 53 | "layout": "default", 54 | "tasks": [ 55 | "readme" 56 | ], 57 | "plugins": [ 58 | "gulp-format-md" 59 | ], 60 | "lint": { 61 | "reflinks": true 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * is-git-url 3 | * 4 | * Copyright (c) 2015, 2017, Jon Schlinkert. 5 | * Released under the MIT License. 6 | */ 7 | 8 | require('mocha'); 9 | var assert = require('assert'); 10 | var isGitUrl = require('./'); 11 | 12 | var validURLs = [ 13 | 'git://github.com/ember-cli/ember-cli.git#ff786f9f', 14 | 'git://github.com/ember-cli/ember-cli.git#gh-pages', 15 | 'git://github.com/ember-cli/ember-cli.git#master', 16 | 'git://github.com/ember-cli/ember-cli.git#Quick-Fix', 17 | 'git://github.com/ember-cli/ember-cli.git#quick_fix', 18 | 'git://github.com/ember-cli/ember-cli.git#v0.1.0', 19 | 'git://host.xz/path/to/repo.git/', 20 | 'git://host.xz/~user/path/to/repo.git/', 21 | 'git@192.168.101.127:user/project.git', 22 | 'git@github.com:user/project.git', 23 | 'git@github.com:user/some-project.git', 24 | 'git@github.com:user/some-project.git', 25 | 'git@github.com:user/some_project.git', 26 | 'git@github.com:user/some_project.git', 27 | 'http://192.168.101.127/user/project.git', 28 | 'http://github.com/user/project.git', 29 | 'http://host.xz/path/to/repo.git/', 30 | 'https://192.168.101.127/user/project.git', 31 | 'https://github.com/user/project.git', 32 | 'https://host.xz/path/to/repo.git/', 33 | 'https://username::;*%$:@github.com/username/repository.git', 34 | 'https://username:$fooABC@:@github.com/username/repository.git', 35 | 'https://username:password@github.com/username/repository.git', 36 | 'ssh://host.xz/path/to/repo.git/', 37 | 'ssh://host.xz/path/to/repo.git/', 38 | 'ssh://host.xz/~/path/to/repo.git', 39 | 'ssh://host.xz/~user/path/to/repo.git/', 40 | 'ssh://host.xz:port/path/to/repo.git/', 41 | 'ssh://user@host.xz/path/to/repo.git/', 42 | 'ssh://user@host.xz/path/to/repo.git/', 43 | 'ssh://user@host.xz/~/path/to/repo.git', 44 | 'ssh://user@host.xz/~user/path/to/repo.git/', 45 | 'ssh://user@host.xz:port/path/to/repo.git/', 46 | ]; 47 | 48 | var invalidURLs = [ 49 | '/path/to/repo.git/', 50 | 'file:///path/to/repo.git/', 51 | 'file://~/path/to/repo.git/', 52 | 'git@github.com:user/some_project.git/foo', 53 | 'git@github.com:user/some_project.gitfoo', 54 | 'host.xz:/path/to/repo.git/', 55 | 'host.xz:path/to/repo.git', 56 | 'host.xz:~user/path/to/repo.git/', 57 | 'path/to/repo.git/', 58 | 'rsync://host.xz/path/to/repo.git/', 59 | 'user@host.xz:/path/to/repo.git/', 60 | 'user@host.xz:path/to/repo.git', 61 | 'user@host.xz:~user/path/to/repo.git/', 62 | '~/path/to/repo.git' 63 | ]; 64 | 65 | validURLs.forEach(function(url, i) { 66 | it('git URL: #' + (i++) + ' - ' + url, function () { 67 | assert(isGitUrl(url) === true); 68 | }); 69 | }); 70 | 71 | invalidURLs.forEach(function(url, i) { 72 | it('not a git url #' + (i++) + ' - ' + url, function () { 73 | assert(isGitUrl(url) === false); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-git-url [![NPM version](https://img.shields.io/npm/v/is-git-url.svg?style=flat)](https://www.npmjs.com/package/is-git-url) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-git-url.svg?style=flat)](https://npmjs.org/package/is-git-url) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-git-url.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-git-url) 2 | 3 | > Regex to validate that a URL is a git url. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save is-git-url 11 | ``` 12 | 13 | Install with [yarn](https://yarnpkg.com): 14 | 15 | ```sh 16 | $ yarn add is-git-url 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | var isGitUrl = require('is-git-url'); 23 | 24 | isGitUrl('git://github.com/jonschlinkert/is-git-url.git'); 25 | //=> true 26 | 27 | isGitUrl('https://github.com/jonschlinkert/'); 28 | //=> false 29 | ``` 30 | 31 | Edit on [debuggex](https://www.debuggex.com/r/WeYxcD7Ghp5ekrPR/0#cheatsheet) 32 | 33 | ![image](https://cloud.githubusercontent.com/assets/383994/2627089/bd37da5c-bdf9-11e3-9c26-d2b02f46bc24.png) 34 | 35 | See [http://git-scm.com/book/ch4-1.html](http://git-scm.com/book/ch4-1.html) for more info. 36 | 37 | ## About 38 | 39 | ### Related projects 40 | 41 | * [git-branch](https://www.npmjs.com/package/git-branch): Get the current branch for a local git repository. | [homepage](https://github.com/jonschlinkert/git-branch "Get the current branch for a local git repository.") 42 | * [git-repo-name](https://www.npmjs.com/package/git-repo-name): Get the repository name from the git remote origin URL. | [homepage](https://github.com/jonschlinkert/git-repo-name "Get the repository name from the git remote origin URL.") 43 | * [git-username](https://www.npmjs.com/package/git-username): Get the username from a git remote origin URL. | [homepage](https://github.com/jonschlinkert/git-username "Get the username from a git remote origin URL.") 44 | * [github-contributors](https://www.npmjs.com/package/github-contributors): Generate a markdown or JSON list of contributors for a project using the GitHub API. | [homepage](https://github.com/jonschlinkert/github-contributors "Generate a markdown or JSON list of contributors for a project using the GitHub API.") 45 | * [parse-github-url](https://www.npmjs.com/package/parse-github-url): Parse a github URL into an object. | [homepage](https://github.com/jonschlinkert/parse-github-url "Parse a github URL into an object.") 46 | 47 | ### Contributing 48 | 49 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 50 | 51 | ### Contributors 52 | 53 | | **Commits** | **Contributor** | 54 | | --- | --- | 55 | | 17 | [jonschlinkert](https://github.com/jonschlinkert) | 56 | | 2 | [tunnckoCore](https://github.com/tunnckoCore) | 57 | | 1 | [dcadenas](https://github.com/dcadenas) | 58 | | 1 | [quaertym](https://github.com/quaertym) | 59 | | 1 | [LoicMahieu](https://github.com/LoicMahieu) | 60 | 61 | ### Building docs 62 | 63 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 64 | 65 | To generate the readme, run the following command: 66 | 67 | ```sh 68 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 69 | ``` 70 | 71 | ### Running tests 72 | 73 | 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: 74 | 75 | ```sh 76 | $ npm install && npm test 77 | ``` 78 | 79 | ### Author 80 | 81 | **Jon Schlinkert** 82 | 83 | * [github/jonschlinkert](https://github.com/jonschlinkert) 84 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) 85 | 86 | ### License 87 | 88 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). 89 | Released under the [MIT License](LICENSE). 90 | 91 | *** 92 | 93 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 17, 2017._ -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | --------------------------------------------------------------------------------