Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Guid

Hierarchy

  • Guid

Index

Constructors

  • new Guid(str?: string): Guid
  • Creates a new Guid object using a string, if no string is provided (or the string is not valid), the Guid value will be initialized with all zeroes (empty Guid).

    Parameters

    • Optional str: string

      is the string to use to initialize the Guid object. If its not valid an empty GUID string will be used.

    Returns Guid

Properties

DASH: "-" = '-'
DASH_REGEXP: RegExp = ...
contentInt?: number
contentStr?: string
MAX_UINT_8: 255 = 255
emptyStr: "00000000-0000-0000-0000-000000000000" = '00000000-0000-0000-0000-000000000000'
patternV4: RegExp = ...

Methods

  • equals(otherGuid: Guid): boolean
  • Checks if the current Guid object is equal to the provided one.

    Parameters

    • otherGuid: Guid

      represents the Guid object to compare to this one.

    Returns boolean

    true if this object value is equal to the provided one.

  • getNumberFromGuidString(): number
  • Attempts to get the number GUID value for the current object.

    Returns number

    the hex number representing the Guid value or -1 if its value cannot be parsed.

  • isEmpty(): boolean
  • Checks if the current internal value is empty (all zeroes value).

    Returns boolean

    true if the object has an empty value.

  • isValid(): boolean
  • Checks if the current internal value is a valid v4 GUID.

    Returns boolean

    true if its a valid v4 GUID value.

  • toNumber(): number
  • Returns the object value as number.

    Returns number

    the hex number representing the Guid value.

  • toString(): string
  • Returns the object value as string.

    Returns string

    the string representing the Guid value.

  • Returns a new Guid object with an all zeroes internal value.

    Returns Guid

    new Guid object with an internal value with all zeroes (an empty GUID, non valid).

  • generate(generator?: Crypto): string
  • Generates a string with a valid GUID v4 value from a custom Crypto object or the defaults.

    Parameters

    • Optional generator: Crypto

    Returns string

    a valid GUID v4 value as a string.

  • generateRandomBytes(generator?: Crypto): Uint8Array
  • Generates an Uint8Array with 16 random values generated using the crypto object provided or the defaults.

    Parameters

    • Optional generator: Crypto

      is the Crypto implementation to use instead of the defaults.

    Returns Uint8Array

    an Uint8Array with 16 random values.

  • getCryptoImplementation(): undefined | Crypto
  • Returns the Crypto object that implements the Crypto API from the browser.

    Returns undefined | Crypto

    Crypto object from the browser implementation.

  • getCryptoRandomBytes(crypto: Crypto): Uint8Array
  • Generates an Uint8Array with 16 random values generated using the crypto object provided.

    Parameters

    • crypto: Crypto

      is the Crypto implementation to use to generate the random values to fill the array.

    Returns Uint8Array

    an Uint8Array with 16 random values.

  • getRandomBytes(): Uint8Array
  • Generates an Uint8Array with 16 random values generated using the Math.random() method.

    Returns Uint8Array

    an Uint8Array with 16 random values.

  • isValid(str: string): boolean
  • Checks if a string represents a valid v4 GUID.

    Parameters

    • str: string

    Returns boolean

    true if its a valid v4 GUID value represented as string.

  • newGuid(generator?: Crypto): Guid
  • Returns a Guid object with a random valid UUID v4 value. The method allows the use of a custom random value generator that implements the Crypto API. The internal guid value is generated using the provided generator (if any), if not provided, it attempts to generate random values from the Crypto API of the browser. If the browser does not support the Crypto API, Math.random() is used as a fallback to generate random values.

    Parameters

    • Optional generator: Crypto

    Returns Guid

    A new Guid object with a valid random value generated by the provided generator or the defaults.

  • setSpecialBytesForV4Guid(arr: Uint8Array): void
  • Sets the bytes of an Uint8Array to match the RFC definition of v4 GUIDs.

    Parameters

    • arr: Uint8Array

      is the array to be modified.

    Returns void

Generated using TypeDoc