linkitty 0.0.0-stage → 0.17.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.
Files changed (32) hide show
  1. package/README.en.md +70 -0
  2. package/README.md +69 -2
  3. package/THIRD_PARTY_NOTICES.md +5 -0
  4. package/artifacts.json +10 -0
  5. package/bin/linkitty.cjs +189 -0
  6. package/lib/i18n.cjs +31 -0
  7. package/lib/install.cjs +95 -0
  8. package/lib/messages.json +457 -0
  9. package/node_modules/qrcode-terminal/.travis.yml +3 -0
  10. package/node_modules/qrcode-terminal/LICENSE +222 -0
  11. package/node_modules/qrcode-terminal/README.md +82 -0
  12. package/node_modules/qrcode-terminal/bin/qrcode-terminal.js +101 -0
  13. package/node_modules/qrcode-terminal/example/basic.js +2 -0
  14. package/node_modules/qrcode-terminal/example/basic.png +0 -0
  15. package/node_modules/qrcode-terminal/example/callback.js +4 -0
  16. package/node_modules/qrcode-terminal/example/small-qrcode.js +6 -0
  17. package/node_modules/qrcode-terminal/lib/main.js +100 -0
  18. package/node_modules/qrcode-terminal/package.json +37 -0
  19. package/node_modules/qrcode-terminal/test/main.js +63 -0
  20. package/node_modules/qrcode-terminal/vendor/QRCode/QR8bitByte.js +22 -0
  21. package/node_modules/qrcode-terminal/vendor/QRCode/QRBitBuffer.js +38 -0
  22. package/node_modules/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js +7 -0
  23. package/node_modules/qrcode-terminal/vendor/QRCode/QRMaskPattern.js +10 -0
  24. package/node_modules/qrcode-terminal/vendor/QRCode/QRMath.js +44 -0
  25. package/node_modules/qrcode-terminal/vendor/QRCode/QRMode.js +6 -0
  26. package/node_modules/qrcode-terminal/vendor/QRCode/QRPolynomial.js +66 -0
  27. package/node_modules/qrcode-terminal/vendor/QRCode/QRRSBlock.js +298 -0
  28. package/node_modules/qrcode-terminal/vendor/QRCode/QRUtil.js +272 -0
  29. package/node_modules/qrcode-terminal/vendor/QRCode/index.js +462 -0
  30. package/package.json +29 -4
  31. package/payload/darwin-arm64.tgz +0 -0
  32. package/payload/linux-x64.tgz +0 -0
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ L : 1,
3
+ M : 0,
4
+ Q : 3,
5
+ H : 2
6
+ };
7
+
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ PATTERN000 : 0,
3
+ PATTERN001 : 1,
4
+ PATTERN010 : 2,
5
+ PATTERN011 : 3,
6
+ PATTERN100 : 4,
7
+ PATTERN101 : 5,
8
+ PATTERN110 : 6,
9
+ PATTERN111 : 7
10
+ };
@@ -0,0 +1,44 @@
1
+ var QRMath = {
2
+
3
+ glog : function(n) {
4
+
5
+ if (n < 1) {
6
+ throw new Error("glog(" + n + ")");
7
+ }
8
+
9
+ return QRMath.LOG_TABLE[n];
10
+ },
11
+
12
+ gexp : function(n) {
13
+
14
+ while (n < 0) {
15
+ n += 255;
16
+ }
17
+
18
+ while (n >= 256) {
19
+ n -= 255;
20
+ }
21
+
22
+ return QRMath.EXP_TABLE[n];
23
+ },
24
+
25
+ EXP_TABLE : new Array(256),
26
+
27
+ LOG_TABLE : new Array(256)
28
+
29
+ };
30
+
31
+ for (var i = 0; i < 8; i++) {
32
+ QRMath.EXP_TABLE[i] = 1 << i;
33
+ }
34
+ for (var i = 8; i < 256; i++) {
35
+ QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4]
36
+ ^ QRMath.EXP_TABLE[i - 5]
37
+ ^ QRMath.EXP_TABLE[i - 6]
38
+ ^ QRMath.EXP_TABLE[i - 8];
39
+ }
40
+ for (var i = 0; i < 255; i++) {
41
+ QRMath.LOG_TABLE[QRMath.EXP_TABLE[i] ] = i;
42
+ }
43
+
44
+ module.exports = QRMath;
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ MODE_NUMBER : 1 << 0,
3
+ MODE_ALPHA_NUM : 1 << 1,
4
+ MODE_8BIT_BYTE : 1 << 2,
5
+ MODE_KANJI : 1 << 3
6
+ };
@@ -0,0 +1,66 @@
1
+ var QRMath = require('./QRMath');
2
+
3
+ function QRPolynomial(num, shift) {
4
+ if (num.length === undefined) {
5
+ throw new Error(num.length + "/" + shift);
6
+ }
7
+
8
+ var offset = 0;
9
+
10
+ while (offset < num.length && num[offset] === 0) {
11
+ offset++;
12
+ }
13
+
14
+ this.num = new Array(num.length - offset + shift);
15
+ for (var i = 0; i < num.length - offset; i++) {
16
+ this.num[i] = num[i + offset];
17
+ }
18
+ }
19
+
20
+ QRPolynomial.prototype = {
21
+
22
+ get : function(index) {
23
+ return this.num[index];
24
+ },
25
+
26
+ getLength : function() {
27
+ return this.num.length;
28
+ },
29
+
30
+ multiply : function(e) {
31
+
32
+ var num = new Array(this.getLength() + e.getLength() - 1);
33
+
34
+ for (var i = 0; i < this.getLength(); i++) {
35
+ for (var j = 0; j < e.getLength(); j++) {
36
+ num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i) ) + QRMath.glog(e.get(j) ) );
37
+ }
38
+ }
39
+
40
+ return new QRPolynomial(num, 0);
41
+ },
42
+
43
+ mod : function(e) {
44
+
45
+ if (this.getLength() - e.getLength() < 0) {
46
+ return this;
47
+ }
48
+
49
+ var ratio = QRMath.glog(this.get(0) ) - QRMath.glog(e.get(0) );
50
+
51
+ var num = new Array(this.getLength() );
52
+
53
+ for (var i = 0; i < this.getLength(); i++) {
54
+ num[i] = this.get(i);
55
+ }
56
+
57
+ for (var x = 0; x < e.getLength(); x++) {
58
+ num[x] ^= QRMath.gexp(QRMath.glog(e.get(x) ) + ratio);
59
+ }
60
+
61
+ // recursive call
62
+ return new QRPolynomial(num, 0).mod(e);
63
+ }
64
+ };
65
+
66
+ module.exports = QRPolynomial;
@@ -0,0 +1,298 @@
1
+ var QRErrorCorrectLevel = require('./QRErrorCorrectLevel');
2
+
3
+ function QRRSBlock(totalCount, dataCount) {
4
+ this.totalCount = totalCount;
5
+ this.dataCount = dataCount;
6
+ }
7
+
8
+ QRRSBlock.RS_BLOCK_TABLE = [
9
+
10
+ // L
11
+ // M
12
+ // Q
13
+ // H
14
+
15
+ // 1
16
+ [1, 26, 19],
17
+ [1, 26, 16],
18
+ [1, 26, 13],
19
+ [1, 26, 9],
20
+
21
+ // 2
22
+ [1, 44, 34],
23
+ [1, 44, 28],
24
+ [1, 44, 22],
25
+ [1, 44, 16],
26
+
27
+ // 3
28
+ [1, 70, 55],
29
+ [1, 70, 44],
30
+ [2, 35, 17],
31
+ [2, 35, 13],
32
+
33
+ // 4
34
+ [1, 100, 80],
35
+ [2, 50, 32],
36
+ [2, 50, 24],
37
+ [4, 25, 9],
38
+
39
+ // 5
40
+ [1, 134, 108],
41
+ [2, 67, 43],
42
+ [2, 33, 15, 2, 34, 16],
43
+ [2, 33, 11, 2, 34, 12],
44
+
45
+ // 6
46
+ [2, 86, 68],
47
+ [4, 43, 27],
48
+ [4, 43, 19],
49
+ [4, 43, 15],
50
+
51
+ // 7
52
+ [2, 98, 78],
53
+ [4, 49, 31],
54
+ [2, 32, 14, 4, 33, 15],
55
+ [4, 39, 13, 1, 40, 14],
56
+
57
+ // 8
58
+ [2, 121, 97],
59
+ [2, 60, 38, 2, 61, 39],
60
+ [4, 40, 18, 2, 41, 19],
61
+ [4, 40, 14, 2, 41, 15],
62
+
63
+ // 9
64
+ [2, 146, 116],
65
+ [3, 58, 36, 2, 59, 37],
66
+ [4, 36, 16, 4, 37, 17],
67
+ [4, 36, 12, 4, 37, 13],
68
+
69
+ // 10
70
+ [2, 86, 68, 2, 87, 69],
71
+ [4, 69, 43, 1, 70, 44],
72
+ [6, 43, 19, 2, 44, 20],
73
+ [6, 43, 15, 2, 44, 16],
74
+
75
+ // 11
76
+ [4, 101, 81],
77
+ [1, 80, 50, 4, 81, 51],
78
+ [4, 50, 22, 4, 51, 23],
79
+ [3, 36, 12, 8, 37, 13],
80
+
81
+ // 12
82
+ [2, 116, 92, 2, 117, 93],
83
+ [6, 58, 36, 2, 59, 37],
84
+ [4, 46, 20, 6, 47, 21],
85
+ [7, 42, 14, 4, 43, 15],
86
+
87
+ // 13
88
+ [4, 133, 107],
89
+ [8, 59, 37, 1, 60, 38],
90
+ [8, 44, 20, 4, 45, 21],
91
+ [12, 33, 11, 4, 34, 12],
92
+
93
+ // 14
94
+ [3, 145, 115, 1, 146, 116],
95
+ [4, 64, 40, 5, 65, 41],
96
+ [11, 36, 16, 5, 37, 17],
97
+ [11, 36, 12, 5, 37, 13],
98
+
99
+ // 15
100
+ [5, 109, 87, 1, 110, 88],
101
+ [5, 65, 41, 5, 66, 42],
102
+ [5, 54, 24, 7, 55, 25],
103
+ [11, 36, 12],
104
+
105
+ // 16
106
+ [5, 122, 98, 1, 123, 99],
107
+ [7, 73, 45, 3, 74, 46],
108
+ [15, 43, 19, 2, 44, 20],
109
+ [3, 45, 15, 13, 46, 16],
110
+
111
+ // 17
112
+ [1, 135, 107, 5, 136, 108],
113
+ [10, 74, 46, 1, 75, 47],
114
+ [1, 50, 22, 15, 51, 23],
115
+ [2, 42, 14, 17, 43, 15],
116
+
117
+ // 18
118
+ [5, 150, 120, 1, 151, 121],
119
+ [9, 69, 43, 4, 70, 44],
120
+ [17, 50, 22, 1, 51, 23],
121
+ [2, 42, 14, 19, 43, 15],
122
+
123
+ // 19
124
+ [3, 141, 113, 4, 142, 114],
125
+ [3, 70, 44, 11, 71, 45],
126
+ [17, 47, 21, 4, 48, 22],
127
+ [9, 39, 13, 16, 40, 14],
128
+
129
+ // 20
130
+ [3, 135, 107, 5, 136, 108],
131
+ [3, 67, 41, 13, 68, 42],
132
+ [15, 54, 24, 5, 55, 25],
133
+ [15, 43, 15, 10, 44, 16],
134
+
135
+ // 21
136
+ [4, 144, 116, 4, 145, 117],
137
+ [17, 68, 42],
138
+ [17, 50, 22, 6, 51, 23],
139
+ [19, 46, 16, 6, 47, 17],
140
+
141
+ // 22
142
+ [2, 139, 111, 7, 140, 112],
143
+ [17, 74, 46],
144
+ [7, 54, 24, 16, 55, 25],
145
+ [34, 37, 13],
146
+
147
+ // 23
148
+ [4, 151, 121, 5, 152, 122],
149
+ [4, 75, 47, 14, 76, 48],
150
+ [11, 54, 24, 14, 55, 25],
151
+ [16, 45, 15, 14, 46, 16],
152
+
153
+ // 24
154
+ [6, 147, 117, 4, 148, 118],
155
+ [6, 73, 45, 14, 74, 46],
156
+ [11, 54, 24, 16, 55, 25],
157
+ [30, 46, 16, 2, 47, 17],
158
+
159
+ // 25
160
+ [8, 132, 106, 4, 133, 107],
161
+ [8, 75, 47, 13, 76, 48],
162
+ [7, 54, 24, 22, 55, 25],
163
+ [22, 45, 15, 13, 46, 16],
164
+
165
+ // 26
166
+ [10, 142, 114, 2, 143, 115],
167
+ [19, 74, 46, 4, 75, 47],
168
+ [28, 50, 22, 6, 51, 23],
169
+ [33, 46, 16, 4, 47, 17],
170
+
171
+ // 27
172
+ [8, 152, 122, 4, 153, 123],
173
+ [22, 73, 45, 3, 74, 46],
174
+ [8, 53, 23, 26, 54, 24],
175
+ [12, 45, 15, 28, 46, 16],
176
+
177
+ // 28
178
+ [3, 147, 117, 10, 148, 118],
179
+ [3, 73, 45, 23, 74, 46],
180
+ [4, 54, 24, 31, 55, 25],
181
+ [11, 45, 15, 31, 46, 16],
182
+
183
+ // 29
184
+ [7, 146, 116, 7, 147, 117],
185
+ [21, 73, 45, 7, 74, 46],
186
+ [1, 53, 23, 37, 54, 24],
187
+ [19, 45, 15, 26, 46, 16],
188
+
189
+ // 30
190
+ [5, 145, 115, 10, 146, 116],
191
+ [19, 75, 47, 10, 76, 48],
192
+ [15, 54, 24, 25, 55, 25],
193
+ [23, 45, 15, 25, 46, 16],
194
+
195
+ // 31
196
+ [13, 145, 115, 3, 146, 116],
197
+ [2, 74, 46, 29, 75, 47],
198
+ [42, 54, 24, 1, 55, 25],
199
+ [23, 45, 15, 28, 46, 16],
200
+
201
+ // 32
202
+ [17, 145, 115],
203
+ [10, 74, 46, 23, 75, 47],
204
+ [10, 54, 24, 35, 55, 25],
205
+ [19, 45, 15, 35, 46, 16],
206
+
207
+ // 33
208
+ [17, 145, 115, 1, 146, 116],
209
+ [14, 74, 46, 21, 75, 47],
210
+ [29, 54, 24, 19, 55, 25],
211
+ [11, 45, 15, 46, 46, 16],
212
+
213
+ // 34
214
+ [13, 145, 115, 6, 146, 116],
215
+ [14, 74, 46, 23, 75, 47],
216
+ [44, 54, 24, 7, 55, 25],
217
+ [59, 46, 16, 1, 47, 17],
218
+
219
+ // 35
220
+ [12, 151, 121, 7, 152, 122],
221
+ [12, 75, 47, 26, 76, 48],
222
+ [39, 54, 24, 14, 55, 25],
223
+ [22, 45, 15, 41, 46, 16],
224
+
225
+ // 36
226
+ [6, 151, 121, 14, 152, 122],
227
+ [6, 75, 47, 34, 76, 48],
228
+ [46, 54, 24, 10, 55, 25],
229
+ [2, 45, 15, 64, 46, 16],
230
+
231
+ // 37
232
+ [17, 152, 122, 4, 153, 123],
233
+ [29, 74, 46, 14, 75, 47],
234
+ [49, 54, 24, 10, 55, 25],
235
+ [24, 45, 15, 46, 46, 16],
236
+
237
+ // 38
238
+ [4, 152, 122, 18, 153, 123],
239
+ [13, 74, 46, 32, 75, 47],
240
+ [48, 54, 24, 14, 55, 25],
241
+ [42, 45, 15, 32, 46, 16],
242
+
243
+ // 39
244
+ [20, 147, 117, 4, 148, 118],
245
+ [40, 75, 47, 7, 76, 48],
246
+ [43, 54, 24, 22, 55, 25],
247
+ [10, 45, 15, 67, 46, 16],
248
+
249
+ // 40
250
+ [19, 148, 118, 6, 149, 119],
251
+ [18, 75, 47, 31, 76, 48],
252
+ [34, 54, 24, 34, 55, 25],
253
+ [20, 45, 15, 61, 46, 16]
254
+ ];
255
+
256
+ QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {
257
+
258
+ var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
259
+
260
+ if (rsBlock === undefined) {
261
+ throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel);
262
+ }
263
+
264
+ var length = rsBlock.length / 3;
265
+
266
+ var list = [];
267
+
268
+ for (var i = 0; i < length; i++) {
269
+
270
+ var count = rsBlock[i * 3 + 0];
271
+ var totalCount = rsBlock[i * 3 + 1];
272
+ var dataCount = rsBlock[i * 3 + 2];
273
+
274
+ for (var j = 0; j < count; j++) {
275
+ list.push(new QRRSBlock(totalCount, dataCount) );
276
+ }
277
+ }
278
+
279
+ return list;
280
+ };
281
+
282
+ QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {
283
+
284
+ switch(errorCorrectLevel) {
285
+ case QRErrorCorrectLevel.L :
286
+ return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
287
+ case QRErrorCorrectLevel.M :
288
+ return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
289
+ case QRErrorCorrectLevel.Q :
290
+ return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
291
+ case QRErrorCorrectLevel.H :
292
+ return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
293
+ default :
294
+ return undefined;
295
+ }
296
+ };
297
+
298
+ module.exports = QRRSBlock;
@@ -0,0 +1,272 @@
1
+ var QRMode = require('./QRMode');
2
+ var QRPolynomial = require('./QRPolynomial');
3
+ var QRMath = require('./QRMath');
4
+ var QRMaskPattern = require('./QRMaskPattern');
5
+
6
+ var QRUtil = {
7
+
8
+ PATTERN_POSITION_TABLE : [
9
+ [],
10
+ [6, 18],
11
+ [6, 22],
12
+ [6, 26],
13
+ [6, 30],
14
+ [6, 34],
15
+ [6, 22, 38],
16
+ [6, 24, 42],
17
+ [6, 26, 46],
18
+ [6, 28, 50],
19
+ [6, 30, 54],
20
+ [6, 32, 58],
21
+ [6, 34, 62],
22
+ [6, 26, 46, 66],
23
+ [6, 26, 48, 70],
24
+ [6, 26, 50, 74],
25
+ [6, 30, 54, 78],
26
+ [6, 30, 56, 82],
27
+ [6, 30, 58, 86],
28
+ [6, 34, 62, 90],
29
+ [6, 28, 50, 72, 94],
30
+ [6, 26, 50, 74, 98],
31
+ [6, 30, 54, 78, 102],
32
+ [6, 28, 54, 80, 106],
33
+ [6, 32, 58, 84, 110],
34
+ [6, 30, 58, 86, 114],
35
+ [6, 34, 62, 90, 118],
36
+ [6, 26, 50, 74, 98, 122],
37
+ [6, 30, 54, 78, 102, 126],
38
+ [6, 26, 52, 78, 104, 130],
39
+ [6, 30, 56, 82, 108, 134],
40
+ [6, 34, 60, 86, 112, 138],
41
+ [6, 30, 58, 86, 114, 142],
42
+ [6, 34, 62, 90, 118, 146],
43
+ [6, 30, 54, 78, 102, 126, 150],
44
+ [6, 24, 50, 76, 102, 128, 154],
45
+ [6, 28, 54, 80, 106, 132, 158],
46
+ [6, 32, 58, 84, 110, 136, 162],
47
+ [6, 26, 54, 82, 110, 138, 166],
48
+ [6, 30, 58, 86, 114, 142, 170]
49
+ ],
50
+
51
+ G15 : (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0),
52
+ G18 : (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0),
53
+ G15_MASK : (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1),
54
+
55
+ getBCHTypeInfo : function(data) {
56
+ var d = data << 10;
57
+ while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
58
+ d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) );
59
+ }
60
+ return ( (data << 10) | d) ^ QRUtil.G15_MASK;
61
+ },
62
+
63
+ getBCHTypeNumber : function(data) {
64
+ var d = data << 12;
65
+ while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
66
+ d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) );
67
+ }
68
+ return (data << 12) | d;
69
+ },
70
+
71
+ getBCHDigit : function(data) {
72
+
73
+ var digit = 0;
74
+
75
+ while (data !== 0) {
76
+ digit++;
77
+ data >>>= 1;
78
+ }
79
+
80
+ return digit;
81
+ },
82
+
83
+ getPatternPosition : function(typeNumber) {
84
+ return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
85
+ },
86
+
87
+ getMask : function(maskPattern, i, j) {
88
+
89
+ switch (maskPattern) {
90
+
91
+ case QRMaskPattern.PATTERN000 : return (i + j) % 2 === 0;
92
+ case QRMaskPattern.PATTERN001 : return i % 2 === 0;
93
+ case QRMaskPattern.PATTERN010 : return j % 3 === 0;
94
+ case QRMaskPattern.PATTERN011 : return (i + j) % 3 === 0;
95
+ case QRMaskPattern.PATTERN100 : return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 === 0;
96
+ case QRMaskPattern.PATTERN101 : return (i * j) % 2 + (i * j) % 3 === 0;
97
+ case QRMaskPattern.PATTERN110 : return ( (i * j) % 2 + (i * j) % 3) % 2 === 0;
98
+ case QRMaskPattern.PATTERN111 : return ( (i * j) % 3 + (i + j) % 2) % 2 === 0;
99
+
100
+ default :
101
+ throw new Error("bad maskPattern:" + maskPattern);
102
+ }
103
+ },
104
+
105
+ getErrorCorrectPolynomial : function(errorCorrectLength) {
106
+
107
+ var a = new QRPolynomial([1], 0);
108
+
109
+ for (var i = 0; i < errorCorrectLength; i++) {
110
+ a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0) );
111
+ }
112
+
113
+ return a;
114
+ },
115
+
116
+ getLengthInBits : function(mode, type) {
117
+
118
+ if (1 <= type && type < 10) {
119
+
120
+ // 1 - 9
121
+
122
+ switch(mode) {
123
+ case QRMode.MODE_NUMBER : return 10;
124
+ case QRMode.MODE_ALPHA_NUM : return 9;
125
+ case QRMode.MODE_8BIT_BYTE : return 8;
126
+ case QRMode.MODE_KANJI : return 8;
127
+ default :
128
+ throw new Error("mode:" + mode);
129
+ }
130
+
131
+ } else if (type < 27) {
132
+
133
+ // 10 - 26
134
+
135
+ switch(mode) {
136
+ case QRMode.MODE_NUMBER : return 12;
137
+ case QRMode.MODE_ALPHA_NUM : return 11;
138
+ case QRMode.MODE_8BIT_BYTE : return 16;
139
+ case QRMode.MODE_KANJI : return 10;
140
+ default :
141
+ throw new Error("mode:" + mode);
142
+ }
143
+
144
+ } else if (type < 41) {
145
+
146
+ // 27 - 40
147
+
148
+ switch(mode) {
149
+ case QRMode.MODE_NUMBER : return 14;
150
+ case QRMode.MODE_ALPHA_NUM : return 13;
151
+ case QRMode.MODE_8BIT_BYTE : return 16;
152
+ case QRMode.MODE_KANJI : return 12;
153
+ default :
154
+ throw new Error("mode:" + mode);
155
+ }
156
+
157
+ } else {
158
+ throw new Error("type:" + type);
159
+ }
160
+ },
161
+
162
+ getLostPoint : function(qrCode) {
163
+
164
+ var moduleCount = qrCode.getModuleCount();
165
+ var lostPoint = 0;
166
+ var row = 0;
167
+ var col = 0;
168
+
169
+
170
+ // LEVEL1
171
+
172
+ for (row = 0; row < moduleCount; row++) {
173
+
174
+ for (col = 0; col < moduleCount; col++) {
175
+
176
+ var sameCount = 0;
177
+ var dark = qrCode.isDark(row, col);
178
+
179
+ for (var r = -1; r <= 1; r++) {
180
+
181
+ if (row + r < 0 || moduleCount <= row + r) {
182
+ continue;
183
+ }
184
+
185
+ for (var c = -1; c <= 1; c++) {
186
+
187
+ if (col + c < 0 || moduleCount <= col + c) {
188
+ continue;
189
+ }
190
+
191
+ if (r === 0 && c === 0) {
192
+ continue;
193
+ }
194
+
195
+ if (dark === qrCode.isDark(row + r, col + c) ) {
196
+ sameCount++;
197
+ }
198
+ }
199
+ }
200
+
201
+ if (sameCount > 5) {
202
+ lostPoint += (3 + sameCount - 5);
203
+ }
204
+ }
205
+ }
206
+
207
+ // LEVEL2
208
+
209
+ for (row = 0; row < moduleCount - 1; row++) {
210
+ for (col = 0; col < moduleCount - 1; col++) {
211
+ var count = 0;
212
+ if (qrCode.isDark(row, col ) ) count++;
213
+ if (qrCode.isDark(row + 1, col ) ) count++;
214
+ if (qrCode.isDark(row, col + 1) ) count++;
215
+ if (qrCode.isDark(row + 1, col + 1) ) count++;
216
+ if (count === 0 || count === 4) {
217
+ lostPoint += 3;
218
+ }
219
+ }
220
+ }
221
+
222
+ // LEVEL3
223
+
224
+ for (row = 0; row < moduleCount; row++) {
225
+ for (col = 0; col < moduleCount - 6; col++) {
226
+ if (qrCode.isDark(row, col) &&
227
+ !qrCode.isDark(row, col + 1) &&
228
+ qrCode.isDark(row, col + 2) &&
229
+ qrCode.isDark(row, col + 3) &&
230
+ qrCode.isDark(row, col + 4) &&
231
+ !qrCode.isDark(row, col + 5) &&
232
+ qrCode.isDark(row, col + 6) ) {
233
+ lostPoint += 40;
234
+ }
235
+ }
236
+ }
237
+
238
+ for (col = 0; col < moduleCount; col++) {
239
+ for (row = 0; row < moduleCount - 6; row++) {
240
+ if (qrCode.isDark(row, col) &&
241
+ !qrCode.isDark(row + 1, col) &&
242
+ qrCode.isDark(row + 2, col) &&
243
+ qrCode.isDark(row + 3, col) &&
244
+ qrCode.isDark(row + 4, col) &&
245
+ !qrCode.isDark(row + 5, col) &&
246
+ qrCode.isDark(row + 6, col) ) {
247
+ lostPoint += 40;
248
+ }
249
+ }
250
+ }
251
+
252
+ // LEVEL4
253
+
254
+ var darkCount = 0;
255
+
256
+ for (col = 0; col < moduleCount; col++) {
257
+ for (row = 0; row < moduleCount; row++) {
258
+ if (qrCode.isDark(row, col) ) {
259
+ darkCount++;
260
+ }
261
+ }
262
+ }
263
+
264
+ var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
265
+ lostPoint += ratio * 10;
266
+
267
+ return lostPoint;
268
+ }
269
+
270
+ };
271
+
272
+ module.exports = QRUtil;