ocr-space-api-wrapper 2.4.4 → 2.4.6
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 +1 -0
- package/index.d.ts +1 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/test/test.js +12 -9
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ The input param specifies the input file (see examples above). It can be _one_ o
|
|
|
39
39
|
This param is an object with the following keys:
|
|
40
40
|
- `apiKey`: your API key for [ocr.space APIs](https://ocr.space/ocrapi). Default API key has a limit of max 10reqs in 10mins.
|
|
41
41
|
- `ocrUrl`: a different URL for ocr.space APIs, for example when you purchase the PRO plan.
|
|
42
|
+
- `signal`: an `AbortSignal` for `AbortController` to abort the request.
|
|
42
43
|
- All other params as documented in the [official website](https://ocr.space/OCRAPI#PostParameters).
|
|
43
44
|
|
|
44
45
|
## Response
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -28,6 +28,7 @@ async function ocrSpace(input, options = {}) {
|
|
|
28
28
|
apiKey, ocrUrl, language, isOverlayRequired,
|
|
29
29
|
filetype, detectOrientation, isCreateSearchablePdf,
|
|
30
30
|
isSearchablePdfHideTextLayer, scale, isTable, OCREngine,
|
|
31
|
+
signal,
|
|
31
32
|
} = options;
|
|
32
33
|
const formData = new FormData();
|
|
33
34
|
const detectedInput = detectInput(input);
|
|
@@ -66,11 +67,13 @@ async function ocrSpace(input, options = {}) {
|
|
|
66
67
|
data: formData,
|
|
67
68
|
maxContentLength: Infinity,
|
|
68
69
|
maxBodyLength: Infinity,
|
|
70
|
+
signal,
|
|
69
71
|
};
|
|
70
72
|
const { data } = await axios(request);
|
|
71
73
|
return data;
|
|
72
74
|
} catch (error) {
|
|
73
75
|
console.error(error);
|
|
76
|
+
throw error;
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -2,15 +2,11 @@ const assert = require('assert');
|
|
|
2
2
|
const { ocrSpace } = require('../index');
|
|
3
3
|
|
|
4
4
|
describe('Tests for OCR Space API Wrapper', () => {
|
|
5
|
-
it('should
|
|
6
|
-
|
|
7
|
-
assert.
|
|
8
|
-
|
|
9
|
-
assert.
|
|
10
|
-
const res3 = await ocrSpace(1);
|
|
11
|
-
assert.strictEqual(res3, undefined);
|
|
12
|
-
const res4 = await ocrSpace(true);
|
|
13
|
-
assert.strictEqual(res4, undefined);
|
|
5
|
+
it('should throw if input is wrong', async () => {
|
|
6
|
+
await assert.rejects(() => ocrSpace());
|
|
7
|
+
await assert.rejects(() => ocrSpace(''));
|
|
8
|
+
await assert.rejects(() => ocrSpace(1));
|
|
9
|
+
await assert.rejects(() => ocrSpace(true));
|
|
14
10
|
});
|
|
15
11
|
it('should return results with a URL input', async () => {
|
|
16
12
|
const res1 = await ocrSpace('http://dl.a9t9.com/ocrbenchmark/eng.png');
|
|
@@ -76,4 +72,11 @@ describe('Tests for OCR Space API Wrapper', () => {
|
|
|
76
72
|
assert.notStrictEqual(res1.SearchablePDFURL, 'Searchable PDF not generated as it was not requested.');
|
|
77
73
|
assert.match(res1.SearchablePDFURL, /https?:\/\/.*\.pdf/);
|
|
78
74
|
});
|
|
75
|
+
it('should throw if the request is aborted', async () => {
|
|
76
|
+
const controller = new AbortController();
|
|
77
|
+
const { signal } = controller;
|
|
78
|
+
const promise = ocrSpace('./test/eng.png', { signal });
|
|
79
|
+
controller.abort();
|
|
80
|
+
await assert.rejects(promise);
|
|
81
|
+
});
|
|
79
82
|
});
|