Skip to content

Commit

Permalink
fix: add strict input check allowing only byte arrays as inputs (#87) (
Browse files Browse the repository at this point in the history
…#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`.
  • Loading branch information
runk authored Sep 28, 2023
1 parent 9d030da commit 91f310f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# chardet

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

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

In browser, you can use [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) instead of the `Buffer`:

```javascript
import chardet from 'chardet';
chardet.analyse(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
```

## Working with large data sets

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

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

```javascript
chardet
.detectFile('/path/to/file', { sampleSize: 32, offset: 128 })
.then(encoding => console.log(encoding));
.then((encoding) => console.log(encoding));
```

## Supported Encodings:
Expand Down

0 comments on commit 91f310f

Please sign in to comment.