semver
Semantic Versioning 2.0.0: parse, compare, sort and match version ranges. Pure - no capabilities.
ecko get github.com/ecko-lang/semver
import semver
Pure computation: it declares no capabilities, so it cannot touch the network, the filesystem or the environment.
Version 0.37.0 - source - MIT.
identifiers(s, numeric_matters, what)
Split a pre-release or build string on dots, checking each identifier. Numeric pre-release identifiers become ints so they compare numerically; build identifiers stay text, since build metadata is never compared.
identifier(p, numeric_matters, what)
One identifier from a dot-separated list.
parse(text)
parse("1.2.3-rc.1+build.5") -> { major, minor, patch, prerelease, build }. Raises { kind: "semver" } for anything that is not a valid version.
valid(text)
Is text a valid version? The total form of parse.
string_of(p)
Render a parsed version back to text, build metadata included.
compare(a, b)
compare(a, b) -> -1, 0 or 1. Accepts text or already-parsed versions. Build metadata is ignored, exactly as the spec requires (§10).
sort(versions)
Ascending order by precedence.
sort_with takes the comparator directly. sort_by could not express this: a pre-release list mixes numeric and alphanumeric identifiers whose ordering depends on their types, which is not a value any key function can return.
eq(a, b)
a == b by precedence, ignoring build metadata.
gt(a, b)
a > b by precedence.
lt(a, b)
a < b by precedence.
inc(text, part)
inc("1.2.3", "minor") -> "1.3.0". Bumping drops any pre-release and build metadata: they described the version being left behind, not the new one.
parse_range(text)
Expand a range string into alternatives, each a list of comparators. { op, version }, where op is one of >= > <= < =.
comparators(alt)
One alternative: whitespace-separated terms, each expanded to comparators.
satisfies(version, range)
satisfies("1.5.0", "^1.2.3") -> true.
A pre-release only ever matches a range that mentions one at the same major.minor.patch. Without that rule ^1.0.0 would quietly accept 2.0.0-alpha, which is the behaviour every package ecosystem regrets.
max_satisfying(versions, range)
The highest version in versions that satisfies range, or null.
min_satisfying(versions, range)
The lowest version in versions that satisfies range, or null.