import { AxiosError } from 'axios'; import { JWTToken } from '../auth/models'; import { AuthProvider, ExternalWalletType, JSONObject } from '../common/models'; export declare const splitAt: (index: number, dropChars: number) => (x: string) => string[]; export default class Helpers { static isInBrowser: boolean; static isNullOrEmpty(obj: any): boolean; static log(message: string, data?: any): void; /** Decodes a JWT token string * If token can't be decoded (e.g. corrupted), returns null */ static jwtDecodeSafe(token: string): Partial; /** Takes a url string and converts it to an object of {paramNane, paramValue} * e.g input: https://xxx?enabled&name=value&name2=val2 * returns: { 'enabled': true, 'name':'value', 'name2':'val2' } * if the parameter only has a name and no value, then its value is set to 'true' * */ static parseUrlParams(fullPath: string): JSONObject; /** Returns Null if parse fails * Reinflates a serialized object (e.g. UInt8Array) if found in JSON */ static tryParseJSON(jsonString: any, unescape?: boolean, replaceQuotes?: boolean): any; /** * The reviver function passed into JSON.parse to implement custom type conversions. * If the value is a previously stringified buffer we convert it to a Buffer, * If its an object of numbers, we convert to UInt8Array {"0":2,"1":209,"2":8 ...} * otherwise return the value */ static jsonParseComplexObjectReviver(key: string, value: any): any; static base64DecodeSafe(encodedString: string): any; /** Base64 encodes a string * if value passed in is an Object or JSON, it will be stringified first * if value is null, this function returns null */ static base64Encode(valueIn: any): string; static sleep(ms: number): Promise; static createGuid(): string; /** Typescript Typeguard to verify that the value is in the enumType specified */ static isInEnum(enumType: T, value: any): value is T[keyof T]; /** Typescript Typeguard helper to ensure that a string value can be assigned to an Enum type * If a value can't be matched to a valid option in the enum, returns null (or throws if throwIfInvalid = true) */ static toEnumValue(e: T, value: any, throwIfInvalid?: boolean): T[keyof T]; /** Parses comma-seperated error_codes from url response * Returns: array of error code strings * Note: Params is a javascript object parsed from callback URL string */ static getErrorCodesFromParams(params: any): string[]; /** Retrieve values from a url query string and returns an array of them * Also parses error codes returned into an array of errors codes/messages */ static extractDataFromCallbackUrl(url: string): { [key: string]: any; }; /** Call the callback once for each item in the array and await for each to finish in turn */ static asyncForEach(array: any[], callback: (item: any, index: number, array: any[]) => Promise): Promise; /** Return a value in a custom claim in a JWT token by using a partial claim name * e.g. function(token, 'appId') => value for claim https://oreid.io/appId */ static getClaimFromJwtTokenBySearchString(decodedToken: JWTToken, searchString: string): string; /** get error from inside a network request (Axios Error object) and return it */ static getErrorFromAxiosError(error: AxiosError): Error; static isAxiosError(error: any): error is AxiosError; static isAString(value: any): boolean; static isADate(value: any): boolean; static isABoolean(value: any): boolean; static isANumber(value: any): boolean; static isAnObject(obj: any): boolean; /** throw error if invalid provider */ static assertValidProvider(provider: AuthProvider): boolean; /** Convert an AuthProvider to the ExternalWalletType subset * Returns null if can't convert member */ static mapAuthProviderToWalletType(provider: AuthProvider | ExternalWalletType): ExternalWalletType; static isCustodial(provider: AuthProvider): boolean; static isValidEmail(email: any): boolean; /** Sort JSON in a deterministic way */ static sortJson(value: any): any; /** filter complex values in array down to an array of a single, uniques values * e.g. if array = [{value:'A', other}, {value:'B', something}, {value:'A', other}] * => [{value:'A', other}, {value:'B', something}] */ static getUniqueValues(array: T[]): any[]; /** Execute a callback function at a given Unix Epoch time */ static runAtTime(callback: Function, executionEoochTime: number): number; /** whether objects are 'equal' by deep comparing all members */ static objectsAreEqual(a: any, b: any): boolean; }