react-native-text-reader 0.4.0 → 1.1.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/README.md CHANGED
@@ -1,33 +1,117 @@
1
- # react-native-text-reader
1
+ # `react-native-text-reader`
2
2
 
3
- A React Native library for OCR (Optical Character Recognition) using Vision Framework on iOS and Firebase ML Kit on Android.
3
+ A simple React Native library for extracting text from images using native iOS (Vision Framework) and Android (ML Kit) capabilities.
4
+
5
+
6
+ ## Table of Contents
7
+
8
+ - [Installation](#installation)
9
+ - [Platform Setup](#platform-setup)
10
+ - [iOS](#ios)
11
+ - [Android](#android)
12
+ - [Usage](#usage)
13
+ - [Basic Example](#basic-example)
14
+ - [Options](#options)
15
+ - [ScriptOptions Enum](#scriptoptions-enum)
16
+ - [Contributing](#contributing)
17
+ - [License](#license)
18
+
19
+ ### NOTE:
20
+ I currently do not work extensively with React Native, so this project may not receive frequent updates. However, if anyone is interested in contributing, please feel free to reach out!
4
21
 
5
22
  ## Installation
6
23
 
7
- ```sh
24
+ Install the package using npm or yarn:
25
+
26
+ ```bash
8
27
  npm install react-native-text-reader
9
28
  ```
10
29
 
30
+ or
31
+
32
+ ```bash
33
+ yarn add react-native-text-reader
34
+ ```
35
+
36
+ After installing the package, make sure to link the native dependencies:
37
+
38
+ ### iOS
39
+
40
+ If you're using iOS, run the following command to install the necessary native modules:
41
+
42
+ ```bash
43
+ cd ios/ && pod install
44
+ ```
45
+
46
+ ### Android
47
+
48
+ No additional steps are required for Android.
49
+
50
+ ---
51
+
11
52
  ## Usage
12
53
 
54
+ To use the text reader, import it and call the `read` method with the image path and options.
55
+
56
+ ### Basic Example
13
57
 
14
- ```js
15
- import { read } from 'react-native-text-reader';
58
+ ```javascript
59
+ import TextReader, { ScriptOptions } from 'react-native-text-reader';
16
60
 
17
- // ...
61
+ const imagePath = 'path/to/your/image.jpg';
62
+ const options = {
63
+ visionIgnoreThreshold: 0.5, // iOS only
64
+ script: ScriptOptions.LATIN, // Android only
65
+ };
66
+
67
+ const readTextFromImage = async () => {
68
+ try {
69
+ const text = await TextReader.read(imagePath, options);
70
+ console.log('Extracted text:', text);
71
+ } catch (error) {
72
+ console.error('Error reading text:', error);
73
+ }
74
+ };
75
+
76
+ readTextFromImage();
18
77
 
19
- const result = await read('imageUri');
20
78
  ```
21
79
 
80
+ ---
22
81
 
23
- ## Contributing
82
+ ## Options
24
83
 
25
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
84
+ ### `Options`
26
85
 
27
- ## License
86
+ | Property | Type | Description |
87
+ |--------------------------|-------------------|------------------------------------------------------|
88
+ | `visionIgnoreThreshold` | `number` | The confidence threshold for iOS (default: 0.0) |
89
+ | `script` | `ScriptOptions` | The language script for Android (default: `LATIN`) |
28
90
 
29
- MIT
91
+ ---
92
+
93
+ ## ScriptOptions
94
+
95
+ The `ScriptOptions` enum allows you to specify different language scripts for Android:
96
+
97
+ ```javascript
98
+ export enum ScriptOptions {
99
+ LATIN = 'Latin',
100
+ CHINESE = 'Chinese',
101
+ DEVANAGARI = 'Devanagari',
102
+ JAPANESE = 'Japanese',
103
+ KOREAN = 'Korean',
104
+ }
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Contributing
110
+
111
+ Contributions are welcome! Please submit a pull request or open an issue for any enhancements or bugs.
30
112
 
31
113
  ---
32
114
 
33
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
115
+ ## License
116
+
117
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -120,11 +120,13 @@ class TextReaderModule(reactContext: ReactApplicationContext) :
120
120
  }
121
121
 
122
122
  @ReactMethod
123
- fun read(url: String, script: ReadableMap?, promise: Promise) {
123
+ fun read(url: String, options: ReadableMap?, promise: Promise) {
124
124
  try {
125
+ val script = options?.getString("script")
126
+
125
127
  val image = getInputImage(reactApplicationContext, url)
126
128
 
127
- val options = getScriptTextRecognizerOptions(script.toString())
129
+ val options = getScriptTextRecognizerOptions(script)
128
130
 
129
131
  val recognizer: TextRecognizer = TextRecognition.getClient(options)
130
132
 
@@ -10,47 +10,59 @@ extension String {
10
10
  @objc(TextReader)
11
11
  class TextReader: NSObject {
12
12
  @objc static func requiresMainQueueSetup() -> Bool { return true }
13
+
13
14
  @objc(read:withOptions:withResolver:withRejecter:)
14
- func read(imgPath: String, options: [String: Float], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
15
- guard !imgPath.isEmpty else { reject("ERR", "Image path cannot be empty.", nil); return }
15
+ func read(imgPath: String, options: [String: Any], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
16
+ guard !imgPath.isEmpty else {
17
+ reject("ERR_EMPTY_PATH", "Image path cannot be empty.", nil)
18
+ return
19
+ }
16
20
 
17
21
  let formattedImgPath = imgPath.stripPrefix("file://")
18
- var threshold: Float = 0.0
19
-
20
- if !(options["visionIgnoreThreshold"]?.isZero ?? true) {
21
- threshold = options["visionIgnoreThreshold"] ?? 0.0
22
- }
22
+ let threshold = (options["visionIgnoreThreshold"] as? NSNumber)?.floatValue ?? 0.0
23
23
 
24
24
  do {
25
25
  let imgData = try Data(contentsOf: URL(fileURLWithPath: formattedImgPath))
26
- let image = UIImage(data: imgData)
27
-
28
- guard let cgImage = image?.cgImage else { return }
26
+ guard let image = UIImage(data: imgData), let cgImage = image.cgImage else {
27
+ reject("ERR_IMAGE_PROCESSING", "Failed to load image from the provided path.", nil)
28
+ return
29
+ }
29
30
 
30
31
  let requestHandler = VNImageRequestHandler(cgImage: cgImage)
31
-
32
- let ocrRequest = VNRecognizeTextRequest { (request: VNRequest, error: Error?) in
33
- self.textReaderHandler(request: request, threshold: threshold, error: error, resolve: resolve, reject: reject)
32
+ let ocrRequest = VNRecognizeTextRequest { request, error in
33
+ self.handleTextRecognitionResult(request: request, threshold: threshold, error: error, resolve: resolve, reject: reject)
34
34
  }
35
35
 
36
36
  try requestHandler.perform([ocrRequest])
37
37
  } catch {
38
- print(error)
39
- reject("ERR", error.localizedDescription, nil)
38
+ reject("ERR_IMAGE_LOADING", "Failed to load or process the image: \(error.localizedDescription)", nil)
40
39
  }
41
40
  }
42
41
 
43
- func textReaderHandler(request: VNRequest, threshold: Float, error _: Error?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
44
- guard let observations = request.results as? [VNRecognizedTextObservation] else { reject("ERR", "Failed to read the text.", nil); return }
42
+ private func handleTextRecognitionResult(request: VNRequest, threshold: Float, error: Error?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
43
+ if let error = error {
44
+ reject("ERR_OCR", "Error in text recognition: \(error.localizedDescription)", nil)
45
+ return
46
+ }
47
+
48
+ guard let observations = request.results as? [VNRecognizedTextObservation] else {
49
+ reject("ERR_OCR_RESULTS", "Failed to read text from the image.", nil)
50
+ return
51
+ }
45
52
 
46
- let strings = observations.compactMap { observation -> String? in
47
- if observation.topCandidates(1).first?.confidence ?? 0 >= threshold {
48
- return observation.topCandidates(1).first?.string
49
- } else {
50
- return nil
53
+ if observations.isEmpty {
54
+ reject("ERR_NO_TEXT_FOUND", "No text found in the image.", nil)
55
+ return
56
+ }
57
+
58
+ let extractedStrings = observations.compactMap { observation -> String? in
59
+ guard let topCandidate = observation.topCandidates(1).first else { return nil }
60
+ if topCandidate.confidence >= threshold {
61
+ return topCandidate.string
51
62
  }
63
+ return nil
52
64
  }
53
-
54
- resolve(strings)
65
+
66
+ resolve(extractedStrings.isEmpty ? [] : extractedStrings)
55
67
  }
56
- }
68
+ }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.ScriptOptions = void 0;
7
7
  var _reactNative = require("react-native");
8
8
  const LINKING_ERROR = `The package 'react-native-text-reader' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
9
9
  ios: "- You have run 'pod install'\n",
@@ -14,15 +14,25 @@ const TextReader = _reactNative.NativeModules.TextReader ? _reactNative.NativeMo
14
14
  throw new Error(LINKING_ERROR);
15
15
  }
16
16
  });
17
+ let ScriptOptions = exports.ScriptOptions = /*#__PURE__*/function (ScriptOptions) {
18
+ ScriptOptions["LATIN"] = "Latin";
19
+ ScriptOptions["CHINESE"] = "Chinese";
20
+ ScriptOptions["DEVANAGARI"] = "Devanagari";
21
+ ScriptOptions["JAPANESE"] = "Japanese";
22
+ ScriptOptions["KOREAN"] = "Korean";
23
+ return ScriptOptions;
24
+ }({}); // Options
17
25
  /**
18
- * Extrae texto de una imagen.
19
- * @param imagePath - La URI de la imagen de la que se extraerá el texto.
20
- * @param options - Opciones adicionales.
21
- * @param options.visionIgnoreThreshold - Umbral de ignoración de la visión.
22
- * @returns Una promesa que se resuelve con el texto extraído.
26
+ * Extracts text from an image.
27
+ * @param imagePath - Image path
28
+ * @param options - Additional options
29
+ * @param options.visionIgnoreThreshold - Vision ignore threshold(iOS)
30
+ * @param options.script - Language script (Android)
23
31
  */
24
32
  async function read(imagePath, options) {
25
- return await TextReader.read(imagePath, options || {});
33
+ return await TextReader.read(imagePath, options || {
34
+ script: ScriptOptions.LATIN
35
+ });
26
36
  }
27
37
  var _default = exports.default = {
28
38
  read
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","TextReader","NativeModules","Proxy","get","Error","read","imagePath","options","_default","exports"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,mFAAmF,GACnFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,UAAU,GAAGC,0BAAa,CAACD,UAAU,GACvCC,0BAAa,CAACD,UAAU,GACxB,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAUL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeU,IAAIA,CACjBC,SAAiB,EACjBC,OAA2B,EACR;EACnB,OAAO,MAAMP,UAAU,CAACK,IAAI,CAACC,SAAS,EAAEC,OAAO,IAAI,CAAC,CAAC,CAAC;AACxD;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAV,OAAA,GAEc;EAAEM;AAAK,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","TextReader","NativeModules","Proxy","get","Error","ScriptOptions","exports","read","imagePath","options","script","LATIN","_default"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,mFAAmF,GACnFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,UAAU,GAAGC,0BAAa,CAACD,UAAU,GACvCC,0BAAa,CAACD,UAAU,GACxB,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAAC,IAEMU,aAAa,GAAAC,OAAA,CAAAD,aAAA,0BAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAA,OAAbA,aAAa;AAAA,OAQzB;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeE,IAAIA,CAACC,SAAiB,EAAEC,OAAgB,EAAqB;EAC1E,OAAO,MAAMT,UAAU,CAACO,IAAI,CAC1BC,SAAS,EACTC,OAAO,IAAI;IACTC,MAAM,EAAEL,aAAa,CAACM;EACxB,CACF,CAAC;AACH;AAAC,IAAAC,QAAA,GAAAN,OAAA,CAAAP,OAAA,GAEc;EAAEQ;AAAK,CAAC","ignoreList":[]}
@@ -10,15 +10,28 @@ const TextReader = NativeModules.TextReader ? NativeModules.TextReader : new Pro
10
10
  throw new Error(LINKING_ERROR);
11
11
  }
12
12
  });
13
+ export let ScriptOptions = /*#__PURE__*/function (ScriptOptions) {
14
+ ScriptOptions["LATIN"] = "Latin";
15
+ ScriptOptions["CHINESE"] = "Chinese";
16
+ ScriptOptions["DEVANAGARI"] = "Devanagari";
17
+ ScriptOptions["JAPANESE"] = "Japanese";
18
+ ScriptOptions["KOREAN"] = "Korean";
19
+ return ScriptOptions;
20
+ }({});
21
+
22
+ // Options
23
+
13
24
  /**
14
- * Extrae texto de una imagen.
15
- * @param imagePath - La URI de la imagen de la que se extraerá el texto.
16
- * @param options - Opciones adicionales.
17
- * @param options.visionIgnoreThreshold - Umbral de ignoración de la visión.
18
- * @returns Una promesa que se resuelve con el texto extraído.
25
+ * Extracts text from an image.
26
+ * @param imagePath - Image path
27
+ * @param options - Additional options
28
+ * @param options.visionIgnoreThreshold - Vision ignore threshold(iOS)
29
+ * @param options.script - Language script (Android)
19
30
  */
20
31
  async function read(imagePath, options) {
21
- return await TextReader.read(imagePath, options || {});
32
+ return await TextReader.read(imagePath, options || {
33
+ script: ScriptOptions.LATIN
34
+ });
22
35
  }
23
36
  export default {
24
37
  read
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","TextReader","Proxy","get","Error","read","imagePath","options"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,mFAAmF,GACnFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,UAAU,GAAGN,aAAa,CAACM,UAAU,GACvCN,aAAa,CAACM,UAAU,GACxB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAUL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeQ,IAAIA,CACjBC,SAAiB,EACjBC,OAA2B,EACR;EACnB,OAAO,MAAMN,UAAU,CAACI,IAAI,CAACC,SAAS,EAAEC,OAAO,IAAI,CAAC,CAAC,CAAC;AACxD;AAEA,eAAe;EAAEF;AAAK,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","TextReader","Proxy","get","Error","ScriptOptions","read","imagePath","options","script","LATIN"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,mFAAmF,GACnFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,UAAU,GAAGN,aAAa,CAACM,UAAU,GACvCN,aAAa,CAACM,UAAU,GACxB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,WAAYQ,aAAa,0BAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAA,OAAbA,aAAa;AAAA;;AAQzB;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeC,IAAIA,CAACC,SAAiB,EAAEC,OAAgB,EAAqB;EAC1E,OAAO,MAAMP,UAAU,CAACK,IAAI,CAC1BC,SAAS,EACTC,OAAO,IAAI;IACTC,MAAM,EAAEJ,aAAa,CAACK;EACxB,CACF,CAAC;AACH;AAEA,eAAe;EAAEJ;AAAK,CAAC","ignoreList":[]}
@@ -1,8 +1,16 @@
1
- export type TextReaderOptions = {
1
+ export declare enum ScriptOptions {
2
+ LATIN = "Latin",
3
+ CHINESE = "Chinese",
4
+ DEVANAGARI = "Devanagari",
5
+ JAPANESE = "Japanese",
6
+ KOREAN = "Korean"
7
+ }
8
+ export type Options = {
2
9
  visionIgnoreThreshold?: number;
10
+ script?: ScriptOptions;
3
11
  };
4
12
  type TextReaderType = {
5
- read(imagePath: string, options?: TextReaderOptions): Promise<string[]>;
13
+ read(imagePath: string, options?: Options): Promise<string[]>;
6
14
  };
7
15
  declare const _default: TextReaderType;
8
16
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAmBA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACzE,CAAC;wBAgByB,cAAc;AAAzC,wBAA0C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAmBA,oBAAY,aAAa;IACvB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,QAAQ,aAAa;IACrB,MAAM,WAAW;CAClB;AAGD,MAAM,MAAM,OAAO,GAAG;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC/D,CAAC;wBAkByB,cAAc;AAAzC,wBAA0C"}
@@ -1,8 +1,16 @@
1
- export type TextReaderOptions = {
1
+ export declare enum ScriptOptions {
2
+ LATIN = "Latin",
3
+ CHINESE = "Chinese",
4
+ DEVANAGARI = "Devanagari",
5
+ JAPANESE = "Japanese",
6
+ KOREAN = "Korean"
7
+ }
8
+ export type Options = {
2
9
  visionIgnoreThreshold?: number;
10
+ script?: ScriptOptions;
3
11
  };
4
12
  type TextReaderType = {
5
- read(imagePath: string, options?: TextReaderOptions): Promise<string[]>;
13
+ read(imagePath: string, options?: Options): Promise<string[]>;
6
14
  };
7
15
  declare const _default: TextReaderType;
8
16
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAmBA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACzE,CAAC;wBAgByB,cAAc;AAAzC,wBAA0C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAmBA,oBAAY,aAAa;IACvB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,QAAQ,aAAa;IACrB,MAAM,WAAW;CAClB;AAGD,MAAM,MAAM,OAAO,GAAG;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC/D,CAAC;wBAkByB,cAAc;AAAzC,wBAA0C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-text-reader",
3
- "version": "0.4.0",
3
+ "version": "1.1.0",
4
4
  "description": "A React Native library for OCR (Optical Character Recognition) using Vision Framework on iOS and Firebase ML Kit on Android.",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
package/src/index.tsx CHANGED
@@ -17,26 +17,38 @@ const TextReader = NativeModules.TextReader
17
17
  }
18
18
  );
19
19
 
20
- export type TextReaderOptions = {
21
- visionIgnoreThreshold?: number;
20
+ export enum ScriptOptions {
21
+ LATIN = 'Latin',
22
+ CHINESE = 'Chinese',
23
+ DEVANAGARI = 'Devanagari',
24
+ JAPANESE = 'Japanese',
25
+ KOREAN = 'Korean',
26
+ }
27
+
28
+ // Options
29
+ export type Options = {
30
+ visionIgnoreThreshold?: number; // only iOS
31
+ script?: ScriptOptions; // only Android
22
32
  };
23
33
 
24
34
  type TextReaderType = {
25
- read(imagePath: string, options?: TextReaderOptions): Promise<string[]>;
35
+ read(imagePath: string, options?: Options): Promise<string[]>;
26
36
  };
27
37
 
28
38
  /**
29
- * Extrae texto de una imagen.
30
- * @param imagePath - La URI de la imagen de la que se extraerá el texto.
31
- * @param options - Opciones adicionales.
32
- * @param options.visionIgnoreThreshold - Umbral de ignoración de la visión.
33
- * @returns Una promesa que se resuelve con el texto extraído.
39
+ * Extracts text from an image.
40
+ * @param imagePath - Image path
41
+ * @param options - Additional options
42
+ * @param options.visionIgnoreThreshold - Vision ignore threshold(iOS)
43
+ * @param options.script - Language script (Android)
34
44
  */
35
- async function read(
36
- imagePath: string,
37
- options?: TextReaderOptions
38
- ): Promise<string[]> {
39
- return await TextReader.read(imagePath, options || {});
45
+ async function read(imagePath: string, options: Options): Promise<string[]> {
46
+ return await TextReader.read(
47
+ imagePath,
48
+ options || {
49
+ script: ScriptOptions.LATIN,
50
+ }
51
+ );
40
52
  }
41
53
 
42
54
  export default { read } as TextReaderType;