react-native-text-reader 0.3.0 → 0.5.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.
@@ -63,7 +63,6 @@ android {
63
63
  defaultConfig {
64
64
  minSdkVersion getExtOrIntegerDefault("minSdkVersion")
65
65
  targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
66
-
67
66
  }
68
67
 
69
68
  buildTypes {
@@ -74,6 +73,7 @@ android {
74
73
 
75
74
  lintOptions {
76
75
  disable "GradleCompatible"
76
+ abortOnError false
77
77
  }
78
78
 
79
79
  compileOptions {
@@ -95,16 +95,16 @@ dependencies {
95
95
  //noinspection GradleDynamicVersion
96
96
  implementation "com.facebook.react:react-native:+"
97
97
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
98
-
98
+
99
99
  // To recognize Latin script
100
- implementation 'com.google.mlkit:text-recognition:16.0.0'
100
+ implementation 'com.google.mlkit:text-recognition:16.0.1'
101
101
  // To recognize Chinese script
102
- implementation 'com.google.mlkit:text-recognition-chinese:16.0.0'
102
+ implementation 'com.google.mlkit:text-recognition-chinese:16.0.1'
103
103
  // To recognize Devanagari script
104
- implementation 'com.google.mlkit:text-recognition-devanagari:16.0.0'
104
+ implementation 'com.google.mlkit:text-recognition-devanagari:16.0.1'
105
105
  // To recognize Japanese script
106
- implementation 'com.google.mlkit:text-recognition-japanese:16.0.0'
106
+ implementation 'com.google.mlkit:text-recognition-japanese:16.0.1'
107
107
  // To recognize Korean script
108
- implementation 'com.google.mlkit:text-recognition-korean:16.0.0'
108
+ implementation 'com.google.mlkit:text-recognition-korean:16.0.1'
109
109
  }
110
110
 
@@ -28,11 +28,10 @@ import com.google.mlkit.vision.text.latin.TextRecognizerOptions
28
28
  import java.io.IOException
29
29
  import java.net.URL
30
30
 
31
-
32
31
  class TextReaderModule(reactContext: ReactApplicationContext) :
33
32
  ReactContextBaseJavaModule(reactContext) {
34
- override fun getName(): String {
35
- return NAME
33
+ override fun getName(): String {
34
+ return "TextReader"
36
35
  }
37
36
 
38
37
  @Throws(IOException::class)
@@ -121,10 +120,14 @@ class TextReaderModule(reactContext: ReactApplicationContext) :
121
120
  }
122
121
 
123
122
  @ReactMethod
124
- fun read(url: String, script: String, promise: Promise) {
123
+ fun read(url: String, options: ReadableMap?, promise: Promise) {
125
124
  try {
125
+ val script = options?.getString("script")
126
+
126
127
  val image = getInputImage(reactApplicationContext, url)
128
+
127
129
  val options = getScriptTextRecognizerOptions(script)
130
+
128
131
  val recognizer: TextRecognizer = TextRecognition.getClient(options)
129
132
 
130
133
  recognizer.process(image)
@@ -149,8 +152,4 @@ class TextReaderModule(reactContext: ReactApplicationContext) :
149
152
  promise.reject("Text recognition failed", e)
150
153
  }
151
154
  }
152
-
153
- companion object {
154
- const val NAME = "TextReader"
155
- }
156
155
  }
@@ -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.3.0",
3
+ "version": "0.5.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;