Skip to content

Commit

Permalink
refactor(text-recognition): use TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
a7medev committed Sep 30, 2023
1 parent fdd179c commit f4e81db
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 45 deletions.
36 changes: 0 additions & 36 deletions text-recognition/index.js

This file was deleted.

33 changes: 28 additions & 5 deletions text-recognition/index.d.ts → text-recognition/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { NativeModules, Platform } from 'react-native';

export interface Frame {
width: number;
height: number;
Expand Down Expand Up @@ -67,7 +69,24 @@ export enum TextRecognitionScript {
KOREAN = 'Korean',
}

interface ITextRecognition {
const LINKING_ERROR =
`The package '@react-native-ml-kit/text-recognition' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo managed workflow\n';

const NativeTextRecognition = NativeModules.TextRecognition
? NativeModules.TextRecognition
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);

const TextRecognition = {
/**
* Recognize text in the image
*
Expand All @@ -84,10 +103,14 @@ interface ITextRecognition {
*/
recognize: (
imageURL: string,
script?: TranslateRecognitionScript = TranslateRecognitionScript.LATIN
) => Promise<TextRecognitionResult>;
}
script = TextRecognitionScript.LATIN
): Promise<TextRecognitionResult> => {
if (Platform.OS === 'ios') {
return NativeTextRecognition.recognize(imageURL, script);
}

declare const TextRecognition: ITextRecognition;
return NativeTextRecognition.recognize(imageURL);
},
};

export default TextRecognition;
9 changes: 5 additions & 4 deletions text-recognition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
"title": "React Native ML Kit Text Recognition",
"version": "1.3.0",
"description": "React Native On-Device Text Recognition w/ Google ML Kit",
"main": "index.js",
"types": "index.d.ts",
"main": "index.ts",
"files": [
"README.md",
"android",
"index.js",
"index.d.ts",
"index.ts",
"ios",
"RNMLKitTextRecognition.podspec"
],
Expand All @@ -34,5 +32,8 @@
"peerDependencies": {
"react": ">=16.8.1",
"react-native": ">=0.60.0-rc.0 <1.0.x"
},
"devDependencies": {
"@types/react-native": "^0.72.3"
}
}
67 changes: 67 additions & 0 deletions text-recognition/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@react-native/virtualized-lists@^0.72.4":
version "0.72.8"
resolved "https://registry.yarnpkg.com/@react-native/virtualized-lists/-/virtualized-lists-0.72.8.tgz#a2c6a91ea0f1d40eb5a122fb063daedb92ed1dc3"
integrity sha512-J3Q4Bkuo99k7mu+jPS9gSUSgq+lLRSI/+ahXNwV92XgJ/8UgOTxu2LPwhJnBk/sQKxq7E8WkZBnBiozukQMqrw==
dependencies:
invariant "^2.2.4"
nullthrows "^1.1.1"

"@types/prop-types@*":
version "15.7.7"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.7.tgz#f9361f7b87fd5d8188b2c998db0a1f47e9fb391a"
integrity sha512-FbtmBWCcSa2J4zL781Zf1p5YUBXQomPEcep9QZCfRfQgTxz3pJWiDFLebohZ9fFntX5ibzOkSsrJ0TEew8cAog==

"@types/react-native@^0.72.3":
version "0.72.3"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.72.3.tgz#eb5726eb3ec6b79a10db7a295cc0346eb5e9331a"
integrity sha512-9+g+DBJIY3bG7+ZlYzKPr9kxTQxUuZQgLWZhYK4RlIcrsm3qaJhL2PU2e/K4CjnzznWCo2Islgec94x2z1pG4Q==
dependencies:
"@react-native/virtualized-lists" "^0.72.4"
"@types/react" "*"

"@types/react@*":
version "18.2.23"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.23.tgz#60ad6cf4895e93bed858db0e03bcc4ff97d0410e"
integrity sha512-qHLW6n1q2+7KyBEYnrZpcsAmU/iiCh9WGCKgXvMxx89+TYdJWRjZohVIo9XTcoLhfX3+/hP0Pbulu3bCZQ9PSA==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.16.4"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.4.tgz#fedc3e5b15c26dc18faae96bf1317487cb3658cf"
integrity sha512-2L9ifAGl7wmXwP4v3pN4p2FLhD0O1qsJpvKmNin5VA8+UvNVb447UDaAEV6UdrkA+m/Xs58U1RFps44x6TFsVQ==

csstype@^3.0.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==

invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
dependencies:
loose-envify "^1.0.0"

"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

loose-envify@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

nullthrows@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/nullthrows/-/nullthrows-1.1.1.tgz#7818258843856ae971eae4208ad7d7eb19a431b1"
integrity sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==

0 comments on commit f4e81db

Please sign in to comment.