Files
react-native-background-dow…/index.d.ts
Philip Su 83b43478ba feat: introduce index.d.ts for typescript support
File taken directly from what I made for @types/kesha-antonov__react-native-background-downloader. Verified working by installing locally in a typescript project that consumes it, and verifying via --traceResolution that the index.d.ts file is successfully found and that types resolve.
2023-02-03 23:47:57 -08:00

119 lines
3.1 KiB
TypeScript

// Type definitions for @kesha-antonov/react-native-background-downloader 2.6
// Project: https://github.com/kesha-antonov/react-native-background-downloader
// Definitions by: Philip Su <https://github.com/fivecar>,
// Adam Hunter <https://github.com/adamrhunter>,
// Junseong Park <https://github.com/Kweiza>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface DownloadHeaders {
[key: string]: string | null;
}
type SetHeaders = (h: DownloadHeaders) => void;
export interface TaskInfoObject {
id: string;
percent: number;
bytesWritten: number;
totalBytes: number;
}
export type TaskInfo = string | TaskInfoObject;
export interface BeginHandlerObject {
expectedBytes: number;
headers: { [key: string]: string };
}
export type BeginHandler = ({
expectedBytes,
headers,
}: BeginHandlerObject) => any;
export type ProgressHandler = (
percent: number,
bytesWritten: number,
totalBytes: number
) => any;
export type DoneHandler = () => any;
export type ErrorHandler = (error: any, errorCode: any) => any;
export type DownloadTaskState =
| "DOWNLOADING"
| "PAUSED"
| "DONE"
| "FAILED"
| "STOPPED";
export interface DownloadTask {
constructor: (taskInfo: TaskInfo) => DownloadTask;
id: string;
state: DownloadTaskState;
percent: number;
bytesWritten: number;
totalBytes: number;
begin: (handler: BeginHandler) => DownloadTask;
progress: (handler: ProgressHandler) => DownloadTask;
done: (handler: DoneHandler) => DownloadTask;
error: (handler: ErrorHandler) => DownloadTask;
_beginHandler: BeginHandler;
_progressHandler: ProgressHandler;
_doneHandler: DoneHandler;
_errorHandler: ErrorHandler;
pause: () => any;
resume: () => any;
stop: () => any;
}
export type CheckForExistingDownloads = () => Promise<DownloadTask[]>;
export type EnsureDownloadsAreRunning = () => Promise<void>;
export interface DownloadOption {
id: string;
url: string;
destination: string;
headers?: DownloadHeaders | undefined;
}
export type Download = (options: DownloadOption) => DownloadTask;
export type CompleteHandler = (id: string) => void;
export interface Directories {
documents: string;
}
export interface Network {
WIFI_ONLY: string;
ALL: string;
}
export interface Priority {
HIGH: string;
MEDIUM: string;
LOW: string;
}
export const setHeaders: SetHeaders;
export const checkForExistingDownloads: CheckForExistingDownloads;
export const ensureDownloadsAreRunning: EnsureDownloadsAreRunning;
export const download: Download;
export const completeHandler: CompleteHandler;
export const directories: Directories;
export const Network: Network;
export const Priority: Priority;
export interface RNBackgroundDownloader {
setHeaders: SetHeaders;
checkForExistingDownloads: CheckForExistingDownloads;
ensureDownloadsAreRunning: EnsureDownloadsAreRunning;
download: Download;
completeHandler: CompleteHandler;
directories: Directories;
Network: Network;
Priority: Priority;
}
declare const RNBackgroundDownloader: RNBackgroundDownloader;
export default RNBackgroundDownloader;