Skip to content

Commit a9fd33e

Browse files
committed
init
0 parents  commit a9fd33e

11 files changed

+286
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[{package.json,*.yml}]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.jshintrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"node": true,
3+
"esnext": true,
4+
"bitwise": true,
5+
"curly": true,
6+
"immed": true,
7+
"newcap": true,
8+
"noarg": true,
9+
"undef": true,
10+
"unused": "vars",
11+
"strict": true
12+
}

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- 'iojs'
5+
- '0.12'
6+
- '0.10'

cli.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
var meow = require('meow');
4+
var npmUser = require('./');
5+
6+
var cli = meow({
7+
help: [
8+
'Usage',
9+
' $ npm-user <username>',
10+
'',
11+
'Example',
12+
' $ npm-user sindresorhus',
13+
' Name: Sindre Sorhus',
14+
' Email: sindresorhus@gmail.com',
15+
' Homepage: http://sindresorhus.com',
16+
' Twitter: sindresorhus',
17+
' GitHub: sindresorhus',
18+
' Freenode: sindresorhus'
19+
].join('\n')
20+
});
21+
22+
var username = cli.input[0];
23+
24+
if (!username) {
25+
console.error('Please supply a npm username');
26+
process.exit(1);
27+
}
28+
29+
npmUser(username, function (err, user) {
30+
if (err) {
31+
console.error(err.message);
32+
process.exit(1);
33+
}
34+
35+
var ret = [];
36+
37+
var createRow = function (prefix, key) {
38+
if (user[key]) {
39+
ret.push(prefix + ': ' + user[key]);
40+
}
41+
}
42+
43+
createRow('Name', 'name');
44+
createRow('Email', 'email');
45+
createRow('Homepage', 'homepage');
46+
createRow('GitHub', 'github');
47+
createRow('Twitter', 'twitter');
48+
createRow('Freenode', 'freenode');
49+
50+
console.log(ret.join('\n'));
51+
});

index.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
var got = require('got');
3+
var cheerio = require('cheerio');
4+
5+
function unobfuscateEmail(str) {
6+
return str.split('%')
7+
.slice(1)
8+
.map(function (el) {
9+
return String.fromCharCode(parseInt(el, 16));
10+
})
11+
.join('');
12+
}
13+
14+
module.exports = function (username, cb) {
15+
if (typeof username !== 'string') {
16+
throw new Error('username required');
17+
}
18+
19+
var url = 'https://www.npmjs.com/~' + username;
20+
21+
got(url, function (err, data) {
22+
if (err && err.code === 404) {
23+
cb(new Error('User doesn\'t exist'));
24+
return;
25+
}
26+
27+
if (err) {
28+
cb(err);
29+
return;
30+
}
31+
32+
var $ = cheerio.load(data);
33+
34+
cb(null, {
35+
name: $('.fullname').text() || null,
36+
email: unobfuscateEmail($('.email [data-email]').attr('data-email')) || null,
37+
homepage: $('.homepage a').attr('href') || null,
38+
github: $('.github a').text().slice(1) || null,
39+
twitter: $('.twitter a').text().slice(1) || null,
40+
freenode: $('.freenode a').text() || null
41+
});
42+
});
43+
};

license

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
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.

package.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "npm-user",
3+
"version": "0.0.0",
4+
"description": "Get user info of a npm user",
5+
"license": "MIT",
6+
"repository": "sindresorhus/npm-user",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "sindresorhus@gmail.com",
10+
"url": "sindresorhus.com"
11+
},
12+
"bin": "cli.js",
13+
"engines": {
14+
"node": ">=0.10.0"
15+
},
16+
"scripts": {
17+
"test": "node test.js"
18+
},
19+
"files": [
20+
"index.js",
21+
"cli.js"
22+
],
23+
"keywords": [
24+
"cli-app",
25+
"cli",
26+
"bin",
27+
"npm",
28+
"user",
29+
"username",
30+
"homepage",
31+
"email",
32+
"get",
33+
"website",
34+
"scrape",
35+
"info",
36+
"profile"
37+
],
38+
"dependencies": {
39+
"cheerio": "^0.19.0",
40+
"got": "^3.0.0",
41+
"meow": "^3.1.0"
42+
},
43+
"devDependencies": {
44+
"ava": "0.0.4"
45+
}
46+
}

readme.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# npm-user [![Build Status](https://travis-ci.org/sindresorhus/npm-user.svg?branch=master)](https://travis-ci.org/sindresorhus/npm-user)
2+
3+
> Get user info of a npm user
4+
5+
Since npm has no API for this we're forced to scrape the [profile page](https://www.npmjs.com/~sindresorhus).
6+
7+
*Use the faster [npm-email](https://github.com/sindresorhus/npm-email) if you only need the email.*
8+
9+
10+
## Install
11+
12+
```
13+
$ npm install --save npm-user
14+
```
15+
16+
17+
## Usage
18+
19+
```js
20+
var npmUser = require('npm-user');
21+
22+
npmuser('sindresorhus', function (err, user) {
23+
console.log(user);
24+
/*
25+
{
26+
name: 'Sindre Sorhus',
27+
email: 'sindresorhus@gmail.com',
28+
homepage: 'http://sindresorhus.com',
29+
github: 'sindresorhus',
30+
twitter: 'sindresorhus',
31+
freenode: 'sindresorhus'
32+
}
33+
*/
34+
});
35+
```
36+
37+
*Values will be `null` if they're not set in the npm profile.*
38+
39+
40+
## CLI
41+
42+
```
43+
$ npm install --global npm-user
44+
```
45+
46+
```
47+
$ npm-user --help
48+
49+
Usage
50+
$ npm-user <username>
51+
52+
Example
53+
$ npm-user sindresorhus
54+
Name: Sindre Sorhus
55+
Email: sindresorhus@gmail.com
56+
Homepage: http://sindresorhus.com
57+
Twitter: sindresorhus
58+
GitHub: sindresorhus
59+
Freenode: sindresorhus
60+
```
61+
62+
63+
## Related
64+
65+
- [npm-email](https://github.com/sindresorhus/npm-email) - Get the email of a npm user
66+
- [npm-keyword](https://github.com/sindresorhus/npm-keyword) - Get a list of npm packages with a certain keyword
67+
- [package-json](https://github.com/sindresorhus/package-json) - Get the package.json of a package from the npm registry
68+
69+
70+
## License
71+
72+
MIT © [Sindre Sorhus](http://sindresorhus.com)

test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
var test = require('ava');
3+
var npmUser = require('./');
4+
5+
test(function (t) {
6+
t.plan(7);
7+
8+
npmUser('sindresorhus', function (err, user) {
9+
console.log(user);
10+
t.assert(!err, err);
11+
t.assert(user.name === 'Sindre Sorhus');
12+
t.assert(user.email === 'sindresorhus@gmail.com');
13+
t.assert(user.homepage === 'http://sindresorhus.com');
14+
t.assert(user.github === 'sindresorhus');
15+
t.assert(user.twitter === 'sindresorhus');
16+
t.assert(user.freenode === 'sindresorhus');
17+
});
18+
});

0 commit comments

Comments
 (0)