Skip to content
喵喵大人 edited this page Dec 3, 2019 · 2 revisions

Bucket version parser

This is Bucket's implementation of Semver version (main) and Calendar version control, and provides additional constraints on this basis And verified support.

Feature

  • Semantic version: support based on Semver semantic version implementation
  • Calendar Version: also compatible with Calendar Calendar version support
  • Standard version: (major, minor, patch, revision) parsing support (for Microsoft rules)
  • Version Constrainer: Allows to establish a version constraint and get whether the versions match
  • Stability Control: Allows to establish minimum version stability (Minimum Stability) version control
  • Major Version Wildcard: Added support for Tilde (^) and Caret (~)
  • AND/OR: For version matching, it allows complex version constraints established by AND (AND) or (OR)
  • Special Version: In addition to the regular version, it is allowed to use branch names starting with dev- as special branch constraints.
  • Wild Version: Allows you to use - to link different version ranges, and to build wild versions via *.

Basic usage

Comparator
  • GreaterThan(a, b)
  • GreaterThanOrEqual(a, b)
  • LessThan(a, b)
  • LessThanOrEqual(a, b)
  • Equal(a, b)
  • NotEqual(a, b)
Comparator.GreaterThan("1.5.0", "1.2.0"); // 1.5.0 > 1.2.0 = true
  • Compare(a, operator, b)

The valid comparison operators are:==, <, <=, >, >=, !=

Comparator.Compare("1.5.0", ">=", "1.2.0"); // 1.5.0 >= 1.2.0 = true
Semver

The Satisfies matching function allows you to use semantic-version for matching satisfaction.

  • Satisfies(version, constraints)
Semver.Satisfies("1.0", "^1.5"); // false
Semver.Satisfies("1.6", "^1.5"); // true

With SatisfiesBy you can match an array of versions, and the function returns the versions that match the conditions:

  • SatisfiesBy(versions, constraints)
Semver.SatisfiesBy(new[]{ "1.1", "1.6", "1.8" }, "^1.5"); // new[] { "1.6", "1.8" }

With Sort, you can sort a set of versions. The second parameter determines whether to sort from large to small.

  • Sort(versions, desc)
Semver.Sort(new[] { "1.1", "1.8", "1.3", "0.6", "2.1" }); // new[] { "0.6", "1.1", "1.3", "1.8", "2.1" }
Semver.Sort(new[] { "1.1", "1.8", "1.3", "0.6", "2.1" }, true); // new[] { "2.1", "1.8", "1.3", "1.1", "0.6" }

VersionParser

VersionParser can build complex semantic-version

  • ParseStability(version)
VersionParser.ParseStability("1.2.0-beta"); // Extracting stability flags:beta
  • ParseConstraints(version)
var versionParser = new VersionParser();
var constraint = versionParser.ParseConstraints("^1.2");
constraint.Matches(new Constraint("=", "1.5")); // true
Clone this wiki locally