@dapplets/dapplet-extension
Version:
The Bridge to the Augmented Web.
120 lines (119 loc) • 5.05 kB
TypeScript
import browser from 'webextension-polyfill';
import { ChainTypes, MessageWrapperRequest, ModuleId, UrlAvailability, WalletDescriptor } from './types';
export declare function getHostName(url: string): string;
/**
* Merges and deduplicates arrays of arrays
* @param input arrays of arrays
*/
export declare function mergeDedupe<T>(input: T[][]): T[];
/**
* Merges arrays of arrays
* @param input arrays of arrays
*/
export declare function mergeArrays<T>(input: T[][]): T[];
/**
* Compares name, branch and version of A and B
* @param a manifest's part A
* @param a manifest's part B
*/
export declare function areModulesEqual(a: ModuleId, b: ModuleId): boolean;
export declare enum UriTypes {
Unknown = 0,
Http = 1,
Swarm = 2,
Ipfs = 3,
Ethereum = 4,
Ens = 5,
Near = 6
}
/**
* Recognizes a type of URI
*/
export declare function typeOfUri(uri: string): UriTypes;
/**
* Assert function for filtering of fullfilled Promises with .filter()
*/
export declare function assertFullfilled<T>(item: PromiseSettledResult<T>): item is PromiseFulfilledResult<T>;
/**
* Assert function for filtering of rejected Promises with .filter()
*/
export declare function assertRejected<T>(item: PromiseSettledResult<T>): item is PromiseRejectedResult;
export declare function allSettled($: any): any;
export declare function timeoutPromise<T>(ms: number, promise: Promise<T>, timeoutCallback?: Function): Promise<T>;
export declare function getCurrentTab(): Promise<browser.Tabs.Tab | null>;
export declare const getCurrentContextIds: (tab: browser.Tabs.Tab | null) => Promise<string[]>;
export declare function networkName(chainId: number): any;
export declare function fetchWithTimeout(resource: any, options: any): Promise<Response>;
export declare function waitTab(url: string): Promise<browser.Tabs.Tab>;
export declare function chainByUri(t: UriTypes): ChainTypes;
/**
* Add increment to filename for uniqueness
* @param name filename
* @returns
*/
export declare function incrementFilename(name: string): string;
export declare function joinUrls(base: string, url: string): string;
export declare function parseModuleName(str: string): {
name: string;
branch: string;
version: string;
} | null;
export declare function pick(o: any, ...fields: string[]): {};
export declare function waitClosingTab(tabId: number, windowId: number): Promise<void>;
export declare function reloadCurrentPage(): Promise<void>;
export declare function formatModuleId({ name, branch, version }: ModuleId): string;
/**
* Returns new array with all matches of `substr` replaced by elements of `newstrArray`
*/
export declare function multipleReplace(arr: string[], substr: string, newstrArray: string[]): string[];
export type ShareLinkPayload = {
sourceExtensionVersion: string;
registry: string;
moduleId: string;
contextIds: string[];
payload: any;
};
export declare function tryParseBase64Payload(base64Payload: string): ShareLinkPayload;
export declare function parseShareLink(url: string): {
urlNoPayload: string;
payloadBase64: string;
};
export declare function groupBy<T>(array: T[], predicate: (v: T) => string): {
[key: string]: T[];
};
/**
* Returns bit value of hex string by bit number
* @param hex hex string (0xdeadbeef) of any length
* @param bitnumber index number of bit from the end (starts from 0)
*/
export declare function getBitFromHex(hex: string, bitnumber: number): boolean;
/**
* Converts hex-string to binary-string. Big numbers resistance.
*/
export declare function convertHexToBinary(hex: string): string;
export declare function checkUrlAvailability(url: string): Promise<UrlAvailability>;
/**
* Decorator for async methods caching promises until it's not fulfilled.
* Prevents execution of multiple promises at the same time.
*/
export declare function CacheMethod(): (_: any, __: any, descriptor: PropertyDescriptor) => PropertyDescriptor;
export declare function getThisTab(callInfo: MessageWrapperRequest): Promise<browser.Tabs.Tab>;
export declare function mergeSameWallets(descriptors: WalletDescriptor[]): WalletDescriptor[];
export declare function convertTimestampToISODate(timestamp: number): string;
export declare function convertISODateToTimestamp(isoDate: string): number;
export declare function blobToDataURL(blob: Blob): Promise<string>;
export declare const isValidUrl: (input: string) => boolean;
export declare const isValidHttp: (url: string) => boolean;
export declare const isValidPostageStampId: (id: string) => boolean;
export declare const numberWithCommas: (x: number) => string;
export declare function Measure(): (target: any, method: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
export declare const objectMap: (obj: any, fn: any) => {
[x: string]: any;
[x: number]: any;
[x: symbol]: any;
};
export declare const makeCancelable: (promise: Promise<void>) => {
promise: Promise<unknown>;
cancel: () => void;
};
export declare const isValidEnumValue: <T>(enumType: T, value: any) => boolean;