Add tus-js-client type definition

This commit is contained in:
Kevin Somers-Higgins
2017-07-07 08:43:35 -05:00
parent 8520aa6314
commit a8d217f430
4 changed files with 93 additions and 0 deletions

32
types/tus-js-client/index.d.ts vendored Normal file
View File

@@ -0,0 +1,32 @@
// Type definitions for tus-js-client 1.4
// Project: https://github.com/tus/tus-js-client/
// Definitions by: Kevin Somers-Higgins <https://github.com/kevhiggins/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface UploadOptions {
endpoint: string;
fingerprint?: string;
resume?: boolean;
onProgress?: ((bytesSent: number, bytesTotal: number) => void) | null;
onChunkComplete?: ((chunkSize: number, bytesAccepted: number, bytesTotal: number) => void) | null;
onSuccess?: (() => void) | null;
onError?: ((error: Error) => void) | null;
headers?: { [key: string]: string };
chunkSize?: number;
withCredentials?: boolean;
uploadUrl?: string | null;
uploadSize?: number | null;
overridePatchMethod?: boolean;
retryDelays?: number[];
}
export class Upload {
constructor(file: File | Blob, options: UploadOptions);
file: File | Blob;
options: UploadOptions;
url: string | null;
start(): void;
abort(): void;
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"tus-js-client-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@@ -0,0 +1,37 @@
import * as Tus from 'tus-js-client';
let file = new File(["foo"], "foo.txt", {
type: "text/plain",
});
let upload = new Tus.Upload(file, {
endpoint: "",
fingerprint: "fingerprint",
resume: true,
onProgress: (bytesSent: number, bytesTotal: number) => {
let percentage = (bytesSent / bytesTotal * 100).toFixed(2);
console.log(bytesSent, bytesTotal, percentage + "%");
},
onChunkComplete: (chunkSize: number, bytesAccepted: number) => {},
onSuccess: () => {
console.log("Download from %s complete", upload.url);
},
onError: (error: Error) => {
console.log("Failed because: " + error);
},
headers: {TestHeader: 'TestValue'},
chunkSize: 100,
withCredentials: true,
uploadUrl: "",
uploadSize: 50,
overridePatchMethod: true,
retryDelays: [10, 20, 50]
});
upload.start();
upload.abort();
let upload2 = new Tus.Upload(file, {
endpoint: ""
});