NPM.SemverUtil (NPM v0.6.0)

Copy Markdown View Source

Utility functions for working with npm semver ranges.

Provides higher-level operations that build on NPMSemver.matches?/2 for common npm workflows like finding the best matching version, filtering compatible versions, and determining update targets.

Summary

Functions

Check if any version in the list satisfies the range.

Filter a list of versions to only those satisfying a range.

Find the highest version from a list that satisfies a range.

Find the lowest version from a list that satisfies a range.

Determine the type of update between two versions.

Functions

any_satisfying?(versions, range)

@spec any_satisfying?([String.t()], String.t()) :: boolean()

Check if any version in the list satisfies the range.

filter(versions, range)

@spec filter([String.t()], String.t()) :: [String.t()]

Filter a list of versions to only those satisfying a range.

max_satisfying(versions, range)

@spec max_satisfying([String.t()], String.t()) :: {:ok, String.t()} | :none

Find the highest version from a list that satisfies a range.

Returns {:ok, version} or :none.

min_satisfying(versions, range)

@spec min_satisfying([String.t()], String.t()) :: {:ok, String.t()} | :none

Find the lowest version from a list that satisfies a range.

update_type(from, to)

@spec update_type(String.t(), String.t()) ::
  :major | :minor | :patch | :prerelease | :none

Determine the type of update between two versions.

Returns :major, :minor, :patch, or :prerelease.