File tree 1 file changed +28
-4
lines changed
1 file changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -20,17 +20,41 @@ const log = {
20
20
} ;
21
21
22
22
function genQRCode ( s ) {
23
+ const blockChars = [
24
+ ' ' , // 0
25
+ '▘' , // 1
26
+ '▝' , // 2
27
+ '▀' , // 3
28
+ '▖' , // 4
29
+ '▌' , // 5
30
+ '▞' , // 6
31
+ '▛' , // 7
32
+ '▗' , // 8
33
+ '▚' , // 9
34
+ '▐' , // 10
35
+ '▜' , // 11
36
+ '▄' , // 12
37
+ '▙' , // 13
38
+ '▟' , // 14
39
+ '█' , // 15
40
+ ] ;
41
+
23
42
const qr = QrCode . encodeText ( s , Ecc . MEDIUM ) ;
43
+ const size = ( ( qr . size + 1 ) / 2 | 0 ) * 2 + 2 ;
24
44
25
45
const lines = [ ] ;
26
- for ( let y = 0 ; y < qr . size ; y ++ ) {
46
+ for ( let y = - 2 ; y < size ; y += 2 ) {
27
47
const line = [ ] ;
28
- for ( let x = 0 ; x < qr . size ; x ++ ) {
29
- line . push ( c [ qr . getModule ( x , y ) ? 'bgBlack' : 'bgWhite' ] ( ' ' ) ) ;
48
+ for ( let x = - 2 ; x < size ; x += 1 ) {
49
+ const code = ( qr . getModule ( x + 0 , y + 0 ) ? 1 : 0 ) |
50
+ ( qr . getModule ( x + 0 , y + 0 ) ? 2 : 0 ) |
51
+ ( qr . getModule ( x + 0 , y + 1 ) ? 4 : 0 ) |
52
+ ( qr . getModule ( x + 0 , y + 1 ) ? 8 : 0 ) ;
53
+ line . push ( blockChars [ code ] ) ;
30
54
}
31
55
lines . push ( line . join ( '' ) ) ;
32
56
}
33
- return lines . join ( '\n' ) ;
57
+ return c . bgWhite ( c . black ( lines . join ( '\n' ) ) ) ;
34
58
}
35
59
36
60
const optionSpec = {
You can’t perform that action at this time.
0 commit comments