@mrbilit/mrz-scanner 2.0.0 → 2.0.1
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/dist/index.d.ts +0 -19
- package/dist/index.js +27 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -16,25 +16,6 @@ export { parse }
|
|
|
16
16
|
|
|
17
17
|
export { ParseResult }
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Scan a document image for MRZ data.
|
|
21
|
-
*
|
|
22
|
-
* @param image - An image-js Image of the document
|
|
23
|
-
* @param options - Configuration options
|
|
24
|
-
* @returns Parsed MRZ result with fields, or error details
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* import { Image } from 'image-js';
|
|
29
|
-
* import { scanMrz } from '@mrbilit/mrz-scanner';
|
|
30
|
-
*
|
|
31
|
-
* const image = await Image.load('passport.jpg');
|
|
32
|
-
* const result = await scanMrz(image);
|
|
33
|
-
* if (result.parsed?.valid) {
|
|
34
|
-
* console.log(result.parsed.fields);
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
19
|
export declare function scanMrz(image: Image_2, options?: ScanMrzOptions): Promise<ScanMrzResult>;
|
|
39
20
|
|
|
40
21
|
export declare interface ScanMrzOptions {
|
package/dist/index.js
CHANGED
|
@@ -2,25 +2,38 @@ import { getMrz as e } from "@mrbilit/mrz-detection";
|
|
|
2
2
|
import { MrzOcr as t } from "@mrbilit/mrz-ocr";
|
|
3
3
|
import { parse as n, parse as r } from "@mrbilit/mrz-core";
|
|
4
4
|
//#region src/scan-mrz.ts
|
|
5
|
-
var i = null;
|
|
6
|
-
async function
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
var i = null, a = null;
|
|
6
|
+
async function o(e) {
|
|
7
|
+
return i || (a ||= (async () => {
|
|
8
|
+
let n = new t({ modelPath: e });
|
|
9
|
+
return await n.init(), i = n, n;
|
|
10
|
+
})().catch((e) => {
|
|
11
|
+
throw a = null, e;
|
|
12
|
+
}), a);
|
|
13
|
+
}
|
|
14
|
+
async function s(t, n = {}) {
|
|
15
|
+
let { onProgress: i, debug: a = !1 } = n, s = {}, c;
|
|
16
|
+
try {
|
|
17
|
+
c = await o(n.modelPath);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return s.error = e instanceof Error ? e : Error(String(e)), s;
|
|
20
|
+
}
|
|
21
|
+
i?.("detecting");
|
|
9
22
|
try {
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
23
|
+
let n = e(t, { debug: a });
|
|
24
|
+
a && (s.debugImages = n.debugImages), i?.("ocr");
|
|
25
|
+
let o = await c.recognize(n.crop);
|
|
26
|
+
s.ocrLines = o.lines, s.confidence = o.confidence, i?.("parsing"), s.parsed = r(o.lines);
|
|
14
27
|
} catch (e) {
|
|
15
28
|
try {
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
|
|
29
|
+
i?.("ocr");
|
|
30
|
+
let n = await c.recognize(t);
|
|
31
|
+
n.lines.length > 0 ? (s.ocrLines = n.lines, s.confidence = n.confidence, i?.("parsing"), s.parsed = r(n.lines)) : s.error = e instanceof Error ? e : Error(String(e));
|
|
19
32
|
} catch {
|
|
20
|
-
|
|
33
|
+
s.error = e instanceof Error ? e : Error(String(e));
|
|
21
34
|
}
|
|
22
35
|
}
|
|
23
|
-
return
|
|
36
|
+
return s;
|
|
24
37
|
}
|
|
25
38
|
//#endregion
|
|
26
|
-
export { n as parse,
|
|
39
|
+
export { n as parse, s as scanMrz };
|