@mrbilit/mrz-scanner 2.0.0 → 2.0.2

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 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 a(n, a = {}) {
7
- let { onProgress: o, debug: s = !1 } = a, c = {};
8
- o?.("detecting"), i || (i = new t({ modelPath: a.modelPath }), await i.init());
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 t = e(n, { debug: s });
11
- s && (c.debugImages = t.debugImages), o?.("ocr");
12
- let a = await i.recognize(t.crop);
13
- c.ocrLines = a.lines, c.confidence = a.confidence, o?.("parsing"), c.parsed = r(a.lines);
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
- o?.("ocr");
17
- let t = await i.recognize(n);
18
- t.lines.length > 0 ? (c.ocrLines = t.lines, c.confidence = t.confidence, o?.("parsing"), c.parsed = r(t.lines)) : c.error = e instanceof Error ? e : Error(String(e));
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
- c.error = e instanceof Error ? e : Error(String(e));
33
+ s.error = e instanceof Error ? e : Error(String(e));
21
34
  }
22
35
  }
23
- return c;
36
+ return s;
24
37
  }
25
38
  //#endregion
26
- export { n as parse, a as scanMrz };
39
+ export { n as parse, s as scanMrz };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrbilit/mrz-scanner",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Full MRZ scanning pipeline: detect, OCR, and parse",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@mrbilit/mrz-core": "2.0.0",
22
22
  "@mrbilit/mrz-detection": "2.0.0",
23
- "@mrbilit/mrz-ocr": "2.0.0",
23
+ "@mrbilit/mrz-ocr": "2.0.2",
24
24
  "image-js": "^1.5.0"
25
25
  },
26
26
  "devDependencies": {