diff --git a/types/downscale/downscale-tests.ts b/types/downscale/downscale-tests.ts new file mode 100644 index 0000000000..c487861cd8 --- /dev/null +++ b/types/downscale/downscale-tests.ts @@ -0,0 +1,19 @@ +import downscale from 'downscale'; + +const image = new HTMLImageElement(); +const video = new HTMLVideoElement(); +const file = new File([], 'abc'); +const string = ''; + +downscale(image, 0, 0); +downscale(video, 0, 0); +downscale(file, 0, 0); +downscale(string, 0, 0); + +async function doTheTests() { + const string_returned: string = await downscale(image, 0, 0); + + const canvas_returned: HTMLCanvasElement = await downscale(image, 0, 0, { returnCanvas: true }); + + const blob_returned: Blob = await downscale(image, 0, 0, { returnBlob: true }); +} diff --git a/types/downscale/index.d.ts b/types/downscale/index.d.ts new file mode 100644 index 0000000000..aeff431137 --- /dev/null +++ b/types/downscale/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for downscale 1.0 +// Project: https://github.com/ytiurin/downscale +// Definitions by: Gabriel Soicher +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type ImageSource = File | HTMLImageElement | HTMLVideoElement | string; + +interface DownscaleOptions { + imageType?: string; + quality?: number; + returnBlob?: boolean; + returnCanvas?: boolean; + sourceX?: number; + sourceY?: number; +} + +/** + * Overloads that automatically type the return value based on the selected options + */ +declare function downscale(source: ImageSource, width: number, height: number, options?: DownscaleOptions & { returnBlob?: false; returnCanvas?: false; }): Promise; +declare function downscale(source: ImageSource, width: number, height: number, options?: DownscaleOptions & { returnBlob: true; }): Promise; +declare function downscale(source: ImageSource, width: number, height: number, options?: DownscaleOptions & { returnCanvas: true; }): Promise; + +export = downscale; + +export as namespace downscale; diff --git a/types/downscale/tsconfig.json b/types/downscale/tsconfig.json new file mode 100644 index 0000000000..a149cdca8e --- /dev/null +++ b/types/downscale/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "DOM" + ], + "esModuleInterop": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "downscale-tests.ts" + ] +} \ No newline at end of file diff --git a/types/downscale/tslint.json b/types/downscale/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/downscale/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }