Skip to content

Commit ede8f9a

Browse files
committed
upd
1 parent c67943d commit ede8f9a

File tree

6 files changed

+63
-30
lines changed

6 files changed

+63
-30
lines changed

src/QR8bitByte.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class QR8bitByte {
55

66
data: string;
77

8-
parsedData = [];
8+
parsedData: (number[] | number)[] = [];
99

1010
constructor(data) {
1111
this.data = data;
@@ -14,23 +14,32 @@ export class QR8bitByte {
1414
let i = 0;
1515
const l = this.data.length;
1616
for (; i < l; i++) {
17-
const byteArray = [];
1817
const code = this.data.charCodeAt(i);
1918

19+
let byteArray: number[];
2020
if (code > 0x10000) {
21-
byteArray[0] = 0xf0 | ((code & 0x1c0000) >>> 18);
22-
byteArray[1] = 0x80 | ((code & 0x3f000) >>> 12);
23-
byteArray[2] = 0x80 | ((code & 0xfc0) >>> 6);
24-
byteArray[3] = 0x80 | (code & 0x3f);
21+
// prettier-ignore
22+
byteArray = [
23+
0xf0 | ((code & 0x1c0000) >>> 18),
24+
0x80 | ((code & 0x3f000) >>> 12),
25+
0x80 | ((code & 0xfc0) >>> 6),
26+
0x80 | (code & 0x3f),
27+
];
2528
} else if (code > 0x800) {
26-
byteArray[0] = 0xe0 | ((code & 0xf000) >>> 12);
27-
byteArray[1] = 0x80 | ((code & 0xfc0) >>> 6);
28-
byteArray[2] = 0x80 | (code & 0x3f);
29+
// prettier-ignore
30+
byteArray = [
31+
0xe0 | ((code & 0xf000) >>> 12),
32+
0x80 | ((code & 0xfc0) >>> 6),
33+
0x80 | (code & 0x3f),
34+
]
2935
} else if (code > 0x80) {
30-
byteArray[0] = 0xc0 | ((code & 0x7c0) >>> 6);
31-
byteArray[1] = 0x80 | (code & 0x3f);
36+
// prettier-ignore
37+
byteArray = [
38+
0xc0 | ((code & 0x7c0) >>> 6),
39+
0x80 | (code & 0x3f),
40+
]
3241
} else {
33-
byteArray[0] = code;
42+
byteArray = [code];
3443
}
3544

3645
this.parsedData.push(byteArray);

src/QRBitBuffer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export class QRBitBuffer {
2-
buffer = [];
2+
buffer: number[] = [];
33

44
length = 0;
55

src/QRCode.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { QRCodeLimitLength } from './QRCodeLimitLength';
44
import { getProp } from './utils';
55

66
type QRCodeOptions = {
7-
padding: number;
87
size: number;
98
circleCorners: boolean;
109
typeNumber: number;
@@ -19,7 +18,6 @@ type QRCodeOptions = {
1918

2019
export class QRCode {
2120
options: QRCodeOptions = {
22-
padding: 0,
2321
size: 256,
2422
circleCorners: false,
2523
typeNumber: 4,
@@ -44,18 +42,10 @@ export class QRCode {
4442
}
4543
}
4644

47-
if (typeof this.options.content !== 'string') {
48-
throw new Error("Expected 'content' as string!");
49-
}
50-
5145
if (this.options.content.length === 0 /* || this.options.content.length > 7089 */) {
5246
throw new Error("Expected 'content' to be non-empty!");
5347
}
5448

55-
if (!(this.options.padding >= 0)) {
56-
throw new Error("Expected 'padding' value to be non-negative!");
57-
}
58-
5949
if (!(this.options.size > 0)) {
6050
throw new Error("Expected 'size' or 'height' value to be higher than zero!");
6151
}
@@ -150,9 +140,7 @@ export class QRCode {
150140
const options = this.options;
151141
const modules = this.qrcode.modules;
152142

153-
//Apply new lines and indents in SVG?
154-
const pretty = typeof options.pretty != 'undefined' ? !!options.pretty : true;
155-
143+
const pretty = options.pretty;
156144
const indent = pretty ? ' ' : '';
157145
const EOL = pretty ? '\r\n' : '';
158146
const width = options.size;

src/QRCodeModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const PAD1 = 0x11;
1010
export class QRCodeModel {
1111
typeNumber!: number;
1212
errorCorrectLevel!: number;
13-
modules = null;
13+
modules: (boolean | null)[][] = [];
1414
moduleCount = 0;
15-
dataCache = null;
16-
dataList = [];
15+
dataCache: number[] | null = null;
16+
dataList: QR8bitByte[] = [];
1717

1818
constructor(typeNumber, errorCorrectLevel) {
1919
this.typeNumber = typeNumber;

src/QRRSBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class QRRSBlock {
178178
throw new Error('bad rs block @ typeNumber:' + typeNumber + '/errorCorrectLevel:' + errorCorrectLevel);
179179
}
180180
const length = rsBlock.length / 3;
181-
const list = [];
181+
const list: QRRSBlock[] = [];
182182
for (let i = 0; i < length; i++) {
183183
const count = rsBlock[i * 3];
184184
const totalCount = rsBlock[i * 3 + 1];

tsconfig.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"lib": [
6+
"dom",
7+
"dom.iterable",
8+
"esnext"
9+
],
10+
"allowJs": true,
11+
"skipLibCheck": true,
12+
"esModuleInterop": true,
13+
"allowSyntheticDefaultImports": true,
14+
"strict": true,
15+
"noImplicitAny": false,
16+
"strictNullChecks": true,
17+
"forceConsistentCasingInFileNames": true,
18+
"moduleResolution": "node",
19+
"resolveJsonModule": true,
20+
"isolatedModules": true,
21+
"noEmit": true,
22+
"typeRoots": [
23+
"./node_modules/@types",
24+
"./src/types"
25+
],
26+
"noFallthroughCasesInSwitch": true
27+
},
28+
"include": [
29+
"src"
30+
],
31+
"exclude": [
32+
"demo",
33+
"node_modules",
34+
"**/*.spec.ts",
35+
]
36+
}

0 commit comments

Comments
 (0)