UNPKG

@canonical/jujulib

Version:
37 lines (34 loc) 1.49 kB
import { Callback, CallbackError } from "../generator/interfaces"; export declare enum Label { UNKNOWN_ERROR = "Unknown error" } /** Automatically bind all methods of the given object to the object itself. @param obj The object whose method must be bound. */ export declare function autoBind(obj: { [k: string]: any; }): void; /** Create an async handler which will either return a value to a supplied callback, or call the appropriate method on the promise resolve/reject. @param [callback] The optional callback. @param [resolve] The optional promise resolve function. @param [reject] The optional promise reject function. @param [transform] The optional response transform function. @return The returned function takes two arguments (err, value). If the the callback is a function the two arguments will be passed through to the callback in the same order. If no callback is supplied, the promise resolve or reject method will be called depending on the existence of an error value. */ export declare function createAsyncHandler<T>(callback: Callback<T> | undefined, resolve: (value: T) => void, reject: (error: CallbackError) => void, transform?: (value: T) => T): { resolve: (value: T) => void; reject: (error: CallbackError) => void; }; /** Convert given input to an Error object. @param error - The input to be converted to an Error object. @returns An Error object. */ export declare function toError(error: any): Error;