Range

a version requirement: a disjunction (logical OR) of ComparatorSets, of the kind found in package manifests. Parse one with from-string and test membership with satisfies?.

Supported syntax (a practical subset of the npm/node-semver grammar):

  • comparators: >=1.2.3, >1.2.3, <=1.2.3, <1.2.3, =1.2.3
  • an exact version: 1.2.3 (equivalent to =1.2.3)
  • caret ranges: ^1.2.3 (compatible up to the next non-zero component)
  • tilde ranges: ~1.2.3 (patch-level changes within the minor)
  • x-ranges and partials: 1.2.x, 1.2.*, 1.x, 1, *
  • hyphen ranges: 1.2.3 - 2.3.4 (inclusive on both ends)
  • whitespace joins comparators with AND; || joins sets with OR

A leading v (as in v1.2.3) is accepted and ignored.

copy

instantiate

(Fn [(Ref Range a)] Range)

copies a Range.

delete

instantiate

(Fn [Range] ())

deletes a Range. Should usually not be called manually.

from-string

defn

(Fn [(Ref String a)] (Maybe Range))

                        (from-string s)
                    

parses a range string such as ^1.2.3, >=1.0.0 <2.0.0, or 1.2.x || 2.0.0 into a Range. Returns Nothing when the string is malformed. The empty string and * both parse to the universal range that every version satisfies.

init

instantiate

(Fn [(Array ComparatorSet)] Range)

creates a Range.

max-satisfying

defn

(Fn [(Ref Range a), (Ref (Array Semver) a)] (Maybe Semver))

                        (max-satisfying r versions)
                    

returns the highest-precedence version in versions that satisfies the range r, or Nothing when none of them do. This is the version a dependency resolver picks for r.

min-satisfying

defn

(Fn [(Ref Range a), (Ref (Array Semver) a)] (Maybe Semver))

                        (min-satisfying r versions)
                    

returns the lowest-precedence version in versions that satisfies the range r, or Nothing when none of them do.

prn

instantiate

(Fn [(Ref Range a)] String)

converts a Range to a string.

satisfies?

defn

(Fn [(Ref Range a), (Ref Semver a)] Bool)

                        (satisfies? r v)
                    

returns whether the version v satisfies the range r.

Comparisons follow SemVer 2.0.0 precedence. Following node-semver's default, a pre-release version (e.g. 1.2.3-beta) satisfies the range only when some comparator explicitly names a pre-release at the same major.minor.patch.

satisfying

defn

(Fn [(Ref Range a), (Ref (Array Semver) a)] (Array Semver))

                        (satisfying r versions)
                    

returns every version in versions that satisfies the range r, sorted ascending by SemVer precedence. The result is empty when none match; its last element, when present, is the version max-satisfying returns, and its first the version min-satisfying returns.

set-sets

instantiate

(Fn [Range, (Array ComparatorSet)] Range)

sets the sets property of a Range.

set-sets!

instantiate

(Fn [(Ref Range a), (Array ComparatorSet)] ())

sets the sets property of a Range in place.

sets

instantiate

(Fn [(Ref Range a)] (Ref (Array ComparatorSet) a))

gets the sets property of a Range.

str

defn

(Fn [(Ref Range a)] String)

                        (str r)
                    

renders a range back to string form; comparator sets are joined by ||. The output is normalized and may differ from the parsed input.

update-sets

instantiate

(Fn [Range, (Ref (Fn [(Array ComparatorSet)] (Array ComparatorSet) a) b)] Range)

updates the sets property of a Range using a function f.