-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
58 lines (48 loc) · 924 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
47
48
49
50
51
52
53
54
55
56
/**
* Module Dependencies
*/
var qrcode = require('./qr-code');
/**
* Export `QR`
*/
module.exports = QR;
/**
* Initialize `QR`
*
* @param {String} text
* @param {Object} opts
*/
function QR(text, opts) {
text = text || '';
opts = opts || {};
var type = opts.type || 4;
var level = opts.level || 'L';
var size = opts.size || 4;
var margin = opts.margin || 0;
var qr = qrcode(type, level);
qr.addData(text);
qr.make();
// Get the source
var img = qr.createImgTag(size, margin);
var o = document.createElement('div');
o.innerHTML = img;
return o.firstChild.src;
}
/**
* Specify the backup level. Default is 'M'
*
* Options include:
*
* L: up to 7% damage
* M: up to 15% damage
* Q: up to 25% damage
* H: up to 30% damage
*
* @param {String} level
* @return {QR}
* @api public
*/
QR.prototype.level = function(level) {
this._level = level;
return this;
}