Skip to content
This repository has been archived by the owner on Jan 22, 2023. It is now read-only.

Latest commit

 

History

History
140 lines (103 loc) · 4.14 KB

README.md

File metadata and controls

140 lines (103 loc) · 4.14 KB



ulid


KUlid

Unit test coverage

Support me

ULID (Universally Unique Lexicographically Sortable Identifier) generator and parser for Kotlin.

Refer the ULID spec for a more detailed ULID specification.

Installation

Kotlin DSL

Add the JitPack repository to your build.gradle.kts:

allprojects {
   repositories {
      ...
      maven { url = uri("https://jitpack.io") }
   }
}

Add the dependency to your build.gradle.kts:

dependencies {
    implementation("com.github.guepardoapps:kulid:2.0.0.0")
}

Groovy DSL

Add the JitPack repository to your build.gradle:

allprojects {
   repositories {
      ...
      maven { url 'https://jitpack.io' }
   }
}

Add the dependency to your build.gradle:

dependencies {
    implementation 'com.github.guepardoapps:kulid:2.0.0.0'
}

Usage

ULID generation examples:

val randomUlid = ULID.random()
val generateUlid = ULID.generate(System.currentTimeMillis(), byteArrayOf(0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9))
val stringUlid = ULID.fromString("003JZ9J6G80123456789ABCDEF")

ULID parsing examples:

val ulid = "003JZ9J6G80123456789ABCDEF"
val isValid = ULID.isValid(ulid)        // returns a Boolean indicating if the ULID is valid
val timestamp = ULID.getTimestamp(ulid) // returns a Long
val entropy = ULID.getEntropy(ulid)     // returns a ByteArray

Prior Projects

Requirements

  • Use at least JVM 1.8

Contributors

JonasSchubert
Jonas Schubert

License

KUlid is distributed under the MIT license. See LICENSE for details.

MIT License

Copyright (c) 2019 - 2021 Jonas Schubert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.