git-username
Advanced tools
Comparing version 0.2.0 to 0.3.0
41
index.js
/*! | ||
* git-username <https://github.com/jonschlinkert/git-username> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert | ||
* Licensed under the MIT License (MIT) | ||
* Copyright (c) 2014-2015, Jon Schlinkert. | ||
* Licensed under the MIT License. | ||
*/ | ||
const url = require('url'); | ||
const origin = require('remote-origin-url'); | ||
const gitUrl = require('github-url-from-git'); | ||
const log = require('verbalize'); | ||
var url = require('url'); | ||
var chalk = require('chalk'); | ||
var origin = require('remote-origin-url'); | ||
/** | ||
* Expose `username` | ||
*/ | ||
module.exports = username; | ||
/** | ||
* Get the username from the GitHub remote origin URL | ||
*/ | ||
module.exports = (function() { | ||
if (/\bhas not been defined\b/.test(origin.url())) { | ||
log.warn(" Can't calculate git-username. This probably means that"); | ||
log.warn(" a git remote origin has not been defined."); | ||
return ''; | ||
function username(cwd) { | ||
var repo = origin.sync(cwd); | ||
if (!repo) { | ||
console.error(chalk.red(' Can\'t calculate git-username, which probably means that\n a git remote origin has not been defined.')); | ||
} | ||
return url.parse(gitUrl(origin.url())).path.split('/')[1]; | ||
})(); | ||
var o = url.parse(repo); | ||
var path = o.path | ||
if (path.length && path.charAt(0) === '/') { | ||
path = path.slice(1); | ||
} | ||
path = path.split('/')[0]; | ||
return path; | ||
}; | ||
console.log(username()) |
{ | ||
"name": "git-username", | ||
"description": "Extract the username from a git remote origin URL.", | ||
"version": "0.2.0", | ||
"description": "Get the username from a git remote origin URL.", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/jonschlinkert/git-username", | ||
@@ -17,17 +17,9 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/git-username/blob/master/LICENSE-MIT" | ||
} | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/git-username/blob/master/LICENSE" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"docs", | ||
"documentation", | ||
"generate", | ||
"generator", | ||
"markdown", | ||
"templates", | ||
"verb" | ||
], | ||
"main": "index.js", | ||
@@ -38,12 +30,23 @@ "engines": { | ||
"scripts": { | ||
"test": "mocha -R test" | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"chalk": "^1.0.0", | ||
"remote-origin-url": "^0.3.0" | ||
}, | ||
"devDependencies": { | ||
"verb": "~0.2.0" | ||
"mocha": "*" | ||
}, | ||
"dependencies": { | ||
"github-url-from-git": "~1.1.1", | ||
"remote-origin-url": "~0.2.1", | ||
"verbalize": "^0.1.2" | ||
} | ||
"keywords": [ | ||
"parse", | ||
"git", | ||
"name", | ||
"origin", | ||
"remote", | ||
"remote origin url", | ||
"remote origin", | ||
"url", | ||
"user", | ||
"username" | ||
] | ||
} |
@@ -1,10 +0,7 @@ | ||
# git-username [![NPM version](https://badge.fury.io/js/git-username.png)](http://badge.fury.io/js/git-username) | ||
# git-username [![NPM version](https://badge.fury.io/js/git-username.svg)](http://badge.fury.io/js/git-username) | ||
> Extract the username from a git remote origin URL. | ||
> Get the username from a git remote origin URL. | ||
This differs from [git-user-name](https://github.com/jonschlinkert/git-user-name), which provides name of the current user from git config. | ||
## Install with [npm](npmjs.org) | ||
## Install | ||
Install with [npm](npmjs.org): | ||
```bash | ||
@@ -14,30 +11,44 @@ npm i git-username --save | ||
## Usage | ||
```js | ||
var username = require('git-username'); | ||
console.log(username); | ||
var username = require('git-username')(); | ||
//=> jonschlinkert | ||
``` | ||
## Related | ||
Here are a few related projects: | ||
+ [git-branch](https://github.com/jonschlinkert/git-branch): Get the current branch for a local git repository | ||
+ [git-repo-name](https://github.com/jonschlinkert/git-repo-name): Get the repository name from the git remote origin URL | ||
+ [git-user-email](https://github.com/jonschlinkert/git-user-email): Get the current user's git email address. | ||
+ [git-user-name](https://github.com/jonschlinkert/git-user-name): Get the name of the current user from git config, at the project or global scope, depending on what git uses in the current context. | ||
+ [git-username](https://github.com/jonschlinkert/git-username): Get the username from a git remote origin URL. | ||
+ [github-repo-url](https://github.com/jonschlinkert/github-repo-url): Extract a GitHub project's URL from its git repository URL. | ||
Optionally pass a CWD as the second argument: | ||
```js | ||
var username = require('git-username')('foo'); | ||
``` | ||
## Run tests | ||
Install dev dependencies: | ||
```bash | ||
npm i -d && npm test | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/git-username/issues) | ||
## Related projects | ||
* [git-branch](https://github.com/jonschlinkert/git-branch): Get the current branch for a local git repository. | ||
* [git-repo-name](https://github.com/jonschlinkert/git-repo-name): Get the repository name from the git remote origin URL. | ||
* [git-user-email](https://github.com/jonschlinkert/git-user-email): Get the git email address of the current user. | ||
* [git-user-name](https://github.com/jonschlinkert/git-user-name): Get the name of the current user from git config, at the project or global scope, depending on what git uses in the current context. | ||
* [git-username](https://github.com/jonschlinkert/git-username): Extract the username from a git remote origin URL. | ||
* [github-repo-url](https://github.com/jonschlinkert/github-repo-url): Extract a GitHub project's URL from its git repository URL. | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert, contributors. | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
@@ -47,2 +58,2 @@ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 04, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on February 27, 2015._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
58
4768
4
30
1
+ Addedchalk@^1.0.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedini@1.3.8(transitive)
+ Addedparse-git-config@0.1.0(transitive)
+ Addedremote-origin-url@0.3.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
- Removedgithub-url-from-git@~1.1.1
- Removedverbalize@^0.1.2
- Removedansi-styles@1.0.0(transitive)
- Removedchalk@0.4.0(transitive)
- Removedfindup-sync@0.1.3(transitive)
- Removedgithub-url-from-git@1.1.1(transitive)
- Removedglob@3.2.11(transitive)
- Removedhas-color@0.1.7(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.1.0(transitive)
- Removedlodash@2.4.2(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.3.0(transitive)
- Removedremote-origin-url@0.2.1(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedstrip-ansi@0.1.1(transitive)
- Removedverbalize@0.1.2(transitive)
Updatedremote-origin-url@^0.3.0