From f29e79d166af654fc89da9c310ffca6000973ccb Mon Sep 17 00:00:00 2001 From: Ahmed Mahmoud Date: Sat, 30 Sep 2023 16:35:35 +0300 Subject: [PATCH] refactor(barcode): use TypeScript --- barcode-scanning/index.d.ts | 30 ----------- barcode-scanning/{index.js => index.ts} | 47 ++++++++++------- barcode-scanning/package.json | 9 ++-- barcode-scanning/yarn.lock | 67 +++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 53 deletions(-) delete mode 100644 barcode-scanning/index.d.ts rename barcode-scanning/{index.js => index.ts} (52%) create mode 100644 barcode-scanning/yarn.lock diff --git a/barcode-scanning/index.d.ts b/barcode-scanning/index.d.ts deleted file mode 100644 index 0d7c02c..0000000 --- a/barcode-scanning/index.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -export enum BarcodeFormat { - UNKNOWN = -1, - ALL_FORMATS = 0, - CODE_128 = 1, - CODE_39 = 2, - CODE_93 = 4, - CODABAR = 8, - DATA_MATRIX = 16, - EAN_13 = 32, - EAN_8 = 64, - ITF = 128, - QR_CODE = 256, - UPC_A = 512, - UPC_E = 1024, - PDF417 = 2048, - AZTEC = 4096, -} - -export interface Barcode { - format: BarcodeFormat; - value: string; -} - -interface IBarcodeScanning { - scan: (imageURL: string) => Promise; -} - -declare const BarcodeScanning: IBarcodeScanning; - -export default BarcodeScanning; diff --git a/barcode-scanning/index.js b/barcode-scanning/index.ts similarity index 52% rename from barcode-scanning/index.js rename to barcode-scanning/index.ts index 105921a..d0bd38d 100644 --- a/barcode-scanning/index.js +++ b/barcode-scanning/index.ts @@ -1,30 +1,39 @@ import { NativeModules, Platform } from 'react-native'; +export enum BarcodeFormat { + UNKNOWN = -1, + ALL_FORMATS = 0, + CODE_128 = 1, + CODE_39 = 2, + CODE_93 = 4, + CODABAR = 8, + DATA_MATRIX = 16, + EAN_13 = 32, + EAN_8 = 64, + ITF = 128, + QR_CODE = 256, + UPC_A = 512, + UPC_E = 1024, + PDF417 = 2048, + AZTEC = 4096, +} + +export interface Barcode { + format: BarcodeFormat; + value: string; +} + +interface IBarcodeScanning { + scan: (imageURL: string) => Promise; +} + const LINKING_ERROR = `The package '@react-native-ml-kit/barcode-scanning' 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'; -export const BarcodeFormat = Object.freeze({ - UNKNOWN: -1, - ALL_FORMATS: 0, - CODE_128: 1, - CODE_39: 2, - CODE_93: 4, - CODABAR: 8, - DATA_MATRIX: 16, - EAN_13: 32, - EAN_8: 64, - ITF: 128, - QR_CODE: 256, - UPC_A: 512, - UPC_E: 1024, - PDF417: 2048, - AZTEC: 4096, -}); - -const BarcodeScanning = NativeModules.BarcodeScanning +const BarcodeScanning: IBarcodeScanning = NativeModules.BarcodeScanning ? NativeModules.BarcodeScanning : new Proxy( {}, diff --git a/barcode-scanning/package.json b/barcode-scanning/package.json index 8931d29..ed3e65f 100644 --- a/barcode-scanning/package.json +++ b/barcode-scanning/package.json @@ -3,13 +3,11 @@ "title": "React Native ML Kit Barcode Scanning", "version": "1.3.0", "description": "React Native On-Device Barcode Scanning 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", "RNMLKitBarcodeScanning.podspec", "ios" ], @@ -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" } } diff --git a/barcode-scanning/yarn.lock b/barcode-scanning/yarn.lock new file mode 100644 index 0000000..c4d1759 --- /dev/null +++ b/barcode-scanning/yarn.lock @@ -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==