Skip to content

Commit 9f147ee

Browse files
committed
feat: improve java usage
feat: lower jvmTarget to 17 docs: update README chore: bump version to 1.0.1
1 parent ff086e1 commit 9f147ee

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Nano ID for Kotlin
22

33
<a href="https://github.com/viascom/nanoid-kotlin/releases"><img src="https://img.shields.io/maven-central/v/io.viascom.nanoid/nanoid" alt="Maven central"></a>
4-
<img src="https://img.shields.io/badge/Kotlin-1.9.20-%238052ff?logo=kotlin" alt="Kotlin Version">
4+
<img src="https://img.shields.io/badge/Kotlin-1.9.22-%238052ff?logo=kotlin" alt="Kotlin Version">
5+
<img src="https://img.shields.io/badge/Java-17-%23437291?logo=openjdk" alt="Java Version">
56
<a href="http://www.apache.org/licenses/"><img src="https://img.shields.io/badge/license-Apache_2.0-blue.svg" alt="license Apache 2.0"></a>
67

78
_Inspired by the following parent project: [ai/nanoid](https://github.com/ai/nanoid)_
@@ -25,7 +26,7 @@ Add nanoid-kotlin as a dependency to your project.
2526
Gradle:
2627
```gradle
2728
dependencies {
28-
implementation 'io.viascom.nanoid:nanoid:1.0.0'
29+
implementation 'io.viascom.nanoid:nanoid:1.0.1'
2930
}
3031
```
3132

@@ -34,7 +35,7 @@ Maven:
3435
<dependency>
3536
<groupId>io.viascom.nanoid</groupId>
3637
<artifactId>nanoid</artifactId>
37-
<version>1.0.0</version>
38+
<version>1.0.1</version>
3839
</dependency>
3940
```
4041

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
ext {
1212
major = 1
1313
minor = 0
14-
patch = 0
14+
patch = 1
1515

1616
isCiServer = System.getenv("GITHUB_ACTIONS") != null || System.getProperty("GITHUB_ACTIONS") != null
1717
}
@@ -33,6 +33,9 @@ jar {
3333
java {
3434
withSourcesJar()
3535
withJavadocJar()
36+
toolchain {
37+
languageVersion.set(JavaLanguageVersion.of(17))
38+
}
3639
}
3740

3841
repositories {
@@ -45,7 +48,7 @@ dependencies {
4548
}
4649

4750
tasks.withType(KotlinCompile).configureEach {
48-
kotlinOptions.jvmTarget = JavaVersion.VERSION_19
51+
kotlinOptions.jvmTarget = JavaVersion.VERSION_17
4952
kotlinOptions.freeCompilerArgs = ["-Xjvm-default=all"]
5053
}
5154

src/main/kotlin/io/viascom/nanoid/NanoId.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ object NanoId {
5151
* @throws IllegalArgumentException if the alphabet is empty or larger than 255 characters, or if the size is not greater than zero.
5252
*/
5353
@JvmOverloads
54+
@JvmStatic
5455
fun generate(
5556
@NotNull
5657
size: Int = 21,
@@ -84,6 +85,7 @@ object NanoId {
8485
* @return The generated optimized string.
8586
*/
8687
@JvmOverloads
88+
@JvmStatic
8789
fun generateOptimized(@NotNull size: Int, @NotNull alphabet: String, @NotNull mask: Int, @NotNull step: Int, @NotNull random: Random = SecureRandom()): String {
8890
val idBuilder = StringBuilder(size)
8991
val bytes = ByteArray(step)
@@ -107,6 +109,7 @@ object NanoId {
107109
* @param alphabet The set of characters to use for generating the string.
108110
* @return The additional bytes factor, rounded to two decimal places.
109111
*/
112+
@JvmStatic
110113
fun calculateAdditionalBytesFactor(@NotNull alphabet: String): Double {
111114
val mask = calculateMask(alphabet)
112115
return (1 + abs((mask - alphabet.length.toDouble()) / alphabet.length)).round(2)
@@ -118,6 +121,7 @@ object NanoId {
118121
* @param alphabet The set of characters to use for generating the string.
119122
* @return The calculated mask value.
120123
*/
124+
@JvmStatic
121125
fun calculateMask(@NotNull alphabet: String) = (2 shl (Integer.SIZE - 1 - Integer.numberOfLeadingZeros(alphabet.length - 1))) - 1
122126

123127
/**
@@ -128,6 +132,7 @@ object NanoId {
128132
* @param additionalBytesFactor The additional bytes factor. Default value is calculated using `calculateAdditionalBytesFactor()`.
129133
* @return The number of random bytes to generate in each iteration.
130134
*/
135+
@JvmStatic
131136
@JvmOverloads
132137
fun calculateStep(@NotNull size: Int, @NotNull alphabet: String, @NotNull additionalBytesFactor: Double = calculateAdditionalBytesFactor(alphabet)) =
133138
ceil(additionalBytesFactor * calculateMask(alphabet) * size / alphabet.length).toInt()

0 commit comments

Comments
 (0)