Skip to content

Commit d199d9c

Browse files
committed
Ran linter on examples
1 parent 564ec5a commit d199d9c

File tree

5 files changed

+42
-35
lines changed

5 files changed

+42
-35
lines changed

benchmarks/node/speed-benchmark.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
#!/usr/bin/env node
22
const path = require('path');
3-
const { createWorker } = require('../../');
3+
const { createWorker } = require('../..');
44

55
(async () => {
66
const worker = await createWorker();
7-
const fileArr = ["../data/meditations.jpg", "../data/tyger.jpg", "../data/testocr.png"];
7+
const fileArr = [
8+
path.join(__dirname, '..', 'data', 'meditations.jpg'),
9+
path.join(__dirname, '..', 'data', 'tyger.jpg'),
10+
path.join(__dirname, '..', 'data', 'testocr.png'),
11+
];
812
let timeTotal = 0;
9-
for (let file of fileArr) {
10-
let time1 = Date.now();
11-
for (let i=0; i < 10; i++) {
12-
await worker.recognize(file)
13-
}
14-
let time2 = Date.now();
15-
const timeDif = (time2 - time1) / 1e3;
16-
timeTotal += timeDif;
17-
18-
console.log(file + " [x10] runtime: " + timeDif + "s");
13+
for (const file of fileArr) {
14+
const time1 = Date.now();
15+
for (let i = 0; i < 10; i++) {
16+
// eslint-disable-next-line no-await-in-loop
17+
await worker.recognize(file);
1918
}
20-
console.log("Total runtime: " + timeTotal + "s");
19+
const time2 = Date.now();
20+
const timeDif = (time2 - time1) / 1e3;
21+
timeTotal += timeDif;
22+
23+
console.log(`${file} [x10] runtime: ${timeDif}s`);
24+
}
25+
console.log(`Total runtime: ${timeTotal}s`);
2126

22-
await worker.terminate();
27+
await worker.terminate();
2328
})();

examples/node/download-pdf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
const path = require('path');
33
const fs = require('fs');
4-
const { createWorker } = require('../../');
4+
const { createWorker } = require('../..');
55

66
const [,, imagePath] = process.argv;
77
const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/cosmic.png'));
@@ -10,7 +10,7 @@ console.log(`Recognizing ${image}`);
1010

1111
(async () => {
1212
const worker = await createWorker();
13-
const { data: { text, pdf } } = await worker.recognize(image, {pdfTitle: "Example PDF"}, {pdf: true});
13+
const { data: { text, pdf } } = await worker.recognize(image, { pdfTitle: 'Example PDF' }, { pdf: true });
1414
console.log(text);
1515
fs.writeFileSync('tesseract-ocr-result.pdf', Buffer.from(pdf));
1616
console.log('Generate PDF: tesseract-ocr-result.pdf');

examples/node/image-processing.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
#!/usr/bin/env node
22
const path = require('path');
33
const fs = require('fs');
4-
const { createWorker } = require('../../');
4+
const { createWorker } = require('../..');
55

66
const [,, imagePath] = process.argv;
77
const image = path.resolve(__dirname, (imagePath || '../data/meditations.jpg'));
88

99
console.log(`Recognizing ${image}`);
1010

11-
// Tesseract.js returns images (imageColor, imageGrey, imageBinary) as strings
11+
// Tesseract.js returns images (imageColor, imageGrey, imageBinary) as strings
1212
// to be used as source tags.
13-
// This function converts to Uint8Array data for saving to disk.
13+
// This function converts to Uint8Array data for saving to disk.
1414
const convertImage = (imageSrc) => {
1515
const data = atob(imageSrc.split(',')[1])
16-
.split('')
17-
.map((c) => c.charCodeAt(0));
16+
.split('')
17+
.map((c) => c.charCodeAt(0));
1818

1919
return new Uint8Array(data);
20-
}
20+
};
2121

2222
(async () => {
2323
const worker = await createWorker();
24-
const { data: { imageColor, imageGrey, imageBinary } } = await worker.recognize(image, {rotateAuto: true}, {imageColor: true, imageGrey: true, imageBinary: true});
25-
24+
const { data: { imageColor, imageGrey, imageBinary } } = await worker.recognize(image,
25+
{ rotateAuto: true }, { imageColor: true, imageGrey: true, imageBinary: true });
26+
2627
console.log('Saving intermediate images: imageColor.png, imageGrey.png, imageBinary.png');
2728

2829
fs.writeFileSync('imageColor.png', convertImage(imageColor));

examples/node/recognize.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env node
22
const path = require('path');
3-
const { createWorker } = require('../../');
3+
const { createWorker } = require('../..');
44

55
const [,, imagePath] = process.argv;
66
const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/cosmic.png'));
77

88
console.log(`Recognizing ${image}`);
99

1010
(async () => {
11-
const worker = await createWorker("eng", 1, {
12-
logger: m => console.log(m),
13-
});
11+
const worker = await createWorker('eng', 1, {
12+
logger: (m) => console.log(m),
13+
});
1414
const { data: { text } } = await worker.recognize(image);
1515
console.log(text);
1616
await worker.terminate();

examples/node/scheduler.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const { createWorker, createScheduler } = require('../../');
21
const path = require('path');
2+
const { createWorker, createScheduler } = require('../..');
3+
34
const [,, imagePath] = process.argv;
45

5-
// Note: This example recognizes the same image 4 times in parallel
6+
// Note: This example recognizes the same image 4 times in parallel
67
// to show how schedulers can be used to speed up bulk jobs.
7-
// In actual use you would (obviously) not want to run multiple identical jobs.
8+
// In actual use you would (obviously) not want to run multiple identical jobs.
89

910
const image = path.resolve(__dirname, (imagePath || '../../tests/assets/images/cosmic.png'));
1011
const imageArr = [image, image, image, image];
@@ -13,14 +14,14 @@ const scheduler = createScheduler();
1314

1415
// Creates worker and adds to scheduler
1516
const workerGen = async () => {
16-
const worker = await createWorker("eng", 1, {cachePath: "."});
17+
const worker = await createWorker('eng', 1, { cachePath: '.' });
1718
scheduler.addWorker(worker);
18-
}
19+
};
1920

2021
const workerN = 4;
2122
(async () => {
2223
const resArr = Array(workerN);
23-
for (let i=0; i<workerN; i++) {
24+
for (let i = 0; i < workerN; i++) {
2425
resArr[i] = workerGen();
2526
}
2627
await Promise.all(resArr);
@@ -34,4 +35,4 @@ const workerN = 4;
3435
await Promise.all(resArr2);
3536

3637
await scheduler.terminate(); // It also terminates all workers.
37-
})();
38+
})();

0 commit comments

Comments
 (0)