NPM.Size (NPM v0.6.0)

Copy Markdown View Source

Estimates install size and disk usage per package.

Analyzes node_modules to report per-package and total sizes, helping identify heavy dependencies.

Summary

Functions

Analyzes a node_modules directory and returns size info per package.

Formats a size in bytes as a human-readable string.

Returns a summary of the node_modules analysis.

Returns the top N largest packages.

Calculates total file count.

Calculates total install size across all packages.

Types

size_entry()

@type size_entry() :: %{
  name: String.t(),
  version: String.t() | nil,
  size: non_neg_integer(),
  file_count: non_neg_integer()
}

Functions

analyze(node_modules_dir)

@spec analyze(String.t()) :: [size_entry()]

Analyzes a node_modules directory and returns size info per package.

format_size(bytes)

@spec format_size(non_neg_integer()) :: String.t()

Formats a size in bytes as a human-readable string.

summary(entries)

@spec summary([size_entry()]) :: %{
  package_count: non_neg_integer(),
  total_size: non_neg_integer(),
  total_files: non_neg_integer(),
  formatted_size: String.t()
}

Returns a summary of the node_modules analysis.

top(node_modules_dir, n \\ 10)

@spec top(String.t(), non_neg_integer()) :: [size_entry()]

Returns the top N largest packages.

total_files(entries)

@spec total_files([size_entry()]) :: non_neg_integer()

Calculates total file count.

total_size(entries)

@spec total_size([size_entry()]) :: non_neg_integer()

Calculates total install size across all packages.