Modules@robinpath/uuid
uuid

@robinpath/uuid

0.1.1Node.jsPublic

UUID generation, parsing, and validation utilities (v4, v5, nil)

UUID

UUID generation, parsing, and validation utilities (v4, v5, nil)

Package: @robinpath/uuid | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the uuid module when you need to:

  • Generate a random UUID v4 -- Use uuid.v4 to perform this operation
  • Generate a deterministic UUID v5 from a name and namespace UUID using SHA-1 -- Use uuid.v5 to perform this operation
  • Check whether a string is a valid UUID format -- Use uuid.isValid to perform this operation
  • Extract the version number from a UUID string -- Use uuid.version to perform this operation
  • Parse a UUID into its component parts (version, variant, time, bytes) -- Use uuid.parse to perform this operation

Quick Reference

FunctionDescriptionReturns
v4Generate a random UUID v4A random UUID v4 string
v5Generate a deterministic UUID v5 from a name and namespace UUID using SHA-1A deterministic UUID v5 string
isValidCheck whether a string is a valid UUID formatTrue if the string matches the UUID pattern
versionExtract the version number from a UUID stringThe UUID version number (1-5)
parseParse a UUID into its component parts (version, variant, time, bytes)An object with version, variant, time (null for non-v1), and bytes (hex string of 16 bytes)
generateGenerate one or more random UUID v4 stringsAn array of random UUID v4 strings
nilReturn the nil UUID (all zeros)The nil UUID "00000000-0000-0000-0000-000000000000"

Functions

v4

Generate a random UUID v4

Module: uuid | Returns: string -- A random UUID v4 string

uuid.v4
ParameterTypeRequiredDescription
(none)NoCall with no arguments

v5

Generate a deterministic UUID v5 from a name and namespace UUID using SHA-1

Module: uuid | Returns: string -- A deterministic UUID v5 string

uuid.v5 "hello" "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
ParameterTypeRequiredDescription
namestringYesThe name to hash into the UUID
namespacestringYesThe namespace UUID (e.g. a well-known DNS or URL namespace)

isValid

Check whether a string is a valid UUID format

Module: uuid | Returns: boolean -- True if the string matches the UUID pattern

uuid.isValid "550e8400-e29b-41d4-a716-446655440000"
ParameterTypeRequiredDescription
valuestringYesThe string to validate

version

Extract the version number from a UUID string

Module: uuid | Returns: number -- The UUID version number (1-5)

uuid.version "550e8400-e29b-41d4-a716-446655440000"
ParameterTypeRequiredDescription
uuidstringYesA valid UUID string

parse

Parse a UUID into its component parts (version, variant, time, bytes)

Module: uuid | Returns: object -- An object with version, variant, time (null for non-v1), and bytes (hex string of 16 bytes)

uuid.parse "550e8400-e29b-41d4-a716-446655440000"
ParameterTypeRequiredDescription
uuidstringYesA valid UUID string

generate

Generate one or more random UUID v4 strings

Module: uuid | Returns: array -- An array of random UUID v4 strings

uuid.generate 5
ParameterTypeRequiredDescription
countnumberNoThe number of UUIDs to generate (default 1)

nil

Return the nil UUID (all zeros)

Module: uuid | Returns: string -- The nil UUID "00000000-0000-0000-0000-000000000000"

uuid.nil
ParameterTypeRequiredDescription
(none)NoCall with no arguments

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Invalid namespace UUID: ${namespace}Check the error message for details
Invalid UUID: ${value}Check the error message for details
@desc "V4 and validate result"
do
  set $result as uuid.v4
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step UUID workflow

Chain multiple uuid operations together.

@desc "V4, v5, and more"
do
  set $r_v4 as uuid.v4
  set $r_v5 as uuid.v5 "hello" "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
  set $r_isValid as uuid.isValid "550e8400-e29b-41d4-a716-446655440000"
  print "All operations complete"
enddo

2. Safe v4 with validation

Check results before proceeding.

@desc "V4 and validate result"
do
  set $result as uuid.v4
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/uuid

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size4.4 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities