@d0paminedriven/jpegdown-ocr 0.0.0-stage → 0.2.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.
- package/index.d.ts +591 -0
- package/index.js +4 -0
- package/jpegdown_ocr.napi.js +797 -0
- package/omp.js +9 -0
- package/package.json +44 -4
- package/README.md +0 -3
package/index.d.ts
ADDED
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
/* auto-generated by @d0paminedriven/jpegdown-ocr */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Which binding artifact the generated loader actually loaded: `'native'` for
|
|
6
|
+
* a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
|
|
7
|
+
* flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
|
|
8
|
+
* can point the loader at a WASI artifact this package does not build itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A JPEG file. Its header is read once, in the constructor or in `openAsync`; its picture is
|
|
14
|
+
* decoded when it is asked for.
|
|
15
|
+
*/
|
|
16
|
+
export declare class JpegDown {
|
|
17
|
+
/**
|
|
18
|
+
* The page as it was read: its words where they lie on the page, and the lines they make.
|
|
19
|
+
* This reads the page on the JavaScript thread; `layoutAsync` does not hold that thread.
|
|
20
|
+
* Throws as `png` does when the picture cannot be decoded.
|
|
21
|
+
*/
|
|
22
|
+
layout(ocr?: OcrOptions | undefined | null): JpegPageLayout
|
|
23
|
+
/** `layout` on a worker thread. */
|
|
24
|
+
layoutAsync(ocr?: OcrOptions | undefined | null): Promise<JpegPageLayout>
|
|
25
|
+
/** The page's text: its lines from the top down. */
|
|
26
|
+
text(ocr?: OcrOptions | undefined | null): string
|
|
27
|
+
/** `text` on a worker thread. */
|
|
28
|
+
textAsync(ocr?: OcrOptions | undefined | null): Promise<string>
|
|
29
|
+
/**
|
|
30
|
+
* Invoice fields read from the recognized page. What the page warns of comes first among
|
|
31
|
+
* its warnings.
|
|
32
|
+
*/
|
|
33
|
+
invoice(opts?: InvoiceOptions | undefined | null, ocr?: OcrOptions | undefined | null): InvoiceResult
|
|
34
|
+
/** `invoice` on a worker thread. */
|
|
35
|
+
invoiceAsync(opts?: InvoiceOptions | undefined | null, ocr?: OcrOptions | undefined | null): Promise<InvoiceResult>
|
|
36
|
+
/**
|
|
37
|
+
* Everything read from the file, from one reading of its page: what the file says of the
|
|
38
|
+
* page, the layout, the text, and the invoice. Calling `layout`, `text`, and `invoice`
|
|
39
|
+
* apart reads the page three times; this reads it once.
|
|
40
|
+
*/
|
|
41
|
+
documentOcr(ocr?: OcrOptions | undefined | null, invoice?: InvoiceOptions | undefined | null): JpegDocumentOcr
|
|
42
|
+
/** `documentOcr` on a worker thread. */
|
|
43
|
+
documentOcrAsync(ocr?: OcrOptions | undefined | null, invoice?: InvoiceOptions | undefined | null): Promise<JpegDocumentOcr>
|
|
44
|
+
/**
|
|
45
|
+
* Read a file's header from its bytes, which are copied. Throws `unsupported format: …`
|
|
46
|
+
* for bytes that are not a JPEG and `malformed file: …` for a header that is damaged.
|
|
47
|
+
*/
|
|
48
|
+
constructor(buffer: Buffer)
|
|
49
|
+
/**
|
|
50
|
+
* Read a file's header off the JavaScript thread; resolves to a `JpegDown`, or rejects with
|
|
51
|
+
* the errors the constructor throws.
|
|
52
|
+
*/
|
|
53
|
+
static openAsync(buffer: Buffer): Promise<JpegDown>
|
|
54
|
+
/** What the file says of its page. */
|
|
55
|
+
page(): JpegPage
|
|
56
|
+
/**
|
|
57
|
+
* The picture as a PNG, as it is to be looked at: turned the way its orientation says.
|
|
58
|
+
* Throws as `jpegPng` does.
|
|
59
|
+
*/
|
|
60
|
+
png(): Buffer
|
|
61
|
+
/** `png` on a worker thread. */
|
|
62
|
+
pngAsync(): Promise<Buffer>
|
|
63
|
+
/** What is known of the file, in one object: its page and its size in bytes. */
|
|
64
|
+
document(): JpegDocument
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** `value` is `lines` joined with `
|
|
68
|
+
`. */
|
|
69
|
+
export interface AddressField {
|
|
70
|
+
value: string
|
|
71
|
+
text: string
|
|
72
|
+
confidence: number
|
|
73
|
+
span?: FieldSpan
|
|
74
|
+
lines: Array<string>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* An aircraft or engine the invoice relates to. Maintenance, parts and
|
|
79
|
+
* program invoices identify the asset by airframe (model, manufacturer serial
|
|
80
|
+
* number, registration) and/or by engine (model, engine serial number); one
|
|
81
|
+
* invoice can cover several assets, so `InvoiceFields.aircraft` is a list.
|
|
82
|
+
*/
|
|
83
|
+
export interface AircraftReference {
|
|
84
|
+
/** Airframe model, e.g. "Challenger 350", "Global 6000", "Phenom 300". */
|
|
85
|
+
model?: StringField
|
|
86
|
+
/** Manufacturer serial number (MSN). */
|
|
87
|
+
serialNumber?: StringField
|
|
88
|
+
/** Registration / tail number, e.g. "N123AB", "C-GXYZ". */
|
|
89
|
+
registration?: StringField
|
|
90
|
+
/** Engine model, e.g. "BR710", "AE 3007", "PW308C". */
|
|
91
|
+
engineModel?: StringField
|
|
92
|
+
/** Engine serial number (ESN). */
|
|
93
|
+
engineSerialNumber?: StringField
|
|
94
|
+
span?: FieldSpan
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Which tier named the currency: evidence on the page (an ISO code or an unambiguous glyph),
|
|
99
|
+
* content priors such as the vendor's country, the caller's option, or nothing.
|
|
100
|
+
*/
|
|
101
|
+
export type CurrencySource = 'Page' | 'Content' | 'Option' | 'Unknown'
|
|
102
|
+
|
|
103
|
+
/** `value` is an ISO 8601 calendar date, `YYYY-MM-DD`. */
|
|
104
|
+
export interface DateField {
|
|
105
|
+
value: string
|
|
106
|
+
text: string
|
|
107
|
+
confidence: number
|
|
108
|
+
span?: FieldSpan
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type DateOrder = 'Auto' | 'MDY' | 'DMY' | 'YMD'
|
|
112
|
+
|
|
113
|
+
export type EInvoiceStandard = 'FacturX' | 'ZUGFeRD' | 'XRechnung' | 'UBL' | 'Unknown'
|
|
114
|
+
|
|
115
|
+
export interface EmbeddedInvoiceXml {
|
|
116
|
+
filename: string
|
|
117
|
+
standard: EInvoiceStandard
|
|
118
|
+
/**
|
|
119
|
+
* The guideline / customization identifier, e.g.
|
|
120
|
+
* `urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic`.
|
|
121
|
+
*/
|
|
122
|
+
profile?: string
|
|
123
|
+
xml: string
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Where a field was read from, in PDF user space on a 1-based page. */
|
|
127
|
+
export interface FieldSpan {
|
|
128
|
+
page: number
|
|
129
|
+
x0: number
|
|
130
|
+
y0: number
|
|
131
|
+
x1: number
|
|
132
|
+
y1: number
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type InvoiceDocumentType = 'Invoice' | 'CreditNote' | 'Unknown'
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Field names mirror the de-facto vocabulary of common invoice extractors so
|
|
139
|
+
* consumers can swap sources with a thin mapper. Naming only: nothing here
|
|
140
|
+
* talks to any service.
|
|
141
|
+
*/
|
|
142
|
+
export interface InvoiceFields {
|
|
143
|
+
vendorName?: StringField
|
|
144
|
+
vendorAddress?: AddressField
|
|
145
|
+
vendorTaxId?: StringField
|
|
146
|
+
vendorEmail?: StringField
|
|
147
|
+
vendorPhone?: StringField
|
|
148
|
+
vendorWebsite?: StringField
|
|
149
|
+
customerName?: StringField
|
|
150
|
+
customerId?: StringField
|
|
151
|
+
customerAddress?: AddressField
|
|
152
|
+
customerTaxId?: StringField
|
|
153
|
+
billingAddress?: AddressField
|
|
154
|
+
shippingAddress?: AddressField
|
|
155
|
+
remittanceAddress?: AddressField
|
|
156
|
+
invoiceId?: StringField
|
|
157
|
+
invoiceDate?: DateField
|
|
158
|
+
dueDate?: DateField
|
|
159
|
+
purchaseOrder?: StringField
|
|
160
|
+
paymentTerm?: StringField
|
|
161
|
+
serviceStartDate?: DateField
|
|
162
|
+
serviceEndDate?: DateField
|
|
163
|
+
currencyCode?: string
|
|
164
|
+
subTotal?: MoneyField
|
|
165
|
+
totalDiscount?: MoneyField
|
|
166
|
+
totalTax?: MoneyField
|
|
167
|
+
shippingCost?: MoneyField
|
|
168
|
+
invoiceTotal?: MoneyField
|
|
169
|
+
amountDue?: MoneyField
|
|
170
|
+
previousUnpaidBalance?: MoneyField
|
|
171
|
+
/** MRO work order / shop order the invoice bills against. */
|
|
172
|
+
workOrder?: StringField
|
|
173
|
+
/** Aircraft and engines the invoice relates to; empty when none is identified. */
|
|
174
|
+
aircraft: Array<AircraftReference>
|
|
175
|
+
taxDetails: Array<TaxDetail>
|
|
176
|
+
paymentDetails: Array<PaymentDetail>
|
|
177
|
+
items: Array<InvoiceItem>
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface InvoiceItem {
|
|
181
|
+
description?: StringField
|
|
182
|
+
productCode?: StringField
|
|
183
|
+
quantity?: NumberField
|
|
184
|
+
unit?: StringField
|
|
185
|
+
unitPrice?: MoneyField
|
|
186
|
+
taxRate?: NumberField
|
|
187
|
+
tax?: MoneyField
|
|
188
|
+
discount?: MoneyField
|
|
189
|
+
date?: DateField
|
|
190
|
+
amount?: MoneyField
|
|
191
|
+
/** Absent when the item came from embedded XML (no page geometry). */
|
|
192
|
+
span?: FieldSpan
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Options accepted by every invoice entry point. `preferEmbeddedXml` picks the embedded
|
|
197
|
+
* XML over the pages when both exist; `languages`, `currency`, `dateOrder` and
|
|
198
|
+
* `decimalSeparator` steer the page reader where the page leaves a choice;
|
|
199
|
+
* `includeCandidates` lists, in `warnings`, the candidates each field was chosen from;
|
|
200
|
+
* `includeLayout` is reserved.
|
|
201
|
+
*/
|
|
202
|
+
export interface InvoiceOptions {
|
|
203
|
+
/** Label lexicons to enable; default `["en"]`. */
|
|
204
|
+
languages?: Array<string>
|
|
205
|
+
/** ISO 4217 hint when the page shows only symbols. */
|
|
206
|
+
currency?: string
|
|
207
|
+
dateOrder?: DateOrder
|
|
208
|
+
decimalSeparator?: "Auto" | "." | ","
|
|
209
|
+
/** Default `true`. Embedded Factur-X / ZUGFeRD / XRechnung / UBL XML is used when present. */
|
|
210
|
+
preferEmbeddedXml?: boolean
|
|
211
|
+
/** Reserved; accepted and ignored. */
|
|
212
|
+
includeLayout?: boolean
|
|
213
|
+
/**
|
|
214
|
+
* Default `false`. Lists, in `warnings`, the candidates each field was chosen from, with
|
|
215
|
+
* their scores.
|
|
216
|
+
*/
|
|
217
|
+
includeCandidates?: boolean
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface InvoiceResult {
|
|
221
|
+
source: InvoiceSource
|
|
222
|
+
documentType: InvoiceDocumentType
|
|
223
|
+
/** Document-level confidence, 0..1. */
|
|
224
|
+
confidence: number
|
|
225
|
+
fields: InvoiceFields
|
|
226
|
+
warnings: Array<string>
|
|
227
|
+
embeddedXml?: EmbeddedInvoiceXml
|
|
228
|
+
/** Which tier named `fields.currencyCode`; absent when no layout pass ran. */
|
|
229
|
+
currencySource?: CurrencySource
|
|
230
|
+
/** The evidence behind `documentType: CreditNote`; empty otherwise. */
|
|
231
|
+
creditSignals: Array<string>
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Which extraction path produced the result: embedded XML, the page text (native, OCR,
|
|
236
|
+
* rendered or mixed), or `None` when the document had no readable
|
|
237
|
+
* pages and no embedded XML.
|
|
238
|
+
*/
|
|
239
|
+
export type InvoiceSource = 'EmbeddedXml' | 'Native' | 'Ocr' | 'Rendered' | 'Mixed' | 'None'
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* How the picture's data is coded, as a union keyed on `type`. `other` carries the marker of
|
|
243
|
+
* the frame for a coding this package has no name for.
|
|
244
|
+
*/
|
|
245
|
+
export type JpegCoding =
|
|
246
|
+
| { type: 'baseline' }
|
|
247
|
+
| { type: 'extended' }
|
|
248
|
+
| { type: 'progressive' }
|
|
249
|
+
| { type: 'lossless' }
|
|
250
|
+
| { type: 'other'; marker: number }
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* What a pixel's components are, as a union keyed on `type`. `other` carries how many there
|
|
254
|
+
* are.
|
|
255
|
+
*/
|
|
256
|
+
export type JpegColor =
|
|
257
|
+
| { type: 'gray' }
|
|
258
|
+
| { type: 'yCbCr' }
|
|
259
|
+
| { type: 'rgb' }
|
|
260
|
+
| { type: 'cmyk' }
|
|
261
|
+
| { type: 'ycck' }
|
|
262
|
+
| { type: 'other'; components: number }
|
|
263
|
+
|
|
264
|
+
/** What is known of a JPEG buffer, in one object: its page and its size in bytes. */
|
|
265
|
+
export declare function jpegDocument(buffer: Buffer): JpegDocument
|
|
266
|
+
|
|
267
|
+
/** A file's page, with its size in bytes. */
|
|
268
|
+
export interface JpegDocument {
|
|
269
|
+
/** How many bytes the file has. */
|
|
270
|
+
byteSize: number
|
|
271
|
+
page: JpegPage
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** `jpegDocument` on a worker thread: the buffer is copied, then read there. */
|
|
275
|
+
export declare function jpegDocumentAsync(buffer: Buffer): Promise<JpegDocument>
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Everything read from a JPEG buffer, from one reading of its page: what the file says of
|
|
279
|
+
* the page, the layout, the text, and the invoice.
|
|
280
|
+
*/
|
|
281
|
+
export declare function jpegDocumentOcr(buffer: Buffer, ocr?: OcrOptions | undefined | null, invoice?: InvoiceOptions | undefined | null): JpegDocumentOcr
|
|
282
|
+
|
|
283
|
+
/** Everything read from a file, from one reading of its page. */
|
|
284
|
+
export interface JpegDocumentOcr {
|
|
285
|
+
/** How many bytes the file has. */
|
|
286
|
+
byteSize: number
|
|
287
|
+
/** What the file says of its page, as `page` gives it. */
|
|
288
|
+
page: JpegPage
|
|
289
|
+
layout: JpegPageLayout
|
|
290
|
+
/** The page's lines from the top down, a line of text to each. */
|
|
291
|
+
text: string
|
|
292
|
+
invoice: InvoiceResult
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** `jpegDocumentOcr` on a worker thread: the buffer is copied, then decoded and read there. */
|
|
296
|
+
export declare function jpegDocumentOcrAsync(buffer: Buffer, ocr?: OcrOptions | undefined | null, invoice?: InvoiceOptions | undefined | null): Promise<JpegDocumentOcr>
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Invoice fields read from the recognized page of a JPEG buffer. What the page warns of comes
|
|
300
|
+
* first among its warnings.
|
|
301
|
+
*/
|
|
302
|
+
export declare function jpegInvoice(buffer: Buffer, opts?: InvoiceOptions | undefined | null, ocr?: OcrOptions | undefined | null): InvoiceResult
|
|
303
|
+
|
|
304
|
+
/** `jpegInvoice` on a worker thread: the buffer is copied, then decoded and read there. */
|
|
305
|
+
export declare function jpegInvoiceAsync(buffer: Buffer, opts?: InvoiceOptions | undefined | null, ocr?: OcrOptions | undefined | null): Promise<InvoiceResult>
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The page of a JPEG buffer as it was read: its words where they lie on the page, and the
|
|
309
|
+
* lines they make. Throws as `jpegPng` does when the picture cannot be decoded.
|
|
310
|
+
*/
|
|
311
|
+
export declare function jpegLayout(buffer: Buffer, ocr?: OcrOptions | undefined | null): JpegPageLayout
|
|
312
|
+
|
|
313
|
+
/** `jpegLayout` on a worker thread: the buffer is copied, then decoded and read there. */
|
|
314
|
+
export declare function jpegLayoutAsync(buffer: Buffer, ocr?: OcrOptions | undefined | null): Promise<JpegPageLayout>
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Words sharing a baseline band, left to right. `firstWord` / `wordCount` address a contiguous
|
|
318
|
+
* slice of `JpegPageLayout.words`.
|
|
319
|
+
*/
|
|
320
|
+
export interface JpegLine {
|
|
321
|
+
text: string
|
|
322
|
+
x0: number
|
|
323
|
+
y0: number
|
|
324
|
+
x1: number
|
|
325
|
+
y1: number
|
|
326
|
+
firstWord: number
|
|
327
|
+
wordCount: number
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* What a JPEG buffer says of its page: its size, its resolution, how it is kept, the paper it
|
|
332
|
+
* is nearest to, and the size it is read at. Nothing of the picture is decoded. Throws
|
|
333
|
+
* `unsupported format: …` for bytes that are not a JPEG and `malformed file: …` for a header
|
|
334
|
+
* that is damaged.
|
|
335
|
+
*/
|
|
336
|
+
export declare function jpegPage(buffer: Buffer): JpegPage
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The file's page, and what the file says of it. Nothing of the picture is decoded to make
|
|
340
|
+
* this.
|
|
341
|
+
*/
|
|
342
|
+
export interface JpegPage {
|
|
343
|
+
/** The picture's size in pixels, as it lies in the file: before its orientation turns it. */
|
|
344
|
+
width: number
|
|
345
|
+
height: number
|
|
346
|
+
/**
|
|
347
|
+
* As the file states it. Absent when it states none, or states one in no unit. It is not
|
|
348
|
+
* always a measurement: software writes 72 or 96 when it has measured nothing.
|
|
349
|
+
*/
|
|
350
|
+
resolution?: JpegResolution
|
|
351
|
+
bitsPerSample: number
|
|
352
|
+
/** How many components a pixel has. */
|
|
353
|
+
components: number
|
|
354
|
+
color: JpegColor
|
|
355
|
+
coding: JpegCoding
|
|
356
|
+
/**
|
|
357
|
+
* How the picture is to be turned for display, numbered from 1 to 8 as Exif does: 1 is as
|
|
358
|
+
* it lies. `jpegPng` gives the picture already turned.
|
|
359
|
+
*/
|
|
360
|
+
orientation: number
|
|
361
|
+
/** The program that wrote the file, as it names itself. */
|
|
362
|
+
software?: string
|
|
363
|
+
/**
|
|
364
|
+
* When the file was written, as it records it: `2015-03-04T10:22:33`. The format has no
|
|
365
|
+
* place for a time zone, so there is none.
|
|
366
|
+
*/
|
|
367
|
+
dateTime?: string
|
|
368
|
+
/**
|
|
369
|
+
* The page's size in points as it lies in the file, by the resolution the file states.
|
|
370
|
+
* Absent for a file that states none.
|
|
371
|
+
*/
|
|
372
|
+
sizeInPoints?: JpegSize
|
|
373
|
+
/**
|
|
374
|
+
* The standard paper size nearest to `sizeInPoints`, in either orientation; its `type` is
|
|
375
|
+
* `UNKNOWN` when none is within 3% on both sides, or the file states no resolution.
|
|
376
|
+
*/
|
|
377
|
+
paperSize: PaperSize
|
|
378
|
+
/** The size the page is read at, which is the stated one when that can be believed. */
|
|
379
|
+
sizeAsRead: JpegPageSize
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** `jpegPage` on a worker thread: the buffer is copied, then read there. */
|
|
383
|
+
export declare function jpegPageAsync(buffer: Buffer): Promise<JpegPage>
|
|
384
|
+
|
|
385
|
+
/** The page as it was read: its words where they lie on it, and the lines they make. */
|
|
386
|
+
export interface JpegPageLayout {
|
|
387
|
+
/**
|
|
388
|
+
* The page's size in points as it was read: the page's `sizeAsRead`, turned again by
|
|
389
|
+
* `contentRotation` when its text lay another way up.
|
|
390
|
+
*/
|
|
391
|
+
width: number
|
|
392
|
+
height: number
|
|
393
|
+
/**
|
|
394
|
+
* Clockwise degrees (0, 90, 180, or 270) the page was turned, beyond what its orientation
|
|
395
|
+
* says, so that its text reads upright. Every word and line is in the turned frame.
|
|
396
|
+
*/
|
|
397
|
+
contentRotation: number
|
|
398
|
+
words: Array<JpegWord>
|
|
399
|
+
lines: Array<JpegLine>
|
|
400
|
+
/**
|
|
401
|
+
* What to know about the reading: a size that was assumed, a picture with few pixels to
|
|
402
|
+
* the inch that was enlarged before it was read, a turn that was made, a language
|
|
403
|
+
* Tesseract has no data for.
|
|
404
|
+
*/
|
|
405
|
+
warnings: Array<string>
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** The size the page is read at, as it is to be looked at. */
|
|
409
|
+
export interface JpegPageSize {
|
|
410
|
+
/** In points. */
|
|
411
|
+
width: number
|
|
412
|
+
height: number
|
|
413
|
+
/**
|
|
414
|
+
* Absent when the size is the one the file's resolution makes. Otherwise the file states
|
|
415
|
+
* no resolution that can be believed (none at all, or one that would make a sheet no
|
|
416
|
+
* sheet is), and the picture is taken to be a sheet of this paper, the one its shape is
|
|
417
|
+
* nearest to among letter, A4, and legal.
|
|
418
|
+
*/
|
|
419
|
+
assumed?: StandardPaperSize
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* The picture of a JPEG buffer as a PNG, as it is to be looked at: turned the way its
|
|
424
|
+
* orientation says. Throws `unsupported format: …` for a picture kept in a coding that is not
|
|
425
|
+
* read (without loss, or with samples of more than 8 bits), `limit exceeded: …` for one
|
|
426
|
+
* larger than any page, and `malformed file: …` for one that cannot be decoded.
|
|
427
|
+
*/
|
|
428
|
+
export declare function jpegPng(buffer: Buffer): Buffer
|
|
429
|
+
|
|
430
|
+
/** `jpegPng` on a worker thread: the buffer is copied, then decoded there. */
|
|
431
|
+
export declare function jpegPngAsync(buffer: Buffer): Promise<Buffer>
|
|
432
|
+
|
|
433
|
+
/** A resolution, in pixels to the inch. */
|
|
434
|
+
export interface JpegResolution {
|
|
435
|
+
x: number
|
|
436
|
+
y: number
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** A width and a height in points, of which there are 72 to the inch. */
|
|
440
|
+
export interface JpegSize {
|
|
441
|
+
width: number
|
|
442
|
+
height: number
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** The text of a JPEG buffer's page: its lines from the top down. */
|
|
446
|
+
export declare function jpegText(buffer: Buffer, ocr?: OcrOptions | undefined | null): string
|
|
447
|
+
|
|
448
|
+
/** `jpegText` on a worker thread: the buffer is copied, then decoded and read there. */
|
|
449
|
+
export declare function jpegTextAsync(buffer: Buffer, ocr?: OcrOptions | undefined | null): Promise<string>
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* One recognized word, with its box in the page frame: points, y up, the page's bottom-left
|
|
453
|
+
* corner at the origin.
|
|
454
|
+
*/
|
|
455
|
+
export interface JpegWord {
|
|
456
|
+
text: string
|
|
457
|
+
x0: number
|
|
458
|
+
y0: number
|
|
459
|
+
x1: number
|
|
460
|
+
y1: number
|
|
461
|
+
/** Index into `JpegPageLayout.lines`. */
|
|
462
|
+
line: number
|
|
463
|
+
/** How sure Tesseract is of the word, from 0 to 1. */
|
|
464
|
+
confidence: number
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Money as a JS number plus the exact printed text; `text` is authoritative
|
|
469
|
+
* when cents matter.
|
|
470
|
+
*/
|
|
471
|
+
export interface MoneyField {
|
|
472
|
+
value: number
|
|
473
|
+
text: string
|
|
474
|
+
confidence: number
|
|
475
|
+
span?: FieldSpan
|
|
476
|
+
currencyCode?: string
|
|
477
|
+
currencySymbol?: string
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export interface NumberField {
|
|
481
|
+
value: number
|
|
482
|
+
text: string
|
|
483
|
+
confidence: number
|
|
484
|
+
span?: FieldSpan
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** How the page is read. */
|
|
488
|
+
export interface OcrOptions {
|
|
489
|
+
/**
|
|
490
|
+
* The language Tesseract reads in, as it names its data; `eng` when left out. Several are
|
|
491
|
+
* joined with `+`. A language the machine has no data for is said in the page's warnings.
|
|
492
|
+
*/
|
|
493
|
+
lang?: string
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* The standard paper size nearest to a page, as a union keyed on `type`. The
|
|
498
|
+
* values of `type` are spelled the way a database enum spells them (`A4`, `LETTER`,
|
|
499
|
+
* `UNKNOWN`). A standard size carries its own dimensions in points, portrait: `width` is
|
|
500
|
+
* the short side. They are the standard's, not the page's; the page's are its `sizeInPoints` and its `sizeAsRead`.
|
|
501
|
+
*
|
|
502
|
+
* `UNKNOWN` carries `closestTo`, the standard sizes the page lies between by area: first the
|
|
503
|
+
* largest one no larger than the page, then the smallest one larger. A side is `null` when
|
|
504
|
+
* the page is beyond that end of the list (smaller than A10, or larger than B0), and both
|
|
505
|
+
* are when the page states no resolution, and so has no size to compare.
|
|
506
|
+
*/
|
|
507
|
+
export type PaperSize =
|
|
508
|
+
| { type: 'A0'; width: number; height: number }
|
|
509
|
+
| { type: 'A1'; width: number; height: number }
|
|
510
|
+
| { type: 'A2'; width: number; height: number }
|
|
511
|
+
| { type: 'A3'; width: number; height: number }
|
|
512
|
+
| { type: 'A4'; width: number; height: number }
|
|
513
|
+
| { type: 'A5'; width: number; height: number }
|
|
514
|
+
| { type: 'A6'; width: number; height: number }
|
|
515
|
+
| { type: 'A7'; width: number; height: number }
|
|
516
|
+
| { type: 'A8'; width: number; height: number }
|
|
517
|
+
| { type: 'A9'; width: number; height: number }
|
|
518
|
+
| { type: 'A10'; width: number; height: number }
|
|
519
|
+
| { type: 'B0'; width: number; height: number }
|
|
520
|
+
| { type: 'B1'; width: number; height: number }
|
|
521
|
+
| { type: 'B2'; width: number; height: number }
|
|
522
|
+
| { type: 'B3'; width: number; height: number }
|
|
523
|
+
| { type: 'B4'; width: number; height: number }
|
|
524
|
+
| { type: 'B5'; width: number; height: number }
|
|
525
|
+
| { type: 'B6'; width: number; height: number }
|
|
526
|
+
| { type: 'B7'; width: number; height: number }
|
|
527
|
+
| { type: 'B8'; width: number; height: number }
|
|
528
|
+
| { type: 'B9'; width: number; height: number }
|
|
529
|
+
| { type: 'B10'; width: number; height: number }
|
|
530
|
+
| { type: 'LETTER'; width: number; height: number }
|
|
531
|
+
| { type: 'LEGAL'; width: number; height: number }
|
|
532
|
+
| { type: 'TABLOID'; width: number; height: number }
|
|
533
|
+
| { type: 'EXECUTIVE'; width: number; height: number }
|
|
534
|
+
| { type: 'STATEMENT'; width: number; height: number }
|
|
535
|
+
| { type: 'UNKNOWN'; closestTo: [StandardPaperSize | undefined | null, StandardPaperSize | undefined | null] }
|
|
536
|
+
|
|
537
|
+
export interface PaymentDetail {
|
|
538
|
+
iban?: StringField
|
|
539
|
+
swift?: StringField
|
|
540
|
+
bankName?: StringField
|
|
541
|
+
accountNumber?: StringField
|
|
542
|
+
routingNumber?: StringField
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* A standard paper size, as a union keyed on `type`, with its own dimensions in points,
|
|
547
|
+
* portrait: `width` is the short side.
|
|
548
|
+
*/
|
|
549
|
+
export type StandardPaperSize =
|
|
550
|
+
| { type: 'A0'; width: number; height: number }
|
|
551
|
+
| { type: 'A1'; width: number; height: number }
|
|
552
|
+
| { type: 'A2'; width: number; height: number }
|
|
553
|
+
| { type: 'A3'; width: number; height: number }
|
|
554
|
+
| { type: 'A4'; width: number; height: number }
|
|
555
|
+
| { type: 'A5'; width: number; height: number }
|
|
556
|
+
| { type: 'A6'; width: number; height: number }
|
|
557
|
+
| { type: 'A7'; width: number; height: number }
|
|
558
|
+
| { type: 'A8'; width: number; height: number }
|
|
559
|
+
| { type: 'A9'; width: number; height: number }
|
|
560
|
+
| { type: 'A10'; width: number; height: number }
|
|
561
|
+
| { type: 'B0'; width: number; height: number }
|
|
562
|
+
| { type: 'B1'; width: number; height: number }
|
|
563
|
+
| { type: 'B2'; width: number; height: number }
|
|
564
|
+
| { type: 'B3'; width: number; height: number }
|
|
565
|
+
| { type: 'B4'; width: number; height: number }
|
|
566
|
+
| { type: 'B5'; width: number; height: number }
|
|
567
|
+
| { type: 'B6'; width: number; height: number }
|
|
568
|
+
| { type: 'B7'; width: number; height: number }
|
|
569
|
+
| { type: 'B8'; width: number; height: number }
|
|
570
|
+
| { type: 'B9'; width: number; height: number }
|
|
571
|
+
| { type: 'B10'; width: number; height: number }
|
|
572
|
+
| { type: 'LETTER'; width: number; height: number }
|
|
573
|
+
| { type: 'LEGAL'; width: number; height: number }
|
|
574
|
+
| { type: 'TABLOID'; width: number; height: number }
|
|
575
|
+
| { type: 'EXECUTIVE'; width: number; height: number }
|
|
576
|
+
| { type: 'STATEMENT'; width: number; height: number }
|
|
577
|
+
|
|
578
|
+
export interface StringField {
|
|
579
|
+
value: string
|
|
580
|
+
/** The exact source text the value was derived from. */
|
|
581
|
+
text: string
|
|
582
|
+
confidence: number
|
|
583
|
+
span?: FieldSpan
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
export interface TaxDetail {
|
|
587
|
+
rate?: NumberField
|
|
588
|
+
amount?: MoneyField
|
|
589
|
+
base?: MoneyField
|
|
590
|
+
category?: StringField
|
|
591
|
+
}
|
package/index.js
ADDED