Skip to content

Commit f29e79d

Browse files
committed
refactor(barcode): use TypeScript
1 parent 8edf002 commit f29e79d

File tree

4 files changed

+100
-53
lines changed

4 files changed

+100
-53
lines changed

barcode-scanning/index.d.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

barcode-scanning/index.js renamed to barcode-scanning/index.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
import { NativeModules, Platform } from 'react-native';
22

3+
export enum BarcodeFormat {
4+
UNKNOWN = -1,
5+
ALL_FORMATS = 0,
6+
CODE_128 = 1,
7+
CODE_39 = 2,
8+
CODE_93 = 4,
9+
CODABAR = 8,
10+
DATA_MATRIX = 16,
11+
EAN_13 = 32,
12+
EAN_8 = 64,
13+
ITF = 128,
14+
QR_CODE = 256,
15+
UPC_A = 512,
16+
UPC_E = 1024,
17+
PDF417 = 2048,
18+
AZTEC = 4096,
19+
}
20+
21+
export interface Barcode {
22+
format: BarcodeFormat;
23+
value: string;
24+
}
25+
26+
interface IBarcodeScanning {
27+
scan: (imageURL: string) => Promise<Barcode[]>;
28+
}
29+
330
const LINKING_ERROR =
431
`The package '@react-native-ml-kit/barcode-scanning' doesn't seem to be linked. Make sure: \n\n` +
532
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
633
'- You rebuilt the app after installing the package\n' +
734
'- You are not using Expo managed workflow\n';
835

9-
export const BarcodeFormat = Object.freeze({
10-
UNKNOWN: -1,
11-
ALL_FORMATS: 0,
12-
CODE_128: 1,
13-
CODE_39: 2,
14-
CODE_93: 4,
15-
CODABAR: 8,
16-
DATA_MATRIX: 16,
17-
EAN_13: 32,
18-
EAN_8: 64,
19-
ITF: 128,
20-
QR_CODE: 256,
21-
UPC_A: 512,
22-
UPC_E: 1024,
23-
PDF417: 2048,
24-
AZTEC: 4096,
25-
});
26-
27-
const BarcodeScanning = NativeModules.BarcodeScanning
36+
const BarcodeScanning: IBarcodeScanning = NativeModules.BarcodeScanning
2837
? NativeModules.BarcodeScanning
2938
: new Proxy(
3039
{},

barcode-scanning/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
"title": "React Native ML Kit Barcode Scanning",
44
"version": "1.3.0",
55
"description": "React Native On-Device Barcode Scanning w/ Google ML Kit",
6-
"main": "index.js",
7-
"types": "index.d.ts",
6+
"main": "index.ts",
87
"files": [
98
"README.md",
109
"android",
11-
"index.js",
12-
"index.d.ts",
10+
"index.ts",
1311
"RNMLKitBarcodeScanning.podspec",
1412
"ios"
1513
],
@@ -34,5 +32,8 @@
3432
"peerDependencies": {
3533
"react": ">=16.8.1",
3634
"react-native": ">=0.60.0-rc.0 <1.0.x"
35+
},
36+
"devDependencies": {
37+
"@types/react-native": "^0.72.3"
3738
}
3839
}

barcode-scanning/yarn.lock

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@react-native/virtualized-lists@^0.72.4":
6+
version "0.72.8"
7+
resolved "https://registry.yarnpkg.com/@react-native/virtualized-lists/-/virtualized-lists-0.72.8.tgz#a2c6a91ea0f1d40eb5a122fb063daedb92ed1dc3"
8+
integrity sha512-J3Q4Bkuo99k7mu+jPS9gSUSgq+lLRSI/+ahXNwV92XgJ/8UgOTxu2LPwhJnBk/sQKxq7E8WkZBnBiozukQMqrw==
9+
dependencies:
10+
invariant "^2.2.4"
11+
nullthrows "^1.1.1"
12+
13+
"@types/prop-types@*":
14+
version "15.7.7"
15+
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.7.tgz#f9361f7b87fd5d8188b2c998db0a1f47e9fb391a"
16+
integrity sha512-FbtmBWCcSa2J4zL781Zf1p5YUBXQomPEcep9QZCfRfQgTxz3pJWiDFLebohZ9fFntX5ibzOkSsrJ0TEew8cAog==
17+
18+
"@types/react-native@^0.72.3":
19+
version "0.72.3"
20+
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.72.3.tgz#eb5726eb3ec6b79a10db7a295cc0346eb5e9331a"
21+
integrity sha512-9+g+DBJIY3bG7+ZlYzKPr9kxTQxUuZQgLWZhYK4RlIcrsm3qaJhL2PU2e/K4CjnzznWCo2Islgec94x2z1pG4Q==
22+
dependencies:
23+
"@react-native/virtualized-lists" "^0.72.4"
24+
"@types/react" "*"
25+
26+
"@types/react@*":
27+
version "18.2.23"
28+
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.23.tgz#60ad6cf4895e93bed858db0e03bcc4ff97d0410e"
29+
integrity sha512-qHLW6n1q2+7KyBEYnrZpcsAmU/iiCh9WGCKgXvMxx89+TYdJWRjZohVIo9XTcoLhfX3+/hP0Pbulu3bCZQ9PSA==
30+
dependencies:
31+
"@types/prop-types" "*"
32+
"@types/scheduler" "*"
33+
csstype "^3.0.2"
34+
35+
"@types/scheduler@*":
36+
version "0.16.4"
37+
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.4.tgz#fedc3e5b15c26dc18faae96bf1317487cb3658cf"
38+
integrity sha512-2L9ifAGl7wmXwP4v3pN4p2FLhD0O1qsJpvKmNin5VA8+UvNVb447UDaAEV6UdrkA+m/Xs58U1RFps44x6TFsVQ==
39+
40+
csstype@^3.0.2:
41+
version "3.1.2"
42+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
43+
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==
44+
45+
invariant@^2.2.4:
46+
version "2.2.4"
47+
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
48+
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
49+
dependencies:
50+
loose-envify "^1.0.0"
51+
52+
"js-tokens@^3.0.0 || ^4.0.0":
53+
version "4.0.0"
54+
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
55+
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
56+
57+
loose-envify@^1.0.0:
58+
version "1.4.0"
59+
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
60+
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
61+
dependencies:
62+
js-tokens "^3.0.0 || ^4.0.0"
63+
64+
nullthrows@^1.1.1:
65+
version "1.1.1"
66+
resolved "https://registry.yarnpkg.com/nullthrows/-/nullthrows-1.1.1.tgz#7818258843856ae971eae4208ad7d7eb19a431b1"
67+
integrity sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==

0 commit comments

Comments
 (0)