Comparator
toStr : Comparator -> Str
Render a comparator to a string.
wildcardComparator = Wildcard (MajorMinor 1 5) expect toStr wildcardComparator == "1.5.*" relationComparator = Relation { operator: GreaterThan, version: Major 2 } expect toStr relationComparator == ">2"
parse : Str -> Result Comparator InvalidComparatorError
Parse a comparator from a string.
This fails if there is any leftover text after the string. Use the parseLazy
twin function if you want to get the leftover text after parsing.
comparator = parse ">=1.2" expect comparator == Ok (Relation { operator: GreaterThanOrEqualTo, version: MajorMinor 1 2 })
parseLazy : Str -> Result Comparator InvalidComparatorError
Parse a comparator from a string, returning the leftover text after parsing on success.
If you don't need the leftover text, use the parse
twin function.
comparator = parseLazy ">=1.2 abc" expect comparator == Ok ( Relation { operator: GreaterThanOrEqualTo, version: MajorMinor 1 2 }), " abc", )
accepts : Comparator, Semver -> Bool
Whether a semver satisfies the constraint of a comparator.
note: you should not use this method directly, as there are some checks
done by VersionReq.matches
not done here.
There are two types of comparator:
- Wildcard: these check that the specified segments of the comparator match the semver, and all other segments are ignored.
- Relation: these check that the specified segments of the comparator hold the relation specified by the operator.
comparator = Relation { operator: LessThan, version: MajorMinor 1 3 } version = { major: 1, minor: 2, patch: 10, preRelease: [], build: [] } expect comparator |> matches version
preReleaseIsCompatible : Comparator, Semver -> Bool
Checks if a semver has a non-empty pre-release and matches all of its version segments.