-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl.js
51 lines (43 loc) · 1.24 KB
/
curl.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
const commandLineArgs = require('command-line-args');
const fetch = require('node-fetch');
const fs = require('fs');
const optionDefinitions = [
{
name: 'value',
alias: 'h',
type: Number,
description: 'Display this guide man'
},
{
name: 'output',
alias: 'o',
type: String,
description: 'File to store fetched content'
},
{
name: 'asci',
alias: 'a',
type: String,
description: 'Write text in ASCII art'
}
]
const options = commandLineArgs(optionDefinitions, {stopAtFirstUnknown: true});
if(options.asci){
let baseURL = 'https://artii.herokuapp.com/make?text=';
let wordsToConvert = '';
if(options._unknown){
wordsToConvert = options.asci + '++' + options._unknown.join('++');
} else {
wordsToConvert = options.asci
}
fetch(baseURL + wordsToConvert)
.then(res => res.text())
.then(body => console.log(body))
.catch(err => console.log(`Im sure its not your fault but...\n${err}`))
}
if(options.output){
fetch(options._unknown[0])
.then(res => res.text())
.then(body => fs.promises.writeFile(options.output, body))
.catch(err => console.log(err))
}