Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/javiersegoviacordoba/semantic-versioning-kmp

A Kotlin Multiplatform library to work with semantic versioning
https://github.com/javiersegoviacordoba/semantic-versioning-kmp

hacktoberfest kmp kotlin kotlin-multiplatform semantic semver versioning

Last synced: 4 months ago
JSON representation

A Kotlin Multiplatform library to work with semantic versioning

Awesome Lists containing this project

README

        

![Kotlin version](https://img.shields.io/badge/kotlin-1.8.0-blueviolet?logo=kotlin&logoColor=white)
[![MavenCentral](https://img.shields.io/maven-central/v/com.javiersc.semver/semver-core?label=MavenCentral)](https://repo1.maven.org/maven2/com/javiersc/semver/semver-core/)
[![Snapshot](https://img.shields.io/nexus/s/com.javiersc.semver/semver-core?server=https%3A%2F%2Foss.sonatype.org%2F&label=Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/com/javiersc/semver/semver-core/)

[![Build](https://img.shields.io/github/actions/workflow/status/JavierSegoviaCordoba/semantic-versioning-kmp/build-kotlin.yaml?label=Build&logo=GitHub)](https://github.com/JavierSegoviaCordoba/semantic-versioning-kmp/tree/main)
[![Coverage](https://img.shields.io/sonar/coverage/com.javiersc.semver:semantic-versioning-kmp?label=Coverage&logo=SonarCloud&logoColor=white&server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=com.javiersc.semver:semantic-versioning-kmp)
[![Quality](https://img.shields.io/sonar/quality_gate/com.javiersc.semver:semantic-versioning-kmp?label=Quality&logo=SonarCloud&logoColor=white&server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=com.javiersc.semver:semantic-versioning-kmp)
[![Tech debt](https://img.shields.io/sonar/tech_debt/com.javiersc.semver:semantic-versioning-kmp?label=Tech%20debt&logo=SonarCloud&logoColor=white&server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=com.javiersc.semver:semantic-versioning-kmp)

# SEMANTIC VERSIONING KMP

A Kotlin Multiplatform library to work with semantic versioning

## Download

```kotlin
implementation("com.javiersc.semver:semver-core:$version")
```

## Usage

A Version must match the following format:

```
..-.
```

> `patch` and `stage` can be null.

### Build a `Version`

There are 3 options to build a `Version`.

#### Passing a `version: String`

```kotlin
Version("1.0.0")

Version("1.0.0-alpha.1")

Version("12.23.34-alpha.45")
```

#### Passing a `version: String` and a `stage: String?`

```kotlin
Version("1.0.0", "alpha.1")

Version("12.23.34", "alpha.45")
```

#### Passing all params; `major: Int`, `minor: Int`, `patch: Int?`, `stage: String?`, and `num: Int?`

```kotlin
Version(1, 0, 0)

Version(1, 0, 0, "alpha", 1)

Version(12, 23, 34, "alpha", 45)
```

### Compare two `Version`

```kotlin
Version("1.0.1") > Version("1.0.0") // true

Version("1.0.1") < Version("1.0.0") // false

Version("1.0.0") == Version("1.0.0") // true
```

### Increase a `Version`

```kotlin
Version("2.4.6-alpha.1").inc(Version.Increase.Patch) // 2.4.7 (stage and num are removed)
Version("2.4.6").inc(Version.Increase.Patch) // 2.4.7
Version("2.4.6").inc(Version.Increase.Minor) // 2.5.0 (patch is reset to 0)
Version("2.4.6").inc(Version.Increase.Major) // 3.0.0 (minor and patch are reset to 0)

// minor and patch are reset to 0, stage and num are removed
Version("2.4.6-beta.4").inc(Version.Increase.Major) // 3.0.0
```

### Copy a `Version`

```kotlin
Version("1.1.0-alpha.1").copy(major = 3) // 3.1.0-alpha.1
```