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: about 1 month ago
JSON representation
A Kotlin Multiplatform library to work with semantic versioning
- Host: GitHub
- URL: https://github.com/javiersegoviacordoba/semantic-versioning-kmp
- Owner: JavierSegoviaCordoba
- Created: 2021-06-25T17:45:26.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-25T13:13:13.000Z (2 months ago)
- Last Synced: 2025-03-17T05:05:00.761Z (about 1 month ago)
- Topics: hacktoberfest, kmp, kotlin, kotlin-multiplatform, semantic, semver, versioning
- Language: Kotlin
- Homepage: https://semantic-versioning-kmp.javiersc.com
- Size: 8.54 MB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README

[](https://repo1.maven.org/maven2/com/javiersc/semver/semver-core/)
[](https://oss.sonatype.org/content/repositories/snapshots/com/javiersc/semver/semver-core/)[](https://github.com/JavierSegoviaCordoba/semantic-versioning-kmp/tree/main)
[](https://sonarcloud.io/dashboard?id=com.javiersc.semver:semantic-versioning-kmp)
[](https://sonarcloud.io/dashboard?id=com.javiersc.semver:semantic-versioning-kmp)
[](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") // trueVersion("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
```