Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext IOS UUID Generator

From Leeroopedia
Knowledge Sources
Domains UUID, iOS
Last Updated 2026-10-24 00:00 GMT

Overview

UUID v4 generator for the iOS app, using the Web Crypto API with a Math.random fallback to produce RFC 4122-compliant UUID strings.

Description

The uuid.js module in src-ios/utils/ implements a single generateStableId function that generates a UUID v4 string. It uses globalThis.crypto.getRandomValues when available (secure random), falling back to Math.random for older environments. The variant and version bits are set according to RFC 4122 (version 4, variant 10xx). The bytes are converted to hex and formatted as xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx.

Usage

Import this function wherever a unique stable identifier is needed — document creation, idea entry IDs, and database stable_id backfilling.

Code Reference

Source Location

Signature

function generateStableId() // → string (UUID v4)
function randomBytes(length) // → Uint8Array
function bytesToHex(bytes) // → string

Import

const { generateStableId } = require('./utils/uuid');

I/O Contract

Inputs

Name Type Required Description
(none) — — No parameters

Outputs

Name Type Description
generateStableId string RFC 4122 UUID v4 string

Usage Examples

Generating Stable IDs

const { generateStableId } = require('./utils/uuid');

// Generate a new stable_id for a document
const stableId = generateStableId();
console.log(stableId); // "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"

// Used in createDoc
const doc = await createDoc({
  title: 'My Note',
  content: '# Content',
  stable_id: generateStableId()
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment