Whisq v0.1.0-alpha.9
randomId()
Generate a UUID-v4-shaped random identifier — a string like "3f5d2c1b-9a4e-4b87-bf1a-7c2d8e3f9a01". The canonical default for keyed-each row keys, todo id fields, and any other “I just need a stable unique string” use case.
Shipped from the sub-path @whisq/core/ids, not the main entry. Since alpha.8.
Signature
Section titled “Signature”import { randomId } from "@whisq/core/ids";
function randomId(): string;Example
Section titled “Example”import { signal } from "@whisq/core";import { randomId } from "@whisq/core/ids";
interface Todo { id: string; text: string; done: boolean }
const todos = signal<Todo[]>([]);
const addTodo = (text: string) => { todos.value = [...todos.value, { id: randomId(), text, done: false }];};How it works
Section titled “How it works”- Prefers
crypto.randomUUID()when the platform provides it — all modern browsers, Node 19+, Deno, Bun. - Falls back to a
Math.randomsynthesis for older targets (pre-19 Node, old Safari). Same v4 shape (xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxxwherey ∈ {8, 9, a, b}), but with weaker entropy. - Same output shape on both paths, so callers don’t have to branch on platform.
Not a security primitive
Section titled “Not a security primitive”Why a sub-path?
Section titled “Why a sub-path?”@whisq/core/ids lives on its own sub-path so apps that don’t generate ids client-side (e.g. an SSR app where the server hands out ids) pay no bundle cost. Same convention as /persistence, /forms, and /collections.
See also: /api/imports/#ids, Todo App example.
Docs current to v0.1.0-alpha.9 . All releases →