Skip to content

A generator library for concise, unambiguous and URL-safe UUIDs

License

Notifications You must be signed in to change notification settings

hsingh/java-shortuuid

Repository files navigation

java-shortuuid

Build Status

A generator library for concise, unambiguous and URL-safe UUIDs

A Java library that generates concise, unambiguous, URL-safe UUIDs. Based on and compatible with the Python library shortuuid. Inspired by the Go implementation.

Often, one needs to use non-sequential IDs in places where users will see them, but the IDs must be as concise and easy to use as possible. shortuuid solves this problem by generating UUIDs using and then translating them to base57 using lowercase and uppercase letters and digits, and removing similar-looking characters such as l, 1, I, O and 0.

Usage

public String shortUuid() {
    ShortUuid.Builder builder = new ShortUuid.Builder();
    ShortUuid shortUuid = builder.build(UUID.randomUUID());
    
    return shortUuid.toString();
}

public UUID getUuid(String shortUuid) {
    ShortUuid.Builder builder = new ShortUuid.Builder();
 
    return UUID.fromString(builder.decode(shortUuid));
}

License

MIT

About

A generator library for concise, unambiguous and URL-safe UUIDs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages