# `NPM.Dependency.Dedupe`
[🔗](https://github.com/elixir-volt/npm_ex/blob/v0.7.4/lib/npm/dependency/dedupe.ex#L1)

Analyzes and deduplicates npm dependency trees.

Finds packages that appear multiple times in the lockfile (or could
be hoisted) and suggests which duplicates can be removed. This is the
logic behind `mix npm.dedupe`.

# `best_shared_version`

```elixir
@spec best_shared_version(String.t(), map()) :: {:ok, String.t()} | :no_common_version
```

Finds the best version of a package that satisfies all dependents.

Given a package name and a lockfile, looks at all packages that depend
on it and finds a version (if any) that satisfies all their ranges.

# `count`

```elixir
@spec count(map()) :: non_neg_integer()
```

Counts package groups installed at multiple versions.

# `find`

```elixir
@spec find(map()) :: [%{name: String.t(), versions: [String.t()]}]
```

Finds packages installed at multiple versions.

Returns maps with the base package name and sorted distinct versions.

# `find_duplicates`

```elixir
@spec find_duplicates(map()) :: [{String.t(), [String.t()]}]
```

Finds packages in the lockfile that could potentially be deduped.

Returns a list of `{name, versions}` where `versions` is a list of
version strings for packages that appear in multiple forms.

# `format_report`

```elixir
@spec format_report([%{name: String.t(), versions: [String.t()]}]) :: String.t()
```

Formats duplicate report for display.

# `potential_savings`

```elixir
@spec potential_savings([%{name: String.t(), versions: [String.t()]}]) ::
  non_neg_integer()
```

Returns the number of extra package versions that dedupe could remove.

# `savings_estimate`

```elixir
@spec savings_estimate(map()) :: %{
  packages: non_neg_integer(),
  duplicates: non_neg_integer()
}
```

Calculates how many bytes could be saved by deduplication.

This is an estimate based on the number of duplicate package entries.

# `summary`

```elixir
@spec summary(map()) :: %{
  total_packages: non_neg_integer(),
  unique_packages: non_neg_integer(),
  duplicate_groups: non_neg_integer(),
  saveable: non_neg_integer()
}
```

Returns a summary of the deduplication analysis.

---

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