Skip to content

Commit c53b73b

Browse files
committed
convert JavaScript to TypeScript
1 parent 981f9b7 commit c53b73b

21 files changed

+7981
-514
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/dist
2+
/node_modules

.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.pbxproj -text
2+
Sample/** linguist-vendored
3+
scripts/** linguist-vendored

.gitignore

+17-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23+
ios/.xcode.env.local
2324

2425
# Android/IntelliJ
2526
#
@@ -28,32 +29,38 @@ build/
2829
.gradle
2930
local.properties
3031
*.iml
32+
*.hprof
33+
.cxx/
34+
*.keystore
35+
!debug.keystore
3136

3237
# node.js
3338
#
3439
node_modules/
3540
npm-debug.log
3641
yarn-error.log
3742

38-
# BUCK
39-
buck-out/
40-
\.buckd/
41-
*.keystore
42-
!debug.keystore
43-
4443
# fastlane
4544
#
4645
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
4746
# screenshots whenever they are needed.
4847
# For more information about the recommended setup visit:
4948
# https://docs.fastlane.tools/best-practices/source-control/
5049

51-
*/fastlane/report.xml
52-
*/fastlane/Preview.html
53-
*/fastlane/screenshots
50+
**/fastlane/report.xml
51+
**/fastlane/Preview.html
52+
**/fastlane/screenshots
53+
**/fastlane/test_output
5454

5555
# Bundle artifact
5656
*.jsbundle
5757

58-
# CocoaPods
58+
# Ruby / CocoaPods
5959
/ios/Pods/
60+
/vendor/bundle/
61+
62+
# Temporary files created by Metro to check the health of the file watcher
63+
.metro-health-check*
64+
65+
/dist
66+
!/dist/.gitkeep

.npmignore

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
template/
1+
.vscode/
2+
.github/
3+
.prettierrc.js
4+
.eslintrc.js
5+
yarn.lock
6+
tsconfig.json
7+
babel.config.js
8+
node_modules/
9+
__tests__/
10+
screenshots/
211
Sample/
3-
__tests__
4-
screenshots
5-
.github
12+
src/
13+
scripts/

.prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
arrowParens: 'avoid',
3+
bracketSameLine: true,
4+
bracketSpacing: false,
5+
singleQuote: true,
6+
trailingComma: 'all',
7+
};

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ For more details, see the [Sample Project](https://github.com/douglasjunior/reac
129129
|modalProps|[ModalProps](https://reactnative.dev/docs/modal)||Override the Modal props.|
130130
|webViewProps|[WebViewProps](https://github.com/react-native-webview/react-native-webview/blob/master/docs/Reference.md)||Override the WebView props.|
131131
|lang|`string`||[Language code](https://developers.google.com/recaptcha/docs/language).|
132-
|siteKey|`string`||(Required) Your sitekey.|
133-
|baseUrl|`string`||(Required) The URL (domain) configured in the reCAPTCHA setup. (ex. http://my.domain.com)|
132+
|siteKey|`string`||(Required) Your web reCAPTCHA site key.|
133+
|baseUrl|`string`||(Required) The URL (domain) configured in the reCAPTCHA site key setup. (ex. http://my.domain.com)|
134134
|size|`'invisible'`, `'normal'` or `'compact'`|`'normal'`|The size of the widget.|
135135
|theme|`'dark'` or `'light'`|`'light'`|The color theme of the widget.|
136136
|onLoad|`function()`||A callback function, executed when the reCAPTCHA is ready to use.|
@@ -141,7 +141,7 @@ For more details, see the [Sample Project](https://github.com/douglasjunior/reac
141141
|recaptchaDomain|`string`|`www.google.com`|The host name of the reCAPTCHA valid api. [See detail](https://developers.google.com/recaptcha/docs/faq#can-i-use-recaptcha-globally).|
142142
|gstaticDomain|`string`|`www.gstatic.com`|Customize reCAPTCHA `gstatic` host.|
143143
|hideBadge|`boolean`|`false`|When `size = 'invisible'`, you are allowed to hide the badge as long as you include the reCAPTCHA branding visibly in the user flow. [See detail](https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed).|
144-
|enterprise|`boolean` (enterprise)|`false`| Use the new [reCAPTCHA Enterprise API](https://cloud.google.com/recaptcha-enterprise/docs/using-features).|
144+
|enterprise|`boolean` (enterprise)|`false`|Use the new [reCAPTCHA Enterprise API](https://cloud.google.com/recaptcha-enterprise/docs/using-features).|
145145
|action|`string` (enterprise)|| An [additional parameter](https://cloud.google.com/recaptcha-enterprise/docs/actions) for specifying the action name associated with the protected element for reCAPTCHA Enterprise API.|
146146

147147
Note: If `lang` is not set, then device language is used.

Sample/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from 'react-native';
1111

1212
import {Colors} from 'react-native/Libraries/NewAppScreen';
13-
import Recaptcha, { RecaptchaHandles } from 'react-native-recaptcha-that-works';
13+
import Recaptcha, { RecaptchaRef } from 'react-native-recaptcha-that-works';
1414

1515
const styles = StyleSheet.create({
1616
safeArea: {
@@ -28,7 +28,7 @@ const App = () => {
2828
const size = 'invisible';
2929
const [token, setToken] = useState('<none>');
3030

31-
const $recaptcha = useRef<RecaptchaHandles>(null);
31+
const $recaptcha = useRef<RecaptchaRef | null>(null);
3232

3333
const handleOpenPress = useCallback(() => {
3434
$recaptcha.current?.open();

Sample/install.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/bin/bash
22

3+
unameOut="$(uname -s)"
4+
5+
echo "$unameOut";
6+
37
rm -rf ../node_modules/
48
rm -rf node_modules/
5-
rm -rf ios/Pods/
6-
79
yarn install
8-
9-
unameOut="$(uname -s)"
10+
rm -rf node_modules/react-native-recaptcha-that-works/Sample/
11+
rm -rf node_modules/react-native-recaptcha-that-works/.git/
1012

1113
if [ "$unameOut" == "Darwin" ]; then
1214
cd ios

babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['module:metro-react-native-babel-preset'],
3+
};

index.js

-27
This file was deleted.

package.json

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
{
22
"name": "react-native-recaptcha-that-works",
33
"displayName": "React-Native reCAPTCHA That Works",
4-
"version": "1.3.2",
4+
"version": "2.0.0",
55
"private": false,
66
"license": "MIT",
77
"description": "⚛ A reCAPTCHA bridge for React Native that works.",
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/douglasjunior/react-native-recaptcha-that-works.git"
1111
},
12-
"main": "index.js",
13-
"types": "index.d.ts",
12+
"main": "src",
1413
"keywords": [
1514
"react-native",
1615
"ios",
1716
"android",
18-
"recaptcha"
17+
"recaptcha",
18+
"captcha",
19+
"security",
20+
"webview"
1921
],
2022
"author": {
2123
"name": "Douglas Nassif Roma Junior",
@@ -26,9 +28,32 @@
2628
"url": "https://github.com/douglasjunior/react-native-recaptcha-that-works/issues"
2729
},
2830
"homepage": "https://github.com/douglasjunior/react-native-recaptcha-that-works",
31+
"scripts": {
32+
"build": "tsc",
33+
"publish-script": "node scripts/publish.js"
34+
},
2935
"peerDependencies": {
30-
"react": ">=16.9.0",
31-
"react-native": ">=0.60.0",
32-
"react-native-webview": ">=10.0.0"
36+
"react-native": ">=0.60",
37+
"react-native-webview": ">=10"
38+
},
39+
"devDependencies": {
40+
"@babel/core": "^7.20.0",
41+
"@babel/preset-env": "^7.20.0",
42+
"@babel/runtime": "^7.20.0",
43+
"@react-native-community/eslint-config": "^3.2.0",
44+
"@tsconfig/react-native": "^2.0.2",
45+
"@types/jest": "^29.2.1",
46+
"@types/react": "^18.0.24",
47+
"@types/react-test-renderer": "^18.0.0",
48+
"babel-jest": "^29.2.1",
49+
"eslint": "^8.19.0",
50+
"jest": "^29.2.1",
51+
"metro-react-native-babel-preset": "0.73.8",
52+
"prettier": "^2.4.1",
53+
"react": "18.2.0",
54+
"react-native": "0.71.4",
55+
"react-native-webview": "13.3.1",
56+
"react-test-renderer": "18.2.0",
57+
"typescript": "4.8.4"
3358
}
3459
}

scripts/publish.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const child_process = require('child_process');
4+
5+
const packageJson = require('../package.json');
6+
7+
packageJson.main = 'dist';
8+
packageJson.types = 'dist';
9+
10+
const packageJsonPath = path.resolve(__dirname, '..', 'package.json');
11+
12+
const content = JSON.stringify(packageJson, null, 2) + '\n';
13+
14+
child_process.execSync('npm run build');
15+
16+
fs.writeFileSync(packageJsonPath, content, {
17+
encoding: 'utf-8',
18+
});
19+
20+
try {
21+
child_process.execSync('npm publish');
22+
} catch (err) {
23+
console.error(err);
24+
}
25+
26+
child_process.execSync('git checkout -- "' + packageJsonPath + '"');

0 commit comments

Comments
 (0)