New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github-username

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-username - npm Package Compare versions

Comparing version 5.0.1 to 6.0.0

6

index.d.ts
/**
Get a GitHub username from an email address.
Get the GitHub username from an email address if the email can be found in any commits on GitHub.
@param email - Email address for the user of whom you want the username.
@param token - GitHub [personal access token](https://github.com/settings/tokens/new).
@returns The username for the `email`.
@returns The username for the `email` or `undefined` if it cannot be found.

@@ -18,4 +18,4 @@ @example

*/
declare function githubUsername(email: string, token?: string): Promise<string>;
declare function githubUsername(email: string, token?: string): Promise<string | undefined>;
export = githubUsername;
'use strict';
const ghGot = require('gh-got');
const {Octokit} = require('@octokit/rest');
async function searchCommits(email, token) {
const result = await ghGot('search/commits', {
token,
query: {
q: `author-email:${email}`,
sort: 'author-date',
// eslint-disable-next-line camelcase
per_page: 1
},
headers: {
accept: 'application/vnd.github.cloak-preview',
'user-agent': 'https://github.com/sindresorhus/github-username'
}
async function searchCommits(octokit, email) {
const {data} = await octokit.search.commits({
q: `author-email:${email}`,
sort: 'author-date',
// eslint-disable-next-line camelcase
per_page: 1
});
const {body: data} = result;
if (data.total_count === 0) {

@@ -33,16 +24,13 @@ throw new Error(`Couldn't find username for \`${email}\``);

const result = await ghGot('search/users', {
token,
query: {
q: `${email} in:email`
},
headers: {
'user-agent': 'https://github.com/sindresorhus/github-username'
}
const octokit = new Octokit({
auth: token,
userAgent: 'https://github.com/sindresorhus/github-username'
});
const {body: data} = result;
const {data} = await octokit.search.users({
q: `${email} in:email`
});
if (data.total_count === 0) {
return searchCommits(email, token);
return searchCommits(octokit, email);
}

@@ -49,0 +37,0 @@

{
"name": "github-username",
"version": "5.0.1",
"version": "6.0.0",
"description": "Get a GitHub username from an email address",
"license": "MIT",
"repository": "sindresorhus/github-username",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},

@@ -32,9 +33,9 @@ "scripts": {

"dependencies": {
"gh-got": "^8.1.0"
"@octokit/rest": "^18.0.6"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^2.4.0",
"tsd": "^0.14.0",
"xo": "^0.36.1"
}
}

@@ -1,6 +0,5 @@

# github-username [![Build Status](https://travis-ci.org/sindresorhus/github-username.svg?branch=master)](https://travis-ci.org/sindresorhus/github-username)
# github-username
> Get a GitHub username from an email address
## Install

@@ -12,3 +11,2 @@

## Usage

@@ -25,9 +23,10 @@

## API
### githubUsername(email, [token])
### githubUsername(email, token?)
Returns a `Promise<string>` with the username.
Get the GitHub username from an email address if the email can be found in any commits on GitHub.
Returns a `Promise<string?>` with the username.
#### email

@@ -45,10 +44,4 @@

## Related
- [github-username-cli](https://github.com/sindresorhus/github-username-cli) - CLI for this module
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc