solo-studios / Strata

A library for parsing and comparing version strings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strata

Build Status MIT license Maven Central 100% Java Discord Server

A simple, dependency-less, library for parsing and comparing version according to the SemVer spec

Features

  • Can parse any valid SemVer version.
  • Has no external dependencies other than JetBrains Annotations to help document the public API.
  • Very fast. Can parse 1 million versions in under 5 seconds. (2.1 seconds on my cpu, a Ryzen 5 3600.) At that level, speed is insignificant, unless you have a really weird usecase where you need to parse hundreds of thousands of versions a second.
  • Simple to use API.
  • Includes a set of Kotlin extensions to make development in kotlin easier and more idiomatic.

Including

Builds can be found on Maven Central, and can be included with any build tool that supports maven.

<dependency>
  <groupId>ca.solo-studios</groupId>
  <artifactId>strata</artifactId>
  <version>1.3.0</version>
</dependency>

The kotlin extensions can be included as follows:

<dependency>
  <groupId>ca.solo-studios</groupId>
  <artifactId>strata-kotlin</artifactId>
  <version>1.3.0</version>
</dependency>

Gradle Groovy DSL

implementation 'ca.solo-studios:strata:1.3.0'

The kotlin extensions can be included as follows:

implementation 'ca.solo-studios:strata-kotlin:1.3.0'

Gradle Kotlin DSL

implementation("ca.solo-studios:strata:1.3.0")

The kotlin extensions can be included as follows:

implementation("ca.solo-studios:strata-kotlin:1.3.0")

Examples

Note: version parsing may throw a ParseException, which you are expeted to handle. This is thrown if ever the provided version is incorrect.

Getting a version

try {
    Version version = Versions.parseVersion("1.2.3");
} catch (ParseException e) {
    // handle version parse exception
}

or

val version = "1.2.3".toVersion()

Getting a version range

try {
    VersionRange range = Versions.parseVersionRange("[1.2.3,4.5.6)");
} catch (ParseException e) {
    // handle invalid version range parse exception
}

or

val range = "[1.2.3,4.5.6)".toVersionRange()

Checking if a version is within a version range

Version version = [...]

VersionRange range = [...]

if (range.isSatisfiedBy(version)) {
    // version is within range
} else {
    // version is outside range
}

or

val version = [...]

val range = [...]

if (version in range)
    // version is within range
else
    // version is outside range

About

A library for parsing and comparing version strings

License:MIT License


Languages

Language:Java 94.4%Language:Kotlin 5.6%