-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (41 loc) · 901 Bytes
/
index.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
#!/usr/bin/env node
import got from "got";
import meow from "meow";
import clipboard from 'clipboardy';
import {createSpinner} from "nanospinner";
const cli = meow(`
Usage
$ publicip <options>
Options
--copy, -c Copy the adress to the clipboard
--v6, -6 Fetches IPv6 address
Examples
$ publicip -c
95.90.201.234 - Copied!
`, {
importMeta: import.meta,
flags: {
copy: {
type: 'boolean',
alias: 'c'
},
v6: {
type: 'boolean',
alias: '6'
}
}
});
const spinner = createSpinner('Fetching IP...').start()
let text;
if(cli.flags.v6) {
text = await got('https://api64.ipify.org').text();
} else {
text = await got('https://api.ipify.org').text();
}
if(cli.flags.copy) {
clipboard.writeSync(text);
text += ' - Copied! ✅';
}
spinner.clear();
spinner.reset();
console.log(text);