Reference · General
uuid
uuid() -> strWhat it does
A new version 4 UUID as text: 36 characters, lower-case hex in five groups of 8, 4, 4,
4 and 12, with a 4 at the start of the third group. Its bytes come from the operating
system, so it can serve as a session id, a token or a file name that cannot be guessed,
which random cannot.
Examples
let u = uuid()print(type_of(u), len(u))print(split(u, "-") | map(len))print(re.test(u, "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"))str 36[8, 4, 4, 4, 12]trueEdge cases
- Each call is a new id: a thousand in a row are a thousand different strings.
- Lower case:
u == lower(u); upper-case it for a display that wants that. - Without its dashes it is 32 hex characters.
uuid()takes no arguments; one given is a runtime error (below).
print(range(1000) | map((i) => uuid()) | unique | len)let u = uuid()print(u == lower(u), len(replace(u, "-", "")), slice(u, 14, 15))1000true 32 4Errors
uuid never gives an error value. It is a runtime error only when the operating system
gives no random bytes, which does not happen on a working machine.
print(is_err(uuid()))falseAn argument is a runtime error, and so is one for quillo check when the call is
written out.
print(uuid(1))line 1: `uuid` takes 0 arguments, got 1: uuid()Chaining
uuid starts a pipeline rather than taking one, since it has no argument.
print(uuid() | upper | len)print(`photos/${uuid()}.jpg` | ends_with(".jpg"))36trueserver fn add_photo(file: map) = save_upload(file, `photos/${uuid()}.jpg`)See also
random, random_int, crypto.token, save_upload
Thread 0 posts
On uuid(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo