Module: services/winget/version

Comparing versions with winget's version comparator.

See https://github.com/microsoft/winget-cli/blob/ae566c7bf21cfcc75be7ec30e4036a30eede8396/src/AppInstallerSharedLib/Versions.cpp for original implementation.

Source:

Methods

(inner) compareVersion(v1, v2) → {number}

Compares two strings representing version numbers lexicographically and returns an integer value.

Parameters:
Name Type Description
v1 string

The first version to compare

v2 string

The second version to compare

Source:
Returns:

-1 if v1 is smaller than v2, 1 if v1 is larger than v2, 0 if v1 and v2 are equal

Type
number
Example
compareVersion('1.2.3', '1.2.4') // returns -1 because numeric part of first version is smaller than the numeric part of second version.

(inner) compareVersionPart(part1, part2) → {number}

Compares two strings representing version number parts lexicographically and returns an integer value.

Parameters:
Name Type Description
part1 string

The first version part to compare

part2 string

The second version part to compare

Source:
Returns:

-1 if part1 is smaller than part2, 1 if part1 is larger than part2, 0 if part1 and part2 are equal

Type
number
Example
compareVersionPart('3', '4') // returns -1 because numeric part of first part is smaller than the numeric part of second part.

(inner) latest(versions) → {string|undefined}

Finds the largest version number lexicographically from an array of strings representing version numbers and returns it as a string.

Parameters:
Name Type Description
versions Array.<string>

The array of version numbers to compare

Source:
Returns:

The largest version number as a string, or undefined if the array is empty

Type
string | undefined
Example
latest(['1.2.3', '1.2.4', '1.3', '2.0']) // returns '2.0' because it is the largest version number.
latest(['1.2.3', '1.2.4', '1.3-alpha', '2.0-beta']) // returns '2.0-beta'. there is no special handling for pre-release versions.

(inner) trimLastZeros(parts)

Removes all trailing zeros from a version number part array.

Parameters:
Name Type Description
parts Array.<string>

parts

Source:

(inner) trimPrefix(version) → {string}

Removes all leading non-digit characters from a version number string if there is a digit before the split character, or no split characters exist.

Parameters:
Name Type Description
version string

The version number string to trim

Source:
Returns:

The version number string with all leading non-digit characters removed

Type
string