-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 808 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
import inquirer from 'inquirer';
import qr from 'qr-image';
import fs from 'fs';
inquirer
.prompt([
{
message: "Type in your URL",
name: "URL",
},
])
.then((answers) => {
const url = answers.URL;
var qr_svg = qr.image(url);
const sanitizedUrl = url.replace(/[^a-z0-9]/gi, '_');
qr_svg.pipe(fs.createWriteStream(`${sanitizedUrl}.png`));
fs.writeFile("URL.txt", url, (err) => {
if (err) throw err;
console.log("The file has been saved!");
});
})
.catch((error) => {
if (error.isTtyError) {
console.error("Prompt couldn't be rendered in the current environment");
} else {
console.error("Something else went wrong");
}
});