# Is ftfy an encoding detector?

No. It is a mojibake detector and fixer. That is easier because correct-looking
text can remain unchanged instead of having an encoding guessed for everything.

Input to `fix_text` should be Unicode text that has already been decoded as
correctly as possible. A string may be valid UTF-8-decoded JavaScript text and
still literally contain mojibake such as `rÃ©flexion`; ftfy repairs that second
layer.

## If byte encoding truly must be guessed

`guess_bytes(bytes)` is available for the same unfortunate cases covered by
upstream. It uses strong signals, not probabilistic language detection:

1. UTF-16 with a byte-order mark
2. UTF-8 or UTF-8 variants
3. MacRoman when CR line endings appear without LF
4. sloppy Windows-1252 as the fallback

```ts
import { guess_bytes } from "ftfy-js";

const { text, encoding } = guess_bytes(bytes);
```

This cannot solve every encoding and does not detect legacy CJK encodings such
as Shift-JIS or Big5. It may create Unicode problems when its guess is wrong.
