Skip to content

Guid Global Unique Identifier Generator

Function List

guid(length?, firstU?, radix?) => string

Generates a global unique identifier that can be used for scenarios where a unique string is needed, such as element ids or class names.

Parameters

Parameter NameTypeRequiredDefaultDescription
lengthnumber | nullNo32The length of the guid. Pass null to generate according to the rfc4122 standard
firstUbooleanNotrueWhether the first character is "u", to ensure it can be used as an id or class
radixnumberNo62The base to generate, determining the range of available characters

Return Value

TypeDescription
stringA globally unique random string

Examples

typescript
import { guid } from '@hy-app/ui';

const elId = guid(20);
const elClass = guid();

console.log(elId); // 20-digit random string
console.log(elClass); // 32-digit random string