function uuid() {
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
return crypto.randomUUID();
}
// Fallback (not cryptographically secure)
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
});
}
// Usage
console.log(uuid()); // e.g. '3b1c9a4f-d82e-4c3b-a7f1-2e9d5b6f8c0e'
Create a free account and build your private vault. Share publicly whenever you want.