You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Semver4k** is a lightweight Kotlin Multiplatform library that helps you handling versions. It follows the rules of the [semantic versioning](http://semver.org) specification and provides several versioning modes: strict, NPM, CocoaPods...
6
4
7
-
**Semver4k** is a lightweight Java library that helps you handling versions. It follows the rules of the [semantic versioning](http://semver.org) specification and provides several versioning modes: strict, NPM, CocoaPods...
5
+
This library is a frok of [semver4j](https://github.com/vdurmont/semver4j) completly rewritten in kotlin.
6
+
7
+
Supported Kotlin Multiplatform targets:
8
+
* jvm
9
+
* ios
8
10
9
11
## Installation
10
12
@@ -14,16 +16,16 @@ Add the dependency to your project:
14
16
15
17
```xml
16
18
<dependency>
17
-
<groupId>com.vdurmont</groupId>
19
+
<groupId>de.voize</groupId>
18
20
<artifactId>semver4k</artifactId>
19
-
<version>3.1.0</version>
21
+
<version>4.0.0</version>
20
22
</dependency>
21
23
```
22
24
23
25
#### Using gradle
24
26
25
-
```xml
26
-
compile 'com.vdurmont:semver4j:3.1.0'
27
+
```kotlin
28
+
implementation("de.voize:semver4j:4.0.0")
27
29
```
28
30
29
31
## Usage
@@ -42,9 +44,9 @@ In Semver4j, a version looks like: `1.2.3-beta.4+sha899d8g79f87`.
42
44
43
45
You can create a version by using one of the 2 constructors:
44
46
45
-
```java
46
-
Semver sem1 =newSemver("1.2.3-beta.4+sha899d8g79f87");// Defaults to STRICT mode
47
-
Semver sem2 =newSemver("1.2.3-beta.4+sha899d8g79f87", SemverType.NPM);// Specify the mode
47
+
```kotlin
48
+
val sem1 =Semver("1.2.3-beta.4+sha899d8g79f87") // Defaults to STRICT mode
49
+
val sem2 =Semver("1.2.3-beta.4+sha899d8g79f87", SemverType.NPM) // Specify the mode
48
50
```
49
51
50
52
If the version is invalid, a `SemverException` will be thrown.
@@ -65,65 +67,65 @@ A version is stable if its major number is _strictly_ positive and it has no suf
-`isGreaterThan` returns true if the version is strictly greater than the other one.
82
84
83
-
```java
84
-
Semver sem =newSemver("1.2.3");
85
-
sem.isGreaterThan("1.2.2");// true
86
-
sem.isGreaterThan("1.2.4");// false
87
-
sem.isGreaterThan("1.2.3");// false
85
+
```kotlin
86
+
val sem =Semver("1.2.3")
87
+
sem.isGreaterThan("1.2.2") // true
88
+
sem.isGreaterThan("1.2.4") // false
89
+
sem.isGreaterThan("1.2.3") // false
88
90
```
89
91
90
92
-`isLowerThan` returns true if the version is strictly lower than the other one.
91
93
92
-
```java
93
-
Semver sem =newSemver("1.2.3");
94
-
sem.isLowerThan("1.2.2");// false
95
-
sem.isLowerThan("1.2.4");// true
96
-
sem.isLowerThan("1.2.3");// false
94
+
```kotlin
95
+
val sem =Semver("1.2.3")
96
+
sem.isLowerThan("1.2.2") // false
97
+
sem.isLowerThan("1.2.4") // true
98
+
sem.isLowerThan("1.2.3") // false
97
99
```
98
100
99
101
-`isEqualTo` returns true if the versions are exactly the same.
100
102
101
-
```java
102
-
Semver sem =newSemver("1.2.3+sha123456789");
103
-
sem.isEqualTo("1.2.3+sha123456789");// true
104
-
sem.isEqualTo("1.2.3+shaABCDEFGHI");// false
103
+
```kotin
104
+
val sem = Semver("1.2.3+sha123456789")
105
+
sem.isEqualTo("1.2.3+sha123456789") // true
106
+
sem.isEqualTo("1.2.3+shaABCDEFGHI") // false
105
107
```
106
108
107
109
-`isEquivalentTo` returns true if the versions are the same (does not take the build information into account).
108
110
109
-
```java
110
-
Semver sem =newSemver("1.2.3+sha123456789");
111
-
sem.isEquivalentTo("1.2.3+sha123456789");// true
112
-
sem.isEquivalentTo("1.2.3+shaABCDEFGHI");// true
111
+
```kotlin
112
+
val sem =Semver("1.2.3+sha123456789")
113
+
sem.isEquivalentTo("1.2.3+sha123456789") // true
114
+
sem.isEquivalentTo("1.2.3+shaABCDEFGHI") // true
113
115
```
114
116
115
117
### Versions diffs
116
118
117
119
If you want to know what is the main difference between 2 versions, use the `diff` method. It will return a `VersionDiff` enum value among: `NONE`, `MAJOR`, `MINOR`, `PATCH`, `SUFFIX`, `BUILD`. It will always return the biggest difference.
118
120
119
-
```java
120
-
Semver sem =newSemver("1.2.3-beta.4+sha899d8g79f87");
121
-
sem.diff("1.2.3-beta.4+sha899d8g79f87");// NONE
122
-
sem.diff("2.3.4-alpha.5+sha32iddfu987");// MAJOR
123
-
sem.diff("1.3.4-alpha.5+sha32iddfu987");// MINOR
124
-
sem.diff("1.2.4-alpha.5+sha32iddfu987");// PATCH
125
-
sem.diff("1.2.3-alpha.5+sha32iddfu987");// SUFFIX
126
-
sem.diff("1.2.3-beta.4+sha32iddfu987");// BUILD
121
+
```kotlin
122
+
val sem =Semver("1.2.3-beta.4+sha899d8g79f87")
123
+
sem.diff("1.2.3-beta.4+sha899d8g79f87") // NONE
124
+
sem.diff("2.3.4-alpha.5+sha32iddfu987") // MAJOR
125
+
sem.diff("1.3.4-alpha.5+sha32iddfu987") // MINOR
126
+
sem.diff("1.2.4-alpha.5+sha32iddfu987") // PATCH
127
+
sem.diff("1.2.3-alpha.5+sha32iddfu987") // SUFFIX
128
+
sem.diff("1.2.3-beta.4+sha32iddfu987") // BUILD
127
129
```
128
130
129
131
### Requirements
@@ -133,33 +135,33 @@ If you want to check if a version satisfies a requirement, use the `satisfies` m
133
135
- In `STRICT` and `LOOSE` modes, the requirement can only be another version.
134
136
- In `NPM` mode, the requirement follows [NPM versioning rules](https://github.com/npm/node-semver).
0 commit comments