https://github.com/elide-dev/uuid
Kotlin Multiplatform UUID
https://github.com/elide-dev/uuid
elide elide-runtime kotlin kotlin-multiplatform
Last synced: 2 months ago
JSON representation
Kotlin Multiplatform UUID
- Host: GitHub
- URL: https://github.com/elide-dev/uuid
- Owner: elide-dev
- License: mit
- Created: 2023-04-29T02:14:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-28T16:58:35.000Z (3 months ago)
- Last Synced: 2025-04-01T17:53:42.490Z (3 months ago)
- Topics: elide, elide-runtime, kotlin, kotlin-multiplatform
- Language: Kotlin
- Homepage: https://elide.dev
- Size: 3.13 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# `elide-uuid`
[](https://search.maven.org/artifact/dev.elide/elide-uuid)
[](https://github.com/elide-dev/uuid/actions/workflows/push.yml)
[](http://kotlinlang.org)
[](http://kotlinlang.org)
[](https://kotl.in/jsirsupported)
[](CODE_OF_CONDUCT.md)
[](https://sonarcloud.io/summary/new_code?id=elide-dev_uuid)
[](https://sonarcloud.io/summary/new_code?id=elide-dev_uuid)
[](https://sonarcloud.io/summary/new_code?id=elide-dev_uuid)
[](https://sonarcloud.io/summary/new_code?id=elide-dev_uuid)
[](https://sonarcloud.io/summary/new_code?id=elide-dev_uuid)
[](https://app.fossa.com/projects/git%2Bgithub.com%2Felide-dev%2Fuuid?ref=badge_shield)
[](https://bestpractices.coreinfrastructure.org/projects/7689)K/N UUID. This brings a UUID that matches UUIDs on various platforms:
- iOS/Mac: `NSUUID`
- Java: `java.util.UUID`
- Native: Source implementation### Features
- Adheres to RFC4122
- Support for `uuid3`, `uuid4`, and `uuid5`
- Frozen and thread-safe (thread-safe randomness in native)
- Tested on all platforms, and against macOS/iOS UUID to verify correctness
- Aggressively optimized for performance and safety
- Updated for new versions of Kotlin
- Zero dependencies (only `stdlib`)
- 🆕 All Kotlin targets, including WASM/WASI and Android/Native
- 🆕 Serializable on JVM
- 🆕 Serializable with KotlinX
- 🆕 Zero-overhead model### Setup
**In your `build.gradle(.kts)`:**
```kotlin
dependencies {
implementation("dev.elide:elide-uuid:")
}
```**From an Elide application:**
```kotlin
dependencies {
implementation(elide.uuid)
}
```**To enable KotlinX Serialization support:**
```kotlin
dependencies {
implementation("dev.elide:elide-uuid-kotlinx:")
}
```### Usage
From any Kotlin source set:
```kotlin
val uuid = uuid4()
println(uuid.toString())
// 1b4e28ba-2fa1-11d2-883f-0016d3cca427
```When KotlinX Serialization support is included:
```kotlin
@Serializable data class Sample(
@Serializable(with = UUIDSerializer::class) val uuid: Uuid,
)val sample = Sample(uuid = uuid4())
println(Json.encodeToString(Sample.serializer(), uuid.toString()))
// {"uuid": "1b4e28ba-2fa1-11d2-883f-0016d3cca427"}
```#### "Zero-overhead" abstraction
This library is designed to offer a compile-time option for dealing with UUIDs; internally, UUIDs are stored as a simple
`Pair` to minimize allocations, and the main `Uuid` class is a `@JvmInline value class`.Thus, your UUIDs are strictly typed and validated but also remain very lightweight.
The main UUID library uses exactly zero dependencies, and even omits a `stdlib` dependency by default. You must bring
your own before shipping a target with this library.#### Serialization
Both JVM serialization and KotlinX serialization are supported out of the box.
### Contributing
Contributions are welcome! Once you file a PR, a bot will as you to sign the CLA (_Contributor License Agreement_) and to sign off your commits to establish your DCO
(_Developer Certificate of Origin_).Checks run automatically on each PR. Review is requested automatically once your PR goes from draft to open.
### Additional checks
[](https://sonarcloud.io/summary/new_code?id=elide-dev_uuid)
[](https://app.fossa.com/projects/git%2Bgithub.com%2Felide-dev%2Fuuid?ref=badge_large)
#### This is a fork
Ben Asher's original library is [here](https://github.com/benasher44/uuid.git).
#### About Elide
This library is part of a larger polyglot framework and runtime called [Elide](https://github.com/elide-dev). You can learn more about Elide at [`elide.dev`](https://elide.dev).