You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-10Lines changed: 75 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,26 +33,83 @@ Feel free to test the functionality of this NPM package [here](https://encoding-
33
33
*[Known Issues](#known-issues)
34
34
*[License](#license)
35
35
36
-
## Usage (Javascript)
36
+
## Usage
37
+
There are several ways in which you can use this NPM package. You can use it as a command-line interface (create a link), server-side with Node.js (create a link) or client-side in the browser (create a link).
37
38
38
-
### Installation
39
-
```bash
40
-
$ npm install detect-file-encoding-and-language
39
+
### In the browser
40
+
In the body section of your html file, create an input element of type `file` and give it an id.
41
+
42
+
```js
43
+
// index.html
44
+
<body>
45
+
<input type="file" id="my-input-field"/>
46
+
<script src="app.js"></script>
47
+
</body>
41
48
```
42
49
43
-
### In the browser
50
+
Next, load the module either via a `<script>` tag (create a link) or by using bundler (create a link)!
51
+
52
+
#### Via a `<script>` tag
53
+
When loading it via the `<script>` tag, you can either use the CDN version (create a link) or download the code itself and include it in your project (create a link). The easiest and fastest to start with is using the CDN version (create a link). If you want to be able to use it offline, download and include it (create a link)!
> Note: This should work fine with frameworks such as React but if you're using pure vanilla Javascript make sure to use a bundler such as Browserify!
86
+
##### Usage (Javascript)
87
+
The `<script>` tag exposes the `languageEncoding` function to everything in the DOM that's beneath it. You should have no trouble accessing it in `app.js` by calling the languageEncoding function and passing in the file that you want to analyze as the argument. As you can see in the example below, languageEncoding returns a Promise that you can use to get the encoding, language and confidenc score.
Note: This works great with frameworks such as React because they are doing the bundling for you. However, if you're using pure vanilla Javascript you will have to bundle it yourself!
0 commit comments