mirror of
https://github.com/zoriya/react-native-background-downloader.git
synced 2025-12-06 06:56:10 +00:00
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.
This commit is contained in:
118
index.d.ts
vendored
Normal file
118
index.d.ts
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
// 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;
|
||||
@@ -25,11 +25,13 @@
|
||||
}
|
||||
],
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"README.md",
|
||||
"LICENSE",
|
||||
"react-native-background-downloader.podspec",
|
||||
"package.json",
|
||||
"index.d.ts",
|
||||
"index.js",
|
||||
"lib/",
|
||||
"ios/",
|
||||
|
||||
Reference in New Issue
Block a user