Options
All
  • Public
  • Public/Protected
  • All
Menu

Module utils

Utility functions for Dolos. These are some miscellaneous functions that didn't really fit anywhere else.

Index

Type aliases

Type

Type: object

Type of a constructor which, when used, returns an instance of T.

example

// declare a function which constructs a URL from a href using a constructor.
function createURL(href: string, constructor: Type<URL>): URL {
    return new URL(href);
}

Type declaration

Functions

arrayElementsEqual

  • arrayElementsEqual(a: any[], b: any[]): boolean
  • Check whether the elements of two arrays are equal.

    Parameters

    • a: any[]

      First array

    • b: any[]

      Second array

    Returns boolean

    true if both arrays have the same elements in the same order and false otherwise.

getBackgroundWindow

getBlobURL

  • getBlobURL(url: string): Promise<string>
  • Download the data and return a url pointing to it.

    Parameters

    • url: string

    Returns Promise<string>

marshalError

  • marshalError(error: Error): string
  • Serialise an error so that it can persist outside of the Javascript environment.

    see

    unmarshalError to recreate an Error

    Parameters

    • error: Error

    Returns string

promisifyCallback

  • promisifyCallback<T>(func: function): Promise<T>
  • promisifyCallback<T>(func: function): Promise<T>
  • Convert a function which takes a callback to a Promise.

    Type parameters

    • T: any

    Parameters

    • func: function
        • (callback: function): void
        • Parameters

          • callback: function
              • (arg: T): void
              • Parameters

                • arg: T

                Returns void

          Returns void

    Returns Promise<T>

  • Convert a function which takes a callback to a Promise.

    Type parameters

    • T: any[]

    Parameters

    • func: function
        • (callback: function): void
        • Parameters

          • callback: function
              • (...args: T): void
              • Parameters

                • Rest ...args: T

                Returns void

          Returns void

    Returns Promise<T>

reactRenderWithTheme

  • reactRenderWithTheme(component: React.ReactNode, theme: Theme, renderTarget: Element): void
  • Apply a theme to a React node and render it to renderTarget

    Parameters

    • component: React.ReactNode
    • theme: Theme
    • renderTarget: Element

    Returns void

retryUntil

  • Re-run a function until the return value meets the condition.

    Type parameters

    • T

    Parameters

    • func: function

      may take the number of attempts that preceded it (counting up from 0)

        • (attempt: number): T | PromiseLike<T>
        • Parameters

          • attempt: number

          Returns T | PromiseLike<T>

    • opts: RetryUntilOptions<T>

    Returns Promise<T | undefined>

unmarshalError

  • unmarshalError(error: string): Error
  • Build an error from a marshalled representation.

    This creates an error of type Error, custom errors are not supported and instanceof checks should not be used. Instead use the [[Error.name]] property to distinguish between error types!

    see

    marshalError to marshal an error.

    Parameters

    • error: string

    Returns Error

waitUntilExists

  • waitUntilExists(selector: string, target?: Node & ParentNode): Promise<Element>
  • Wait for an Element to exist in the DOM.

    Parameters

    • selector: string

      CSS selector to wait for

    • Optional target: Node & ParentNode

      Node from which to use the selector. Defaults to document

    Returns Promise<Element>

waitWithTimeout

  • waitWithTimeout<T>(promise: PromiseLike<T>, timeout: number): Promise<T | undefined>
  • Apply a timeout to a promise.

    Type parameters

    • T

    Parameters

    • promise: PromiseLike<T>
    • timeout: number

      Timeout in milliseconds

    Returns Promise<T | undefined>

    The result of promise or undefined if it timed out

wrapSentryLogger

  • wrapSentryLogger(component: React.ReactNode): React.ReactNode
  • Wrap a React node with a Sentry logger which catches errors and displays a message to the user.

    see

    SentryLogger

    Parameters

    • component: React.ReactNode

    Returns React.ReactNode

wrapWithTheme

  • wrapWithTheme(component: React.ReactNode, theme: Theme): ReactElement<any>
  • Apply a theme to a React node.

    This wraps the provided node with both the modern [[ThemeProvider]] and the old [[MuiThemeProvider]].

    see

    reactRenderWithTheme to render the result to an element.

    Parameters

    • component: React.ReactNode
    • theme: Theme

    Returns ReactElement<any>

Generated using TypeDoc