# `Beancount.Normalizer`
[🔗](https://github.com/thanos/beancount_ex/blob/v0.6.0/lib/beancount/normalizer.ex#L1)

Normalizes raw engine output into a stable, engine-independent structure.

Normalization is what makes Beancount usable as an *oracle*: two different
engines (the CLI today, a native engine tomorrow) can be compared on their
normalized output rather than on incidental, backend-specific text such as
temporary file paths.

The normalized map has the shape:

    %{
      status: :ok | :error,
      errors: [%{line: non_neg_integer() | nil, message: String.t()}]
    }

# `error`

```elixir
@type error() :: %{line: non_neg_integer() | nil, message: String.t()}
```

# `t`

```elixir
@type t() :: %{status: Beancount.Result.status(), errors: [error()]}
```

# `normalize`

```elixir
@spec normalize(non_neg_integer() | nil, binary(), binary(), binary() | nil) :: t()
```

Normalize captured `stdout`/`stderr` for a given exit status.

`source_path`, when provided, is stripped from error lines so that the
normalized output does not depend on temporary file locations and stays
deterministic.

## Examples

    iex> Beancount.Normalizer.normalize(0, "", "")
    %{status: :ok, errors: []}

    iex> Beancount.Normalizer.normalize(1, "", "/tmp/x.bean:3: Invalid")
    %{status: :error, errors: [%{line: 3, message: "Invalid"}]}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
