mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 19:43:20 +08:00
Add tus-js-client type definition
This commit is contained in:
32
types/tus-js-client/index.d.ts
vendored
Normal file
32
types/tus-js-client/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
23
types/tus-js-client/tsconfig.json
Normal file
23
types/tus-js-client/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/tus-js-client/tslint.json
Normal file
1
types/tus-js-client/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
37
types/tus-js-client/tus-js-client-tests.ts
Normal file
37
types/tus-js-client/tus-js-client-tests.ts
Normal 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: ""
|
||||
});
|
||||
Reference in New Issue
Block a user