github-username
Advanced tools
Comparing version 4.1.0 to 5.0.0
38
index.js
'use strict'; | ||
const ghGot = require('gh-got'); | ||
function searchCommits(email, token) { | ||
return ghGot('search/commits', { | ||
async function searchCommits(email, token) { | ||
const result = await ghGot('search/commits', { | ||
token, | ||
@@ -17,19 +17,19 @@ query: { | ||
} | ||
}).then(result => { | ||
const data = result.body; | ||
}); | ||
if (data.total_count === 0) { | ||
throw new Error(`Couldn't find username for \`${email}\``); | ||
} | ||
const {body: data} = result; | ||
return data.items[0].author.login; | ||
}); | ||
if (data.total_count === 0) { | ||
throw new Error(`Couldn't find username for \`${email}\``); | ||
} | ||
return data.items[0].author.login; | ||
} | ||
module.exports = (email, token) => { | ||
module.exports = async (email, token) => { | ||
if (!(typeof email === 'string' && email.includes('@'))) { | ||
return Promise.reject(new Error('Email required')); | ||
throw new Error('Email required'); | ||
} | ||
return ghGot('search/users', { | ||
const result = await ghGot('search/users', { | ||
token, | ||
@@ -42,11 +42,11 @@ query: { | ||
} | ||
}).then(result => { | ||
const data = result.body; | ||
}); | ||
if (data.total_count === 0) { | ||
return searchCommits(email, token); | ||
} | ||
const {body: data} = result; | ||
return data.items[0].login; | ||
}); | ||
if (data.total_count === 0) { | ||
return searchCommits(email, token); | ||
} | ||
return data.items[0].login; | ||
}; |
{ | ||
"name": "github-username", | ||
"version": "4.1.0", | ||
"description": "Get a GitHub username from an email address", | ||
"license": "MIT", | ||
"repository": "sindresorhus/github-username", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"github", | ||
"user", | ||
"username", | ||
"email", | ||
"address", | ||
"gh", | ||
"git" | ||
], | ||
"dependencies": { | ||
"gh-got": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "github-username", | ||
"version": "5.0.0", | ||
"description": "Get a GitHub username from an email address", | ||
"license": "MIT", | ||
"repository": "sindresorhus/github-username", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"github", | ||
"user", | ||
"username", | ||
"email", | ||
"address", | ||
"gh", | ||
"git" | ||
], | ||
"dependencies": { | ||
"gh-got": "^8.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -18,6 +18,6 @@ # github-username [](https://travis-ci.org/sindresorhus/github-username) | ||
githubUsername('sindresorhus@gmail.com').then(username => { | ||
console.log(username); | ||
(async () => { | ||
console.log(await githubUsername('sindresorhus@gmail.com')); | ||
//=> 'sindresorhus' | ||
}); | ||
})(); | ||
``` | ||
@@ -30,3 +30,3 @@ | ||
Returns a `Promise` for the username. | ||
Returns a `Promise<string>` with the username. | ||
@@ -33,0 +33,0 @@ #### email |
4223
5
57
3
+ Added@sindresorhus/is@0.14.0(transitive)
+ Added@szmarczak/http-timer@1.1.2(transitive)
+ Addedcacheable-request@6.1.0(transitive)
+ Addedclone-response@1.0.3(transitive)
+ Addeddefer-to-connect@1.1.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedget-stream@4.1.05.2.0(transitive)
+ Addedgh-got@8.1.0(transitive)
+ Addedgot@9.6.0(transitive)
+ Addedhttp-cache-semantics@4.1.1(transitive)
+ Addedjson-buffer@3.0.0(transitive)
+ Addedkeyv@3.1.0(transitive)
+ Addedlowercase-keys@2.0.0(transitive)
+ Addednormalize-url@4.5.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-cancelable@1.1.0(transitive)
+ Addedprepend-http@2.0.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedresponselike@1.0.2(transitive)
+ Addedto-readable-stream@1.0.0(transitive)
+ Addedurl-parse-lax@3.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedget-stream@3.0.0(transitive)
- Removedgh-got@6.0.0(transitive)
- Removedgot@7.1.0(transitive)
- Removedhas-symbol-support-x@1.4.2(transitive)
- Removedhas-to-string-tag-x@1.4.1(transitive)
- Removedis-object@1.0.2(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisurl@1.0.0(transitive)
- Removedp-cancelable@0.3.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@1.2.1(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedtimed-out@4.0.1(transitive)
- Removedurl-parse-lax@1.0.0(transitive)
- Removedurl-to-options@1.0.1(transitive)
Updatedgh-got@^8.1.0