ocr-space-api-wrapper 2.3.1 → 2.4.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.
@@ -0,0 +1 @@
1
+ npm run lint
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # OCR.Space Node.js API wrapper
2
- [![](https://github.com/davideviolante/ocr-space-api-wrapper/workflows/Node.js%20CI/badge.svg)](https://github.com/DavideViolante/ocr-space-api-wrapper/actions?query=workflow%3A"Node.js+CI") [![Coverage Status](https://coveralls.io/repos/github/DavideViolante/ocr-space-api-wrapper/badge.svg?branch=master)](https://coveralls.io/github/DavideViolante/ocr-space-api-wrapper?branch=master) ![npm](https://img.shields.io/npm/dm/ocr-space-api-wrapper) [![Donate](https://img.shields.io/badge/paypal-donate-179BD7.svg)](https://www.paypal.me/dviolante)
2
+ [![](https://github.com/davideviolante/ocr-space-api-wrapper/workflows/Node.js%20CI/badge.svg)](https://github.com/DavideViolante/ocr-space-api-wrapper/actions?query=workflow%3A"Node.js+CI") [![Coverage Status](https://coveralls.io/repos/github/DavideViolante/ocr-space-api-wrapper/badge.svg?branch=master)](https://coveralls.io/github/DavideViolante/ocr-space-api-wrapper?branch=master) [![npm](https://img.shields.io/npm/dm/ocr-space-api-wrapper)](https://www.npmjs.com/package/ocr-space-api-wrapper) [![Donate](https://img.shields.io/badge/paypal-donate-179BD7.svg)](https://www.paypal.me/dviolante)
3
3
 
4
- [![NPM](https://nodei.co/npm/ocr-space-api-wrapper.png)](https://nodei.co/npm/ocr-space-api-wrapper/)
4
+ [![NPM](https://nodei.co/npm/ocr-space-api-wrapper.png)](https://www.npmjs.com/package/ocr-space-api-wrapper)
5
5
 
6
6
  Node.js wrapper for [ocr.space APIs](https://ocr.space/ocrapi), a service for executing OCR (Optical Character Recognition) to images and PDFs.
7
7
 
package/index.d.ts CHANGED
@@ -20,20 +20,26 @@ declare module "ocr-space-api-wrapper" {
20
20
  OCREngine?: '1' | '2' | '3';
21
21
  };
22
22
 
23
- type OcrSpaceResponse = {
23
+ export type OcrSpaceParsedResult = {
24
+ ErrorMessage: string;
25
+ ErrorDetails: string;
26
+ FileParseExitCode: 0 | 1 | -10 | -20 | -30 | -99;
27
+ HasOverlay: boolean;
28
+ Message: string;
29
+ ParsedText: string;
30
+ TextOverlay: {
31
+ Lines: any[];
32
+ HasOverlay: boolean;
33
+ Message: string;
34
+ };
35
+ }
36
+
37
+ export type OcrSpaceResponse = {
24
38
  ErrorMessage: string;
25
39
  ErrorDetails: string;
26
40
  IsErroredOnProcessing: boolean;
27
41
  OCRExitCode: number;
28
- ParsedResults: {
29
- ErrorMessage: string;
30
- ErrorDetails: string;
31
- FileParseExitCode: 0 | 1 | -10 | -20 | -30 | -99;
32
- HasOverlay: boolean,
33
- Message: string;
34
- ParsedText: string;
35
- TextOverlay: any;
36
- }[];
42
+ ParsedResults: OcrSpaceParsedResult[];
37
43
  ProcessingTimeInMilliseconds: number
38
44
  SearchablePDFURL: string;
39
45
  };
package/index.js CHANGED
@@ -40,7 +40,12 @@ async function ocrSpace(input, options = {}) {
40
40
  formData.append(detectedInput, input);
41
41
  break;
42
42
  }
43
- formData.append('language', String(language || 'eng'));
43
+ let defaultLanguage = language;
44
+ if (!defaultLanguage) {
45
+ // Only OCREngine 2 supports auto as language
46
+ defaultLanguage = String(OCREngine) === '2' ? 'auto' : 'eng';
47
+ }
48
+ formData.append('language', String(defaultLanguage));
44
49
  formData.append('isOverlayRequired', String(isOverlayRequired || 'false'));
45
50
  if (filetype) {
46
51
  formData.append('filetype', String(filetype));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ocr-space-api-wrapper",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "Node.js wrapper for ocr.space APIs.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,12 +32,13 @@
32
32
  "homepage": "https://github.com/DavideViolante/ocr-space-api-wrapper#readme",
33
33
  "dependencies": {
34
34
  "axios": "0.27.2",
35
- "form-data": "^4.0.0"
35
+ "form-data": "^4.0.1"
36
36
  },
37
37
  "devDependencies": {
38
- "eslint": "^8.57.0",
38
+ "eslint": "^8.57.1",
39
39
  "eslint-config-google": "^0.14.0",
40
- "mocha": "^10.2.0",
41
- "nyc": "^15.1.0"
40
+ "husky": "^9.1.7",
41
+ "mocha": "^11.0.1",
42
+ "nyc": "^17.1.0"
42
43
  }
43
44
  }
package/test/test.js CHANGED
@@ -61,4 +61,19 @@ describe('Tests for OCR Space API Wrapper', () => {
61
61
  assert.notStrictEqual(res1.SearchablePDFURL, 'Searchable PDF not generated as it was not requested.');
62
62
  assert.match(res1.SearchablePDFURL, /https?:\/\/.*\.pdf/);
63
63
  });
64
+ it('should return results with a local file input and options with OCREngine 2', async () => {
65
+ const res1 = await ocrSpace('./test/eng.png', {
66
+ isCreateSearchablePdf: true,
67
+ isSearchablePdfHideTextLayer: true,
68
+ scale: true,
69
+ OCREngine: 2,
70
+ filetype: 'application/pdf',
71
+ });
72
+ assert.ok(res1.ParsedResults);
73
+ assert.ok(res1.ParsedResults.length);
74
+ assert.strictEqual(res1.OCRExitCode, 1);
75
+ assert.strictEqual(res1.IsErroredOnProcessing, false);
76
+ assert.notStrictEqual(res1.SearchablePDFURL, 'Searchable PDF not generated as it was not requested.');
77
+ assert.match(res1.SearchablePDFURL, /https?:\/\/.*\.pdf/);
78
+ });
64
79
  });