Skip to content

Commit e6a9b76

Browse files
Add TypeScript typings (#67)
* Add typings to options param * Add response typings * Add types directly in the options type * Export types too * Rename types * Put everything together * Export also options type * Update version
1 parent 8fa34f3 commit e6a9b76

File tree

3 files changed

+67
-28
lines changed

3 files changed

+67
-28
lines changed

index.d.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
11
declare module "ocr-space-api-wrapper" {
2-
export function ocrSpace(input: string, options?: any): any;
2+
type OcrSpaceLanguages = 'ara' | 'bul' | 'chs' | 'cht' | 'hrv' | 'cze' | 'dan' | 'dut' |
3+
'eng' | 'fin' | 'fre' | 'ger' | 'gre' | 'hun' | 'kor' | 'ita' | 'jpn' | 'pol' |
4+
'por' | 'rus' | 'slv' | 'spa' | 'swe' | 'tur' |
5+
// The following are only supported by OCREngine = '3'
6+
'hin' | 'kan' | 'per' | 'tel' | 'tam' | 'tai' | 'vie';
7+
type OcrSpaceFileTypes = string | 'PDF' | 'GIF' | 'PNG' | 'JPG' | 'TIF' | 'BMP';
8+
9+
export type OcrSpaceOptions = {
10+
apiKey?: string;
11+
ocrUrl?: string;
12+
language?: OcrSpaceLanguages;
13+
isOverlayRequired?: boolean;
14+
filetype?: OcrSpaceFileTypes;
15+
detectOrientation?: boolean;
16+
isCreateSearchablePdf?: boolean;
17+
isSearchablePdfHideTextLayer?: boolean;
18+
scale?: boolean;
19+
isTable?: boolean;
20+
OCREngine?: '1' | '2' | '3';
21+
};
22+
23+
type OcrSpaceResponse = {
24+
ErrorMessage: string;
25+
ErrorDetails: string;
26+
IsErroredOnProcessing: boolean;
27+
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+
}[];
37+
ProcessingTimeInMilliseconds: number
38+
SearchablePDFURL: string;
39+
};
40+
41+
export function ocrSpace(input: string, options?: OcrSpaceOptions): OcrSpaceResponse;
342
}

package-lock.json

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ocr-space-api-wrapper",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Node.js wrapper for ocr.space APIs.",
55
"main": "index.js",
66
"scripts": {
@@ -35,7 +35,7 @@
3535
"form-data": "^4.0.0"
3636
},
3737
"devDependencies": {
38-
"eslint": "^8.33.0",
38+
"eslint": "^8.42.0",
3939
"eslint-config-google": "^0.14.0",
4040
"mocha": "^10.2.0",
4141
"nyc": "^15.1.0"

0 commit comments

Comments
 (0)