sortVersions
Sorts version strings by version, not by text (1.10.0 after 1.9.0), in the given scheme: the
same as versions.sort((a, b) => compare(a, b, scheme)), without mutating the input. Versions
that compare as equal keep their order. Strings are returned as they were written (a v prefix
stays).
Every version is compared with compare, so in the schemes that throw on invalid input
('gentoo', 'debian', …) a bad version throws a SyntaxError: filter with isValid first.
Available since v3.1.9
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
versions | readonly T[] | The versions to sort |
options | SortVersionsOptions | Order and scheme — see SortVersionsOptions |
Returns
Section titled “Returns”T[] — A new sorted array
Examples
Section titled “Examples”Sort versions, not strings
Section titled “Sort versions, not strings”1.10.0 comes after 1.9.0, which a plain sort() gets wrong.
Find the latest tag
Section titled “Find the latest tag”Newest first; the v prefix of git tags is kept.
Related Types
Section titled “Related Types”SortVersionsOptions
Section titled “SortVersionsOptions”Options for sortVersions.
