Function convertValueToHexString

  • Converts a value to a hexadecimal string representation.

    • If the value is a string that can be parsed as a number, converts it to hex.
    • If the value is a string that cannot be parsed as a number, returns it as is.
    • If the value is a Uint8Array, converts each byte to a hex string, with optional padding and prefix, then joins with spaces.
    • If the value is a number, converts it to hex with optional padding and prefix.
    • If the value is an array of numbers, converts each to hex with optional padding and prefix, then joins with spaces.
    • Returns an empty string for unsupported value types.

    Returns

    Hexadecimal string representation or original string.

    Example

    convertValueToHexString("255");                       // "0xff"
    convertValueToHexString("not a number"); // "not a number"
    convertValueToHexString(255); // "0xff"
    convertValueToHexString([1, 255], 4); // "0x0001 0x00ff"
    convertValueToHexString(new Uint8Array([15,255]), 2); // "0x0f 0xff"

    Parameters

    • value: string | number | Uint8Array | number[]

      The value to convert (string, number, Uint8Array, or array of numbers).

    • Optional pad: null | number

      Optional minimum length for each hex number (without prefix).

    • prefix: string = '0x'

      Optional prefix for each hex number (default '0x').

    Returns string

Generated using TypeDoc