NPM.VersionUtil (NPM v0.6.0)

Copy Markdown View Source

Utilities for npm version string manipulation.

Helpers for parsing, comparing, and formatting npm version strings that go beyond what Elixir's Version module handles.

Summary

Functions

Increment the major version (resets minor and patch to 0).

Increment the minor version (resets patch to 0).

Increment the patch version.

Compare two version strings.

Check if version a is greater than version b.

Get the latest (highest) version from a list.

Check if version a is less than version b.

Get the major version number from a version string.

Get the minor version number from a version string.

Parse a version string into {major, minor, patch} tuple.

Check if a version is a prerelease (has a pre tag).

Sort a list of version strings.

Functions

bump_major(version)

@spec bump_major(String.t()) :: String.t() | :error

Increment the major version (resets minor and patch to 0).

bump_minor(version)

@spec bump_minor(String.t()) :: String.t() | :error

Increment the minor version (resets patch to 0).

bump_patch(version)

@spec bump_patch(String.t()) :: String.t() | :error

Increment the patch version.

compare(a, b)

@spec compare(String.t(), String.t()) :: :gt | :eq | :lt

Compare two version strings.

Returns :gt, :eq, or :lt.

gt?(a, b)

@spec gt?(String.t(), String.t()) :: boolean()

Check if version a is greater than version b.

latest(versions)

@spec latest([String.t()]) :: String.t() | nil

Get the latest (highest) version from a list.

lt?(a, b)

@spec lt?(String.t(), String.t()) :: boolean()

Check if version a is less than version b.

major(version)

@spec major(String.t()) :: non_neg_integer() | :error

Get the major version number from a version string.

minor(version)

@spec minor(String.t()) :: non_neg_integer() | :error

Get the minor version number from a version string.

parse_triple(version)

@spec parse_triple(String.t()) ::
  {:ok, {non_neg_integer(), non_neg_integer(), non_neg_integer()}} | :error

Parse a version string into {major, minor, patch} tuple.

Returns :error for invalid versions.

prerelease?(version)

@spec prerelease?(String.t()) :: boolean()

Check if a version is a prerelease (has a pre tag).

sort(versions)

@spec sort([String.t()]) :: [String.t()]

Sort a list of version strings.