util.id

This module provides randomized strings for use as identifiers. Often you might reach for UUID for this, but sometimes you might want a smaller or more compact representation. That’s where this module comes in! The URL-safe Base64 character set is used.

The exact amount of entropy produced by these functions may be adjusted, do not depend on the exact format.

tiny

Appropriate for avoiding naming conflicts of internally managed and short-lived objects.

id.tiny() --> PuLh

short

Appropriate for generating identifiers for relatively short-lived objects.

id.short() --> f72wMeZO6JfT

medium

Appropriate for globally unique identifiers of objects with long lifetime, as well as secret tokens. Meant to be equivalent but more compact to an UUID.

id.medium() --> 7GnAYG898D453tfZcm8mU5tB

long

Appropriate for very secret tokens, insane overkill for most uses.

id.long() --> 6_MvvkXVpHgMs_oGDuQnjipvSIXIjnd5GH7D

custom

Appropriate for when you just want to have more control over the amount of entropy in the IDs. Takes the number of octets of entropy to procure as argument and returns a function that returns an id with that much entropy.

id.custom(6) --> function () --> z_mXz-fJ