Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 1.17 KB

README.md

File metadata and controls

29 lines (19 loc) · 1.17 KB

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