@luii/node-tesseract-ocr 1.0.17 → 1.0.18

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,351 @@
1
+ /*
2
+ * node-tesseract-ocr
3
+ * Copyright (C) 2025 Philipp Czarnetzki
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ declare module 'node-tesseract-ocr' {
20
+
21
+ /**
22
+ * All available languages for tesseract
23
+ * @readonly
24
+ * @enum {string}
25
+ */
26
+ export enum AvailableLanguages {
27
+ afr = 'afr',
28
+ amh = 'amh',
29
+ ara = 'ara',
30
+ asm = 'asm',
31
+ aze = 'aze',
32
+ aze_cyrl = 'aze_cyrl',
33
+ bel = 'bel',
34
+ ben = 'ben',
35
+ bod = 'bod',
36
+ bos = 'bos',
37
+ bre = 'bre',
38
+ bul = 'bul',
39
+ cat = 'cat',
40
+ ceb = 'ceb',
41
+ ces = 'ces',
42
+ chi_sim = 'chi_sim',
43
+ chi_tra = 'chi_tra',
44
+ chr = 'chr',
45
+ cos = 'cos',
46
+ cym = 'cym',
47
+ dan = 'dan',
48
+ deu = 'deu',
49
+ deu_latf = 'deu_latf',
50
+ div = 'div',
51
+ dzo = 'dzo',
52
+ ell = 'ell',
53
+ eng = 'eng',
54
+ enm = 'enm',
55
+ epo = 'epo',
56
+ equ = 'equ',
57
+ est = 'est',
58
+ eus = 'eus',
59
+ fao = 'fao',
60
+ fas = 'fas',
61
+ fil = 'fil',
62
+ fin = 'fin',
63
+ fra = 'fra',
64
+ frm = 'frm',
65
+ fry = 'fry',
66
+ gla = 'gla',
67
+ gle = 'gle',
68
+ glg = 'glg',
69
+ grc = 'grc',
70
+ guj = 'guj',
71
+ hat = 'hat',
72
+ heb = 'heb',
73
+ hin = 'hin',
74
+ hrv = 'hrv',
75
+ hun = 'hun',
76
+ hye = 'hye',
77
+ iku = 'iku',
78
+ ind = 'ind',
79
+ isl = 'isl',
80
+ ita = 'ita',
81
+ ita_old = 'ita_old',
82
+ jav = 'jav',
83
+ jpn = 'jpn',
84
+ kan = 'kan',
85
+ kat = 'kat',
86
+ kat_old = 'kat_old',
87
+ kaz = 'kaz',
88
+ khm = 'khm',
89
+ kir = 'kir',
90
+ kmr = 'kmr',
91
+ kor = 'kor',
92
+ kor_vert = 'kor_vert',
93
+ kur = 'kur',
94
+ lao = 'lao',
95
+ lat = 'lat',
96
+ lav = 'lav',
97
+ lit = 'lit',
98
+ ltz = 'ltz',
99
+ mal = 'mal',
100
+ mar = 'mar',
101
+ mkd = 'mkd',
102
+ mlt = 'mlt',
103
+ mon = 'mon',
104
+ mri = 'mri',
105
+ msa = 'msa',
106
+ mya = 'mya',
107
+ nep = 'nep',
108
+ nld = 'nld',
109
+ nor = 'nor',
110
+ oci = 'oci',
111
+ ori = 'ori',
112
+ osd = 'osd',
113
+ pan = 'pan',
114
+ pol = 'pol',
115
+ por = 'por',
116
+ pus = 'pus',
117
+ que = 'que',
118
+ ron = 'ron',
119
+ rus = 'rus',
120
+ san = 'san',
121
+ sin = 'sin',
122
+ slk = 'slk',
123
+ slv = 'slv',
124
+ snd = 'snd',
125
+ spa = 'spa',
126
+ spa_old = 'spa_old',
127
+ sqi = 'sqi',
128
+ srp = 'srp',
129
+ srp_latn = 'srp_latn',
130
+ sun = 'sun',
131
+ swa = 'swa',
132
+ swe = 'swe',
133
+ syr = 'syr',
134
+ tam = 'tam',
135
+ tat = 'tat',
136
+ tel = 'tel',
137
+ tgk = 'tgk',
138
+ tha = 'tha',
139
+ tir = 'tir',
140
+ ton = 'ton',
141
+ tur = 'tur',
142
+ uig = 'uig',
143
+ ukr = 'ukr',
144
+ urd = 'urd',
145
+ uzb = 'uzb',
146
+ uzb_cyrl = 'uzb_cyrl',
147
+ vie = 'vie',
148
+ yid = 'yid',
149
+ yor = 'yor'
150
+ }
151
+
152
+ /**
153
+ * When Tesseract/Cube is initialized we can choose to instantiate/load/run
154
+ * only the Tesseract part, only the Cube part or both along with the combiner.
155
+ * The preference of which engine to use is stored in tessedit_ocr_engine_mode.
156
+ * @readonly
157
+ * @enum {number}
158
+ */
159
+ export enum OcrEngineMode {
160
+ // Run Tesseract only - fastest; deprecated
161
+ OEM_TESSERACT_ONLY = 0,
162
+ // Run just the LSTM line recognizer.
163
+ OEM_LSTM_ONLY = 1,
164
+ // Run the LSTM recognizer, but allow fallback
165
+ // to Tesseract when things get difficult.
166
+ // deprecated
167
+ OEM_TESSERACT_LSTM_COMBINED = 2,
168
+ // Specify this mode when calling init_*(),
169
+ // to indicate that any of the above modes
170
+ // should be automatically inferred from the
171
+ // variables in the language-specific config,
172
+ // command-line configs, or if not specified
173
+ // in any of the above should be set to the
174
+ // default OEM_TESSERACT_ONLY.
175
+ OEM_DEFAULT = 3,
176
+ }
177
+
178
+
179
+ /**
180
+ * Possible modes for page layout analysis.
181
+ * @readonly
182
+ * @enum {number}
183
+ */
184
+ export enum PageSegmentationMode {
185
+ // Orientation and script detection only.
186
+ PSM_OSD_ONLY = 0,
187
+ // Automatic page segmentation with orientation and script detection. (OSD)
188
+ PSM_AUTO_OSD = 1,
189
+ // Automatic page segmentation, but no OSD, or OCR.
190
+ PSM_AUTO_ONLY = 2,
191
+ // Fully automatic page segmentation, but no OSD.
192
+ PSM_AUTO = 3,
193
+ // Assume a single column of text of variable sizes.
194
+ PSM_SINGLE_COLUMN = 4,
195
+ // Assume a single uniform block of vertically aligned text.
196
+ PSM_SINGLE_BLOCK_VERT_TEXT = 5,
197
+ // Assume a single uniform block of text. (Default.)
198
+ PSM_SINGLE_BLOCK = 6,
199
+ // Treat the image as a single text line.
200
+ PSM_SINGLE_LINE = 7,
201
+ // Treat the image as a single word.
202
+ PSM_SINGLE_WORD = 8,
203
+ // Treat the image as a single word in a circle.
204
+ PSM_CIRCLE_WORD = 9,
205
+ // Treat the image as a single character.
206
+ PSM_SINGLE_CHAR = 10,
207
+ // Find as much text as possible in no particular order.
208
+ PSM_SPARSE_TEXT = 11,
209
+ // Sparse text with orientation and script det.
210
+ PSM_SPARSE_TEXT_OSD = 12,
211
+ // Treat the image as a single text line, bypassing hacks that are Tesseract-specific.
212
+ PSM_RAW_LINE = 13,
213
+ }
214
+
215
+ /**
216
+ * Tesseract constructor options
217
+ */
218
+ export interface TesseractOptions {
219
+ /**
220
+ * Its generally safer to use as few languages as possible.
221
+ * The more languages Tesseract needs to load the longer it takes to recognize a image.
222
+ * @public
223
+ */
224
+ lang: Array<keyof typeof AvailableLanguages>;
225
+
226
+ /**
227
+ * Skip Ocr for when you only want to (for example) analyze the layout
228
+ * @property {boolean} [skipOcr]
229
+ */
230
+ skipOcr?: boolean;
231
+
232
+ /**
233
+ * OCR Engine Modes
234
+ * The engine mode cannot be changed after creating the instance
235
+ * If another mode is needed, its advised to create a new instance.
236
+ * @throws {Error} Will throw an error when oem mode is below 0 or over 3
237
+ */
238
+ oemMode?: OcrEngineMode;
239
+
240
+ /**
241
+ * Page Segmentation Modes
242
+ * The page segmentation mode cannot be changed after creating the instance
243
+ * If another mode is needed, its advised to create a new instance.
244
+ * @throws {Error} Will throw a error when psm mode is below 0 or over 13
245
+ */
246
+ psm?: PageSegmentationMode;
247
+ }
248
+
249
+ export interface ProgressChangedInfo {
250
+
251
+ /**
252
+ * Chars in this buffer
253
+ */
254
+ progress: number;
255
+
256
+ /**
257
+ * Percent complete increasing (0-100)
258
+ */
259
+ percent: number;
260
+
261
+ /**
262
+ * States if the worker is still alive
263
+ */
264
+ ocrAlive: number;
265
+
266
+ /**
267
+ * top coordinate of the bbox of the current element that tesseract is processing
268
+ */
269
+ top: number;
270
+
271
+ /**
272
+ * right coordinate of the bbox of the current element that tesseract is processing
273
+ */
274
+ right: number;
275
+
276
+ /**
277
+ * bottom coordinate of the bbox of the current element that tesseract is processing
278
+ */
279
+ bottom: number;
280
+
281
+ /**
282
+ * left coordinate of the bbox of the current element that tesseract is processing
283
+ */
284
+ left: number;
285
+ }
286
+
287
+ /**
288
+ * Progress callback thats called during `recognize`
289
+ */
290
+ export type RecognizeProgressChangedCallback = (info: ProgressChangedInfo) => void;
291
+
292
+ export interface RecognizeOptions {
293
+
294
+ /**
295
+ * @property {RecognizeProgressChangedCallback} [progressChanged]
296
+ */
297
+ progressChanged?: RecognizeProgressChangedCallback;
298
+ }
299
+
300
+ export interface RecognizeResult {
301
+
302
+ /**
303
+ * Returns the recognized text as utf8
304
+ * @returns {string}
305
+ */
306
+ getText: () => string;
307
+
308
+ /**
309
+ * Returns the recognized text as tsv format (Tab seperated values)
310
+ * @returns {string}
311
+ */
312
+ getTSV: () => string;
313
+
314
+ /**
315
+ * Returns the recognized results in an hOCR format.
316
+ * hOCR is a derivative of the XML format and can be parsed as such.
317
+ * The hOCR format contains layout information, so that
318
+ * it could be overlayed over the source material for example.
319
+ * @see https://en.wikipedia.org/wiki/HOCR
320
+ * @returns {string}
321
+ */
322
+ getHOCR: () => string;
323
+
324
+ /**
325
+ * Returns the recognized results in an ALTO format.
326
+ * ALTO is a derivative of the XML format and can be parsed as such.
327
+ * The ALTO format contains layout information, so that
328
+ * it could be overlayed over the source material for example.
329
+ * @see https://en.wikipedia.org/wiki/Analyzed_Layout_and_Text_Object
330
+ * @returns {string}
331
+ */
332
+ getALTO: () => string;
333
+ }
334
+
335
+ export class Tesseract {
336
+ constructor(options: TesseractOptions);
337
+
338
+ /**
339
+ * @throws {Error} Will throw an error if no available underlying api is available
340
+ * @throws {Error} Will throw an error if skipOcr is on and this function is called
341
+ * @throws {Error} Will throw an error if the parameter at index 0 is not a buffer
342
+ * @param {Buffer<ArrayBuffer>} imageBuffer The image that should be recognized
343
+ * @param {RecognizeOptions} [options] Optional options,
344
+ * @returns {Promise<RecognizeResult>} Returns a result object containing
345
+ * various functions to retrieve the results
346
+ */
347
+ recognize: (imageBuffer: Buffer<ArrayBuffer>, options?: RecognizeOptions) => Promise<RecognizeResult>;
348
+ }
349
+
350
+ export default Tesseract;
351
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luii/node-tesseract-ocr",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "private": false,
5
5
  "gypfile": true,
6
6
  "main": "dist/cjs/index.cjs",
@@ -41,7 +41,8 @@
41
41
  "build": "npm run build:release",
42
42
  "build:addon:debug": "node-gyp rebuild --debug",
43
43
  "build:addon:release": "node-gyp rebuild --release",
44
- "build:ts": "npm run build:cjs && npm run build:esm",
44
+ "build:types": "mkdir -p dist && cp lib/index.d.ts dist/index.d.ts",
45
+ "build:ts": "npm run build:cjs && npm run build:esm && npm run build:types",
45
46
  "build:cjs": "tsc -p tsconfig.cjs.json && mv dist/cjs/index.js dist/cjs/index.cjs",
46
47
  "build:esm": "tsc -p tsconfig.esm.json && mv dist/esm/index.js dist/esm/index.mjs",
47
48
  "build:debug": "rm -rf dist && mkdir dist && npm run build:addon:debug && npm run build:cjs && npm run build:esm",
@@ -55,8 +56,9 @@
55
56
  "src/**",
56
57
  "build/Release/*.node",
57
58
  "package.json",
59
+ "binding.gyp",
58
60
  "README.md",
59
- "binding.gyp"
61
+ "LICENSE.md"
60
62
  ],
61
63
  "devDependencies": {
62
64
  "@types/node": "^22.0.0",