Skip to content

Commit 3742acd

Browse files
authored
Update README.md
1 parent 983dff3 commit 3742acd

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

README.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,27 @@ npm install detect-file-encoding-and-language
4141
</body>
4242

4343
// app.js
44-
document.getElementById("my-input-field").addEventListener("change", inputHandler);
45-
function inputHandler(e) {
44+
document.getElementById("my-input-field").addEventListener("change", (e) => {
4645
const file = e.target.files[0];
4746
languageEncoding(file).then((fileInfo) => console.log(fileInfo));
4847
// Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } }
49-
}
48+
});
5049
```
5150

5251
If you don't want to use a CDN feel free to [download the source code](https://github.com/gignupg/Detect-File-Encoding-and-Language/wiki/Downloading-the-Source-Code)!
5352

5453
### In React
5554

5655
```js
57-
// index.html
58-
<body>
59-
<input type="file" id="my-input-field" />
60-
<script src="app.js"></script>
61-
</body>
62-
63-
// app.js
56+
// App.js
6457
import languageEncoding from "detect-file-encoding-and-language";
65-
document.getElementById("my-input-field").addEventListener("change", inputHandler);
66-
function inputHandler(e) {
67-
const file = e.target.files[0];
68-
languageEncoding(file).then((fileInfo) => console.log(fileInfo));
69-
// Possible result: { language: french, encoding: CP1252, confidence: { encoding: 1, language: 0.97 } }
58+
export default function App() {
59+
function inputHandler(e) {
60+
const file = e.target.files[0];
61+
languageEncoding(file).then((fileInfo) => console.log(fileInfo));
62+
// Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } }
63+
}
64+
return <input type="file" onChange={inputHandler} />;
7065
}
7166
```
7267

0 commit comments

Comments
 (0)