Class HexString

A util class for working with hex strings. Hex strings are strings that are prefixed with 0x

Hierarchy

  • HexString

Constructors

  • Creates new HexString instance from regular string. If specified string already starts with "0x" prefix, it will not add another one

    Example

     const string = "string";
    new HexString(string); // "0xstring"

    Parameters

    • hexString: string

      String to convert

    Returns HexString

Properties

hexString: string

Methods

  • Getter for inner hexString without prefix

    Returns

    Inner hex string without prefix

    Example

     const hexString = new HexString("string"); // "0xstring"
    hexString.noPrefix(); // "string"

    Returns string

  • Trimmes extra zeroes in the begining of a string

    Returns

    Inner hexString without leading zeroes

    Example

     new HexString("0x000000string").toShortString(); // result = "0xstring"
    

    Returns string

  • Overrides default toString method

    Returns

    Inner hex string

    Returns string

  • Converts hex string to a Uint8Array

    Returns

    Uint8Array from inner hexString without prefix

    Returns Uint8Array

  • Ensures hexString is instance of HexString class

    Returns

    New HexString if hexString is regular string or hexString if it is HexString instance

    Example

     const regularString = "string";
    const hexString = new HexString("string"); // "0xstring"
    HexString.ensure(regularString); // "0xstring"
    HexString.ensure(hexString); // "0xstring"

    Parameters

    Returns HexString

Generated using TypeDoc