Skip to content

luxe API (2025.1.2)


luxe: id module


ID

import "luxe: id" for ID

IDs are useful in many cases, this API provides them in various forms like UUID or unique short strings.


ID.unique() returns String

Returns a unique short string ID for use. These are useful for default generated names, random urls, etc.

Note that these are "unique enough" but has higher risk of collision than a UUID. If you want universally unique IDs that's what UUID is for. (Don't make assumptions about the length of the ID, for fixed length use ID.unique(length: Num)).

Log.print(ID.unique()) //UuIyH
Log.print(ID.unique()) //39sjDw
Log.print(ID.unique()) //28zASZ

ID.unique(length: Num) returns String

Returns a unique short string ID for use. These are useful for default generated names, random urls, etc.

Note that these are "unique enough" but has higher risk of collision than a UUID. If you want universally unique IDs that's what UUID is for.

Log.print(ID.unique(6)) //Uu2IyH
Log.print(ID.unique(8)) //39sjDwl4

ID.index(index: Num) returns String

no docs found

ID.uuid() returns String

Returns a UUID v4 ID. These are unique enough to not worry about collisions (not for cryptography).

Log.print(ID.uuid()) //5606ba0f-968a-4ab7-8230-ba46cdb345da
Log.print(ID.uuid()) //48e3d469-e9fa-4a24-aa22-d653de9af5b2
Log.print(ID.uuid()) //a4861cc5-c2e4-4656-a3a4-176bc63e5d05

ID.uuid(from: String) returns String

Returns a UUID v4 from the given string (treated as bytes). This runs a 128 bit hash (spooky v2) over the string, converting the bits to a uuid string.

Log.print(ID.uuid("hello")) //3768826a-d382-e6ca-5c94-1ed1c71ae043
Log.print(ID.uuid("luxe")) //7281a4a8-abc4-dc50-52ae-7f59626f242a

ID.uuid_validate(uuid: String) returns unknown

Returns true if the given UUID is valid (using regex matching).

Log.print(ID.validate_uuid(ID.uuid())) //true
Log.print(ID.validate_uuid("hello"))   //false

ID.uuid_base62() returns String

Returns a UUID represented as a base62 string.

Log.print(ID.uuid_base62()) //AXiFxIVixJM-EDCrnEHVkWJ

ID.uuid_combine(uuid_a: String, uuid_b: String) returns String

Returns a new UUID by combining the two UUIDs given.

Log.print(ID.uuid_combine(ID.uuid(), ID.uuid())) //5f558462-7525-48c0-812d-a65df074ce42