qr-min 0.0.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,72 @@
8
8
  Minimal implementation to generate a QR code from a UTF-8 string.
9
9
  This is all you need for 99.9% of applications.
10
10
 
11
- Pure JavaScript. No dependencies.
11
+ Pure JavaScript. No dependencies. Works in browser and Node.js.
12
12
 
13
13
  If you need finer control over QR code generation,
14
- please check https://github.com/nayuki/QR-Code-generator
14
+ please check https://github.com/nayuki/QR-Code-generator
15
+
16
+ ## Usage
17
+
18
+ ##### Plain HTML
19
+
20
+ ```html
21
+ <script src="qr-min.js"></script>
22
+ ```
23
+
24
+ ##### CDN (jsdelivr)
25
+
26
+ ```html
27
+ <script src="https://cdn.jsdelivr.net/npm/qr-min"></script>
28
+ ```
29
+
30
+ ##### CDN (unpkg)
31
+
32
+ ```html
33
+ <script src="https://unpkg.com/qr-min"></script>
34
+ ```
35
+
36
+ ##### Node.js
37
+
38
+ ```js
39
+ const QR = require('qr-min');
40
+ ```
41
+
42
+ ## API
43
+
44
+ `QR(...)` - the only function in this package.
45
+ Takes a string and returns a 2-dimensional array of the dots in the QR code.
46
+ Use this data to produce an image in your own artistic style.
47
+
48
+ ##### Example
49
+ ```js
50
+ const QR = require('qr-min');
51
+ const qr = QR('https://github.com/jazz-soft/qr-min');
52
+ var i, j, s = '';
53
+ for (i = 0; i < qr.length; i += 2) {
54
+ for (j = 0; j < qr.length; j++) s += i + 1 < qr.length && qr[i + 1][j] ? qr[i][j] ? '█' : '▄' : qr[i][j] ? '▀' : ' ';
55
+ s += '\n';
56
+ }
57
+ console.log(s);
58
+ ```
59
+ This will produce the following output:
60
+ ```
61
+ █▀▀▀▀▀█ ▄▀ ▄▀ ▀ █ █▀▀▀▀▀█
62
+ █ ███ █ ▀▄ ▀▄▄ ▀ ▀▀█ █ ███ █
63
+ █ ▀▀▀ █ ▀▄▄█▀▄▄▀███▄ █ ▀▀▀ █
64
+ ▀▀▀▀▀▀▀ █ ▀▄▀ ▀ █▄█▄▀ ▀▀▀▀▀▀▀
65
+ █▀▀▄██▀▀█▄ ▄█▄ ▀██▄ █▀█ ▄▀ ▄
66
+ █ ▄ █▄▀ ▄▄█▀█▄█▄ ██ ▀▀▀▄█ ▀█▀
67
+ █▄ ▄ █▀▀ ██ █▀█▀ ▀███ █ ▀█
68
+ ▀█▀█▄▀▀█▄ ▀▄ ▀ ▄▄█▄ ▄▄█ ▀█ █▀
69
+ █▄▀█▀ ▄ ▄█▄ ▀██ ▀▀▄█▀ █▄▀█
70
+ ▀▄▄▄ █▀ ▄▀ ▀█▄█▄▄█ ▄▄█▄██▄ █▀
71
+ ▀ ▀ ▀ ▄▀██ █▀▀█▄██▀▀▀█ ▄▄▄
72
+ █▀▀▀▀▀█ █ █▄ ▀ ▀▄ ▀█ ▀ ██ ▀█
73
+ █ ███ █ ▀▀█▄█▄ ▄▀▀ █▀▀██ ▄▄█
74
+ █ ▀▀▀ █ █▄ ▀█▄█▄ █▄█▄▄ ▀█▀ ▄▀
75
+ ▀▀▀▀▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀ ▀▀ ▀▀
76
+ ```
77
+ Sorry, it doesn’t look very impressive in the Markdown document, but it works nevertheless! :)
78
+
79
+ See more examples of generating SVG and Canvas images in this repository.
@@ -143,6 +143,17 @@
143
143
  }
144
144
  }
145
145
  d[sz - 8][8] = 1;
146
+ if (v > 6) {
147
+ m = v;
148
+ for (k = 0; k < 12; k++) m = (m << 1) ^ ((m >>> 11) * 0x1F25);
149
+ m = v << 12 | m;
150
+ for (k = 0; k < 18; k++) {
151
+ i = sz - 11 + k % 3;
152
+ j = Math.floor(k / 3);
153
+ d[i][j] = (m & (1 << k)) >>> k;
154
+ d[j][i] = (m & (1 << k)) >>> k;
155
+ }
156
+ }
146
157
  }
147
158
  function _res(v) {
148
159
  var i, j, k, m, sz = v * 4 + 17, e = _eyes(v);
@@ -168,6 +179,10 @@
168
179
  r[e[k] + i - 2][e[m] + j - 2] = 1;
169
180
  }
170
181
  }
182
+ if (v > 6) for (i = 0; i < 6; i++) for (j = 0; j < 3; j++) {
183
+ r[i][sz - j - 9] = 1;
184
+ r[sz - j - 9][i] = 1;
185
+ }
171
186
  return r;
172
187
  }
173
188
  function _format(d, c, m) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qr-min",
3
- "version": "0.0.2",
3
+ "version": "1.0.0",
4
4
  "description": "Minimal implementation to generate a QR code from a UTF-8 string",
5
5
  "main": "javascript/qr-min.js",
6
6
  "scripts": {
package/test/mocha.js DELETED
@@ -1,48 +0,0 @@
1
- var assert = require('assert');
2
- var QR = require('..');
3
-
4
- function text(qr) {
5
- var i, j, s = '';
6
- for (i = 0; i < qr.length; i += 2) {
7
- for (j = 0; j < qr.length; j++) s += i + 1 < qr.length && qr[i + 1][j] ? qr[i][j] ? '█' : '▄' : qr[i][j] ? '▀' : ' ';
8
- s += '\n';
9
- }
10
- return s;
11
- }
12
-
13
- describe('qr', function() {
14
- it('short', function() {
15
- assert.equal(text(QR('a')),`
16
- █▀▀▀▀▀█ █▄█▀ █▀▀▀▀▀█
17
- █ ███ █ ▀█ █▀ █ ███ █
18
- █ ▀▀▀ █ ▀ █ █ ▀▀▀ █
19
- ▀▀▀▀▀▀▀ █▄▀▄█ ▀▀▀▀▀▀▀
20
- ▀▀█ ██▀█▀▀█▀ ▀█ █▄
21
- ▄▄ ▄▀▄▀▀▀██ ▀ ▄ ▀ ▄ ▀
22
- ▀▀ ▀▀▀▀▄▄ ▄▀▄▀▄▀▄▀▄█
23
- █▀▀▀▀▀█ █▄▄█▄█▀█▄█▀▀▀
24
- █ ███ █ ▀ █▀ ▀█▀ ▀█▄▀
25
- █ ▀▀▀ █ ██ ▀ ▄ ▀ ▄▄▀
26
- ▀▀▀▀▀▀▀ ▀▀ ▀ ▀ ▀ ▀▀▀
27
- `.substring(1));
28
- });
29
- it('medium', function() {
30
- assert.equal(text(QR('https://github.com/jazz-soft/qr-min')),`
31
- █▀▀▀▀▀█ ▄▀ ▄▀ ▀ █ █▀▀▀▀▀█
32
- █ ███ █ ▀▄ ▀▄▄ ▀ ▀▀█ █ ███ █
33
- █ ▀▀▀ █ ▀▄▄█▀▄▄▀███▄ █ ▀▀▀ █
34
- ▀▀▀▀▀▀▀ █ ▀▄▀ ▀ █▄█▄▀ ▀▀▀▀▀▀▀
35
- █▀▀▄██▀▀█▄ ▄█▄ ▀██▄ █▀█ ▄▀ ▄
36
- █ ▄ █▄▀ ▄▄█▀█▄█▄ ██ ▀▀▀▄█ ▀█▀
37
- █▄ ▄ █▀▀ ██ █▀█▀ ▀███ █ ▀█
38
- ▀█▀█▄▀▀█▄ ▀▄ ▀ ▄▄█▄ ▄▄█ ▀█ █▀
39
- █▄▀█▀ ▄ ▄█▄ ▀██ ▀▀▄█▀ █▄▀█
40
- ▀▄▄▄ █▀ ▄▀ ▀█▄█▄▄█ ▄▄█▄██▄ █▀
41
- ▀ ▀ ▀ ▄▀██ █▀▀█▄██▀▀▀█ ▄▄▄
42
- █▀▀▀▀▀█ █ █▄ ▀ ▀▄ ▀█ ▀ ██ ▀█
43
- █ ███ █ ▀▀█▄█▄ ▄▀▀ █▀▀██ ▄▄█
44
- █ ▀▀▀ █ █▄ ▀█▄█▄ █▄█▄▄ ▀█▀ ▄▀
45
- ▀▀▀▀▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀ ▀▀ ▀▀
46
- `.substring(1));
47
- });
48
- });