-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
24 lines (22 loc) · 983 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
import inquirer from "inquirer";
import qr from "qr-image";
import fs from "fs";
const path = "./out/QR_Library"
const contents = "./out/QR_Contents.txt"
inquirer.prompt([{name: "data", message: "Convert my data:"}, {name: "type", type: "list", message: "Type:", choices: [{name: "PNG"}, {name: "SVG"}]}]).then((answers) => {
const data = answers.data;
const type = answers.type;
const qr_img = qr.image(data, {type: type});
const fileLines = fs.readdirSync(path).length;
qr_img.pipe(fs.createWriteStream(`${path}/QR${fileLines !== 1 ? " " + fileLines : ""}.${type.toLowerCase()}`));
fs.writeFile(contents, `QR ${fileLines !== 1 ? fileLines + " " : ""}(${type.toUpperCase()}) : ${data}\n`, {flag: "a", encoding: "utf-8"}, (err) => {
if (err) console.log("Error!", err);
else console.log("Successful!");
})
}).catch(e => {
if (e.isTtyError) {
console.log("Please run in a Terminal");
} else {
console.log("Oops! Error occured:\n", e);
}
})