Generate a Version 1 (Time-based) UUID
masterUnderstanding the internal data flow can help when debugging or extending the library.
UUID v4 Generation Flow
- RNG: Get the Random Number Generator (default or custom).
- Bytes: Generate 16 random bytes.
- Version Bits: Set version bits (
010in thetime_hi_and_versionfield). - Variant Bits: Set variant bits (
10in theclock_seq_hi_and_reservedfield). - Stringify: Convert bytes to hex and format as
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx.
UUID v5 (Name-based) Flow
- Parse: Parse the namespace UUID into bytes.
- Combine: Combine namespace bytes with the name string.
- Hash: Hash the combined data using SHA1.
- Stringify: Call
stringify()withversion=5andvariant=10bits set.
import { version } from 'react-native-uuid';
const id = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';
const v = version(id);
console.log(v); // 4