# Fixing problems and getting explanations

## Ode to a Shipping Label

A [poem about mojibake](https://imgur.com/4J7Il0m), whose original author might
be [Carlos Bueno on Facebook](https://www.facebook.com/cmb/posts/619241744770551:0),
shows a shipping label addressed to
`L&AMP;AMP;ATILDE;&AMP;AMP;SUP3;PEZ`.

![A package addressed to a mojibake surname](images/shipping-label.png)

ftfy can fix the label and explain the transformations:

```ts
import { apply_plan, fix_and_explain } from "ftfy-js";

const shippingLabel = "L&AMP;AMP;ATILDE;&AMP;AMP;SUP3;PEZ";
const [fixed, explanation] = fix_and_explain(shippingLabel);

fixed;
// "LóPEZ"

explanation;
// [
//   ["apply", "unescape_html"],
//   ["apply", "unescape_html"],
//   ["apply", "unescape_html"],
//   ["encode", "latin-1"],
//   ["decode", "utf-8"],
// ]

apply_plan("CARR&AMP;AMP;ATILDE;&AMP;AMP;COPY;", explanation ?? []);
// "CARRé"
```

The capitalization is inconsistent because a lowercase `ó` is encoded in the
source even though the rest was printed in capital letters.

## Functions that fix text

`fix_text(text, config?)` applies every enabled fix independently to each line.
It is normally the function to use.

`fix_and_explain(text, config?)` processes the input as one segment and returns
both the fixed text and a plan. The result supports both tuple destructuring and
the `.text` / `.explanation` properties.

`fix_encoding_and_explain(text, config?)` only fixes problems solved through
encoding and decoding, including its subordinate byte fixes. Its counterpart
`fix_encoding(text, config?)` returns only the string.

`fix_text_segment(text, config?)` applies the complete fixer pipeline to one
segment but discards the explanation.

`apply_plan(text, plan)` replays `encode`, `decode`, `transcode`, and `apply`
steps using only the functions recognized by ftfy.

## Showing characters in a string

`explain_unicode(text)` prints each code point's hexadecimal value, glyph or
escape, Unicode general category, and Unicode name:

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

explain_unicode("(╯°□°)╯︵ ┻━┻");
```

The package ships the pinned Python reference environment's Unicode names and
categories so this helper does not depend on a platform-specific JS table.
