instagram-user
Advanced tools
Comparing version 1.0.0 to 2.0.0
42
index.js
@@ -5,19 +5,31 @@ 'use strict'; | ||
module.exports = user => { | ||
if (typeof user !== 'string') { | ||
throw new TypeError(`Expected a string, got ${typeof user}`); | ||
module.exports = async username => { | ||
if (typeof username !== 'string') { | ||
throw new TypeError(`Expected \`user\` to be of type \`string\` but received type \`${typeof username}\``); | ||
} | ||
return got(`http://instagram.com/${user}/?__a=1`, {json: true}).then(res => ({ | ||
description: res.body.user.biography || '', | ||
email: getEmails(res.body.user.biography || '')[0] || '', | ||
followers: res.body.user.followed_by.count, | ||
following: res.body.user.follows.count, | ||
fullName: res.body.user.full_name || '', | ||
id: res.body.user.id, | ||
posts: res.body.user.media.count, | ||
url: `http://instagram.com/${user}`, | ||
username: res.body.user.username, | ||
website: res.body.user.external_url || '' | ||
})); | ||
try { | ||
const url = `https://instagram.com/${username}`; | ||
const {body: {graphql: {user}}} = await got(`${url}/?__a=1`, {json: true}); | ||
const email = getEmails(user.biography).values().next().value || ''; | ||
return { | ||
...user, | ||
description: user.biography, | ||
email, | ||
followers: user.edge_followed_by.count, | ||
following: user.edge_follow.count, | ||
fullName: user.full_name, | ||
posts: user.edge_owner_to_timeline_media.count, | ||
url, | ||
username, | ||
website: user.external_url | ||
}; | ||
} catch (error) { | ||
if (error.statusCode === 404) { | ||
error.message = `User "${username}" not found`; | ||
} | ||
throw error; | ||
} | ||
}; |
{ | ||
"name": "instagram-user", | ||
"version": "1.0.0", | ||
"description": "Get Instagram user info", | ||
"license": "MIT", | ||
"repository": "kevva/instagram-user", | ||
"author": { | ||
"name": "Kevin Martensson", | ||
"email": "kevinmartensson@gmail.com", | ||
"url": "github.com/kevva" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"api", | ||
"instagram", | ||
"user", | ||
"username" | ||
], | ||
"dependencies": { | ||
"get-emails": "^1.0.1", | ||
"got": "^6.3.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "instagram-user", | ||
"version": "2.0.0", | ||
"description": "Get Instagram user info", | ||
"license": "MIT", | ||
"repository": "kevva/instagram-user", | ||
"author": { | ||
"name": "Kevin Mårtensson", | ||
"email": "kevinmartensson@gmail.com", | ||
"url": "github.com/kevva" | ||
}, | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"api", | ||
"instagram", | ||
"user", | ||
"username" | ||
], | ||
"dependencies": { | ||
"get-emails": "^3.0.0", | ||
"got": "^9.6.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # instagram-user [![Build Status](https://travis-ci.org/kevva/instagram-user.svg?branch=master)](https://travis-ci.org/kevva/instagram-user) | ||
``` | ||
$ npm install --save instagram-user | ||
$ npm install instagram-user | ||
``` | ||
@@ -19,6 +19,6 @@ | ||
instagramUser('unicorns').then(user => { | ||
console.log(user); | ||
(async () => { | ||
console.log(await instagramUser('unicorns')); | ||
//=> {description: 'A wonderful description', email: 'unicorns@foo.com', ...} | ||
}) | ||
})(); | ||
``` | ||
@@ -31,2 +31,4 @@ | ||
Returns a `Promise<Object>` with the user information. | ||
#### username | ||
@@ -37,6 +39,1 @@ | ||
Instagram username. | ||
## License | ||
MIT © [Kevin Martensson](https://github.com/kevva) |
Sorry, the diff of this file is not supported yet
3160
30
36
+ 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)
+ Addeddecompress-response@3.3.0(transitive)
+ Addeddefer-to-connect@1.1.3(transitive)
+ Addedemail-regex@3.0.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedget-emails@3.0.0(transitive)
+ Addedget-stream@4.1.05.2.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)
+ Addedmimic-response@1.0.1(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.0(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)
- Removedarray-uniq@1.0.3(transitive)
- Removedcapture-stack-trace@1.0.2(transitive)
- Removedcreate-error-class@3.0.2(transitive)
- Removedemail-regex@1.0.0(transitive)
- Removedget-emails@1.0.1(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedget-stream@3.0.0(transitive)
- Removedgot@6.7.1(transitive)
- Removedis-redirect@1.0.0(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedtimed-out@4.0.1(transitive)
- Removedunzip-response@2.0.1(transitive)
- Removedurl-parse-lax@1.0.0(transitive)
Updatedget-emails@^3.0.0
Updatedgot@^9.6.0