-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (42 loc) · 1.36 KB
/
index.js
File metadata and controls
49 lines (42 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const got = require('got');
const unicode = require('unicodechar-string');
const baseLink = username => {
return `https://instagram.com/${username}`;
};
const points = {
id: `"id":"`,
fullname: `full_name":"`,
username: `,"username":"`,
bio: `"biography":"`,
externalUrl: `"external_url":"`,
linkshimmed: `"external_url_linkshimmed":"`,
posts: `,"edge_owner_to_timeline_media":{"count":`,
followers: `,"edge_followed_by":{"count":`,
following: `,"edge_follow":{"count":`,
private: `,"is_private":`,
verified: `,"is_verified":`,
connected: `,"connected_fb_page":`
};
const splitData = (data, index) => {
if (index === points.id || index === points.fullname || index === points.username || index === points.bio || index === points.externalUrl || index === points.linkshimmed) {
return data.split(index)[1].split(`","`)[0];
}
if (index === points.followers || index === points.following) {
return data.split(index)[1].split(`},"`)[0];
}
return data.split(index)[1].split(`,"`)[0];
};
module.exports = (username, info) => {
return got(baseLink(username)).then(res => {
const data = res.body;
const skip = points[info];
const user = splitData(data, skip);
return {data: unicode(user)};
}).catch(err => {
if (err && err.message === `Cannot read property \'split\' of undefined`) {
return {data: false};
}
return {data: err.message};
});
};