Skip to content

Commit bebd12e

Browse files
committed
Meta tweaks
1 parent e098d3d commit bebd12e

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface UserData {
1+
export interface UserInfo {
22
/**
33
* User's name.
44
*/
@@ -20,7 +20,7 @@ export interface UserData {
2020
github: string | null;
2121

2222
/**
23-
* User's associated twitter account.
23+
* User's associated Twitter account.
2424
*/
2525
twitter: string | null;
2626
}
@@ -30,4 +30,4 @@ export interface UserData {
3030
*
3131
* @param name - User's username on npm.
3232
*/
33-
export default function npmUser(name: string): Promise<UserData>;
33+
export default function npmUser(name: string): Promise<UserInfo>;

index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ const npmEmail = require('npm-email');
55

66
const npmUser = async username => {
77
if (typeof username !== 'string') {
8-
return Promise.reject(new Error('Username required'));
8+
throw new TypeError('Username required');
99
}
1010

1111
const url = `https://www.npmjs.com/~${username}`;
1212
try {
13-
const values = await Promise.all([got(url), npmEmail(username)]);
14-
15-
const res = values[0];
16-
const email = values[1];
17-
const $ = cheerio.load(res.body);
13+
const [profile, email] = await Promise.all([got(url), npmEmail(username)]);
14+
const $ = cheerio.load(profile.body);
1815

1916
let avatar = $('img[src^="https://s.gravatar.com"]').attr('src');
2017
avatar = avatar ? avatar.replace(/^(https:\/\/)s\./, '$1').replace(/&default=retro$/, '') : null;

index.test-d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {expectType} from 'tsd-check';
2-
import npmUser, {UserData} from '.';
2+
import npmUser, {UserInfo} from '.';
33

4-
const userDataPromise = npmUser('sindresorhus');
5-
expectType<Promise<UserData>>(userDataPromise);
4+
const userInfoPromise = npmUser('sindresorhus');
5+
expectType<Promise<UserInfo>>(userInfoPromise);
66

7-
const userData = await userDataPromise;
8-
expectType<string | null>(userData.name);
9-
expectType<string | null>(userData.avatar);
10-
expectType<string | null>(userData.email);
11-
expectType<string | null>(userData.github);
12-
expectType<string | null>(userData.twitter);
7+
const userInfo = await userInfoPromise;
8+
expectType<string | null>(userInfo.name);
9+
expectType<string | null>(userInfo.avatar);
10+
expectType<string | null>(userInfo.email);
11+
expectType<string | null>(userInfo.github);
12+
expectType<string | null>(userInfo.twitter);

readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Since npm has no API for this we're forced to scrape the [profile page](https://www.npmjs.com/~sindresorhus).
66

7-
*Use the faster [npm-email](https://github.com/sindresorhus/npm-email) if you only need the email.*
7+
*Use the faster [npm-email](https://github.com/sindresorhus/npm-email) package if you only need the email.*
88

99

1010
## Install
@@ -19,8 +19,8 @@ $ npm install npm-user
1919
```js
2020
const npmUser = require('npm-user');
2121

22-
npmUser('sindresorhus').then(user => {
23-
console.log(user);
22+
(async () => {
23+
console.log(await npmUser('sindresorhus'));
2424
/*
2525
{
2626
name: 'Sindre Sorhus',
@@ -30,7 +30,7 @@ npmUser('sindresorhus').then(user => {
3030
twitter: 'sindresorhus'
3131
}
3232
*/
33-
});
33+
})()
3434
```
3535

3636
*Values will be `null` if they're not set in the npm profile.*

0 commit comments

Comments
 (0)