luxe: id
import "luxe: id" for IDIDs are useful in many cases, this API provides them in various forms like UUID or unique short strings.
ID.unique(.)
Section titled “ID.unique(.)”ID.unique() : StringReturns 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()) //UuIyHLog.print(ID.unique()) //39sjDwLog.print(ID.unique()) //28zASZ
ID.unique(.)
Section titled “ID.unique(.)”ID.unique(length : Num) : StringReturns 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)) //Uu2IyHLog.print(ID.unique(8)) //39sjDwl4
ID.index(.)
Section titled “ID.index(.)”ID.index(index : Num) : Stringno docs found
ID.uuid(.)
Section titled “ID.uuid(.)”ID.uuid() : StringReturns a UUID v4 ID. These are unique enough to not worry about collisions (not for cryptography).
Log.print(ID.uuid()) //5606ba0f-968a-4ab7-8230-ba46cdb345daLog.print(ID.uuid()) //48e3d469-e9fa-4a24-aa22-d653de9af5b2Log.print(ID.uuid()) //a4861cc5-c2e4-4656-a3a4-176bc63e5d05
ID.uuid(.)
Section titled “ID.uuid(.)”ID.uuid(from : String) : StringReturns 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-1ed1c71ae043Log.print(ID.uuid("luxe")) //7281a4a8-abc4-dc50-52ae-7f59626f242a
ID.uuid_validate(.)
Section titled “ID.uuid_validate(.)”ID.uuid_validate(uuid : String) : unknownReturns true if the given UUID is valid (using regex matching).
Log.print(ID.validate_uuid(ID.uuid())) //trueLog.print(ID.validate_uuid("hello")) //false
ID.uuid_base62(.)
Section titled “ID.uuid_base62(.)”ID.uuid_base62() : StringReturns a UUID represented as a base62 string.
Log.print(ID.uuid_base62()) //AXiFxIVixJM-EDCrnEHVkWJ
ID.uuid_combine(..)
Section titled “ID.uuid_combine(..)”ID.uuid_combine(uuid_a : String, uuid_b : String) : StringReturns a new UUID by combining the two UUIDs given.
Log.print(ID.uuid_combine(ID.uuid(), ID.uuid())) //5f558462-7525-48c0-812d-a65df074ce42