forked from BloomTech-Labs/Labs8-MusicMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qrcode.js
47 lines (37 loc) · 1.15 KB
/
qrcode.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
var QRCode = require('qrcode');
// this is the general QR code creation function, takes a string and returns the code
// using both console logs and returns for testing purposes
// adding a random string generator to test a variety of cases rather than a simple 'test' string each time
// 16 characters for now
let stringGen = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 16);
let code = QRCode.toString(stringGen, function (err, string) {
if(err) throw err;
console.log(string);
});
// this is the version we'll want to store in the database, returns the QR code data itself
let data = QRCode.toDataURL(stringGen, function (err, url) {
if(err) throw err;
console.log(url);
});
return code;
return data;
// async versions for reference and implementation if desired
// promise
// let asyncData = QRCode.toDataURL('async test')
// .then(url => {
// console.log(url)
// return(url)
// })
// .catch(err => {
// console.error(err.message)
// });
//
// // await
//
// const asyncAwait = async url => {
// try {
// console.log(await QRCode.toDataURL(url))
// } catch (err) {
// console.error(err.message)
// }
// }