Skip to main content

@rtorcato/js-common / uuid

uuid

Functions

getUUIDv7()

getUUIDv7(): string

Defined in: uuid/index.ts:23

Generates a UUID v7 string (time-ordered). UUID v7 embeds a Unix timestamp, making them sortable and ideal for database primary keys.

Example

getUUIDv7() // '018e5e2c-7c0a-7000-8000-0e02b2c3d479'

Returns

string

A new UUID v7 string.


getShortUUID()

getShortUUID(): string

Defined in: uuid/index.ts:36

Generates a short UUID string using short-uuid.

Example

getShortUUID() // 'mhvXdrZT4jP5T8vBxuvm75'

Returns

string

A new short UUID string.


toShortUUID()

toShortUUID(uuid): string

Defined in: uuid/index.ts:50

Converts a standard UUID to a short UUID.

Example

toShortUUID('f47ac10b-58cc-4372-a567-0e02b2c3d479') // 'mhvXdrZT4jP5T8vBxuvm75'

Parameters

uuid

string

The standard UUID string.

Returns

string

The short UUID string.


fromShortUUID()

fromShortUUID(short): string

Defined in: uuid/index.ts:64

Converts a short UUID back to a standard UUID.

Example

fromShortUUID('mhvXdrZT4jP5T8vBxuvm75') // 'f47ac10b-58cc-4372-a567-0e02b2c3d479'

Parameters

short

string

The short UUID string.

Returns

string

The standard UUID string.


isUUID()

isUUID(id): boolean

Defined in: uuid/index.ts:73

Checks if a string is a valid UUID (any version).

Parameters

id

string

The string to validate.

Returns

boolean

True if valid UUID, false otherwise.


isUUIDv4()

isUUIDv4(id): boolean

Defined in: uuid/index.ts:80

Checks if a string is a valid UUID v4.

Parameters

id

string

The string to validate.

Returns

boolean

True if valid UUID v4, false otherwise.


isNilUUID()

isNilUUID(id): boolean

Defined in: uuid/index.ts:93

Checks if a UUID is the nil UUID (all zeros).

Example

isNilUUID('00000000-0000-0000-0000-000000000000') // true
isNilUUID('f47ac10b-58cc-4372-a567-0e02b2c3d479') // false

Parameters

id

string

The UUID string to check.

Returns

boolean

True if nil UUID, false otherwise.


getUUIDVersion()

getUUIDVersion(id): number

Defined in: uuid/index.ts:108

Gets the version number of a UUID.

Example

getUUIDVersion('f47ac10b-58cc-4372-a567-0e02b2c3d479') // 4
getUUIDVersion('018e5e2c-7c0a-7000-8000-0e02b2c3d479') // 7
getUUIDVersion('00000000-0000-0000-0000-000000000000') // 0

Parameters

id

string

The UUID string.

Returns

number

The UUID version (1, 4, 7, etc.), or 0 for nil UUID.

Throws

If the UUID is invalid.


getNilUUID()

getNilUUID(): string

Defined in: uuid/index.ts:119

Returns the nil UUID (all zeros).

Returns

string

The nil UUID string.


uuidToBytes()

uuidToBytes(id): Uint8Array

Defined in: uuid/index.ts:126

Converts a UUID string to a byte array (Uint8Array).

Parameters

id

string

The UUID string.

Returns

Uint8Array

The byte array representation of the UUID.


bytesToUUID()

bytesToUUID(bytes): string

Defined in: uuid/index.ts:133

Converts a byte array (Uint8Array) to a UUID string.

Parameters

bytes

Uint8Array

The byte array.

Returns

string

The UUID string.