types for downscale - uses esmoduleinterop for export default (#41493)

* types for downscale - uses esmoduleinterop for export default

* umd declaration added
This commit is contained in:
Gabriel Soicher 2020-01-10 21:40:24 +02:00 committed by Armando Aguirre
parent 863519d139
commit a1c3da38c5
4 changed files with 71 additions and 0 deletions

View File

@ -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 });
}

26
types/downscale/index.d.ts vendored Normal file
View File

@ -0,0 +1,26 @@
// Type definitions for downscale 1.0
// Project: https://github.com/ytiurin/downscale
// Definitions by: Gabriel Soicher <https://github.com/Lunrtick>
// 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<string>;
declare function downscale(source: ImageSource, width: number, height: number, options?: DownscaleOptions & { returnBlob: true; }): Promise<Blob>;
declare function downscale(source: ImageSource, width: number, height: number, options?: DownscaleOptions & { returnCanvas: true; }): Promise<HTMLCanvasElement>;
export = downscale;
export as namespace downscale;

View File

@ -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"
]
}

View File

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