Skip to content

Commit 91f310f

Browse files
authored
fix: add strict input check allowing only byte arrays as inputs (#87) (#88)
BREAKING CHANGE From this release, only instances of Array with numeric values <= 255 are accepted as inputs. No strings or anything else except shapes like `Buffer` or `Uint8Array`.
1 parent 9d030da commit 91f310f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# chardet
22

3-
*Chardet* is a character detection module written in pure JavaScript (TypeScript). Module uses occurrence analysis to determine the most probable encoding.
3+
_Chardet_ is a character detection module written in pure JavaScript (TypeScript). Module uses occurrence analysis to determine the most probable encoding.
44

55
- Packed size is only **22 KB**
66
- Works in all environments: Node / Browser / Native
@@ -42,10 +42,17 @@ Returned value is an array of objects sorted by confidence value in descending o
4242
```javascript
4343
[
4444
{ confidence: 90, name: 'UTF-8' },
45-
{ confidence: 20, name: 'windows-1252', lang: 'fr' }
45+
{ confidence: 20, name: 'windows-1252', lang: 'fr' },
4646
];
4747
```
4848

49+
In browser, you can use [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) instead of the `Buffer`:
50+
51+
```javascript
52+
import chardet from 'chardet';
53+
chardet.analyse(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
54+
```
55+
4956
## Working with large data sets
5057

5158
Sometimes, when data set is huge and you want to optimize performance (with a tradeoff of less accuracy),
@@ -54,15 +61,15 @@ you can sample only the first N bytes of the buffer:
5461
```javascript
5562
chardet
5663
.detectFile('/path/to/file', { sampleSize: 32 })
57-
.then(encoding => console.log(encoding));
64+
.then((encoding) => console.log(encoding));
5865
```
5966

6067
You can also specify where to begin reading from in the buffer:
6168

6269
```javascript
6370
chardet
6471
.detectFile('/path/to/file', { sampleSize: 32, offset: 128 })
65-
.then(encoding => console.log(encoding));
72+
.then((encoding) => console.log(encoding));
6673
```
6774

6875
## Supported Encodings:

0 commit comments

Comments
 (0)