-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
executable file
·52 lines (43 loc) · 1.36 KB
/
cli.js
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
50
51
52
#!/usr/bin/env node
'use strict';
const dns = require('dns');
const got = require('got');
const chalk = require('chalk');
const logUpdate = require('log-update');
const ora = require('ora');
const updateNotifier = require('update-notifier');
const pkg = require('./package.json');
updateNotifier({pkg}).notify();
const arg = process.argv[2];
const end = process.exit;
const spinner = ora();
const profile = `https://instagram.com/${arg}`;
if (!arg || arg === '-h' || arg === '--help') {
console.log(`
${chalk.cyan('Usage')} : insta-id-of <username>
${chalk.cyan('Example')} : insta-id-of 9gag
${chalk.cyan('Help')} : insta-id-of ${chalk.dim('-h or --help')}
`);
end(1);
}
dns.lookup('instagram.com', err => {
if (err) {
logUpdate(`\n ${chalk.red('›')} ${chalk.dim('Please check your internet connection!')} \n`);
end(1);
} else {
logUpdate();
spinner.text = chalk.blue('Fetching...');
spinner.start();
got(profile).then(res => {
const userId = res.body.split(',"id":"')[1].split('",')[0];
const userName = res.body.split(',"full_name":"')[1].split('",')[0] || arg;
logUpdate(`\n${chalk.cyan('›')} User ID of ${chalk.cyan(userName)} is ${chalk.yellow(userId)} \n`);
spinner.stop();
}).catch(err => {
if (err) {
logUpdate(`\n${chalk.red('›')} ${chalk.yellow(arg)} is not an instagram user! \n`);
end(1);
}
});
}
});