NPM.Tree (NPM v0.6.0)

Copy Markdown View Source

Formats and renders dependency trees for display.

Provides npm ls style tree output from lockfile data.

Summary

Functions

Builds a tree structure from a lockfile and root dependencies.

Counts total packages in the tree (including nested).

Filters the tree to only show packages matching a pattern.

Flattens a tree to a list of all packages with their depths.

Formats a dependency tree as a string.

Returns the maximum depth of the tree.

Functions

build(lockfile, root_deps)

@spec build(map(), map()) :: map()

Builds a tree structure from a lockfile and root dependencies.

Returns a nested map representing the dependency tree.

count(tree)

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

Counts total packages in the tree (including nested).

filter(tree, pattern)

@spec filter(map(), String.t()) :: map()

Filters the tree to only show packages matching a pattern.

flatten(tree, depth \\ 0)

@spec flatten(map(), non_neg_integer()) :: [
  {String.t(), String.t(), non_neg_integer()}
]

Flattens a tree to a list of all packages with their depths.

format(tree)

@spec format(map()) :: String.t()

Formats a dependency tree as a string.

max_depth(tree)

@spec max_depth(map()) :: non_neg_integer()

Returns the maximum depth of the tree.