Options
All
  • Public
  • Public/Protected
  • All
Menu

Module utils

This file contains useful functions which can be (and are) used in whole project.

Functions

AddressEquals

  • AddressEquals(x: string | Address, y: string | Address): boolean
  • Accepts two Ethereum addresses (as string or Address type) and returns true if and only if these addresses are the same.

    Parameters

    • x: string | Address

      First address

    • y: string | Address

      Second address

    Returns boolean

    True if first address is same as the second one, false otherwise

Const clamp

  • clamp(value: number, min?: number, max?: number): number
  • Function which clamps given value.

    Parameters

    • value: number

      Numeric value which should be clamped

    • Default value min: number = Number.MIN_VALUE

      Minimal value, which is returned if the given value is less than it

    • Default value max: number = Number.MAX_VALUE

      Maximal value, which is returned if the given value is greater than it

    Returns number

    Given numeric value, clamped by min and max values

Const delay

  • delay(ms: number): Promise<void>
  • Returns promise which is always resolved after given time.

    Parameters

    • ms: number

      Time (in milliseconds) after which the promise is resolved

    Returns Promise<void>

    Promise which is resolved after given time

Const notUndefined

  • notUndefined<T>(x: T | undefined): x
  • Predicate returning true if the given object is not undefined. It is useful for converting Array<T | undefined> to Array<T> with filter function.

    Type parameters

    • T

      Type of given object

    Parameters

    • x: T | undefined

      Object of type T or undefined

    Returns x

Const parseWeb3ErrorMessage

  • parseWeb3ErrorMessage(err: object): string
  • Function which detects wrong error messages of MetaMask (due to its bug) and returns "Unknown error" if the real error was invalid.

    Parameters

    • err: object

      MetaMask's error object

      • message: string

    Returns string

Const throwError

  • throwError(msg: string): never
  • Function which always throws an error with given message. It is useful in chained functions.

    Parameters

    • msg: string

      Error message

    Returns never

Generated using TypeDoc