diff --git a/types/compress.js/compress.js-tests.ts b/types/compress.js/compress.js-tests.ts new file mode 100644 index 0000000000..c78b146205 --- /dev/null +++ b/types/compress.js/compress.js-tests.ts @@ -0,0 +1,32 @@ +import Compress = require('compress.js'); + +const compress = new Compress(); + +const uploadInput: HTMLInputElement = document.createElement('input'); + +uploadInput.type = 'file'; + +uploadInput.addEventListener( + 'change', + event => { + const target = event.target as HTMLInputElement; + + if (!target.files) { + return; + } + + compress.compress(Array.from(target.files), { + size: 4, + quality: 0.75, + maxWidth: 1920, + maxHeight: 1920, + resize: true, + }); + }, + false, +); + +compress.attach('#upload', { + size: 4, + quality: 0.75, +}); diff --git a/types/compress.js/index.d.ts b/types/compress.js/index.d.ts new file mode 100644 index 0000000000..cbeb243c64 --- /dev/null +++ b/types/compress.js/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for compress.js 1.1 +// Project: - (link to the repo is missing) +// Definitions by: Yuri Drabik +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = Compress; + +declare class Compress { + attach( + el: string, + options: CompressOptions, + ): Promise; + + compress( + files: File[], + options: CompressOptions, + ): Promise; + + static convertBase64ToFile( + base64: string, + mime?: string, + ): File; +} + +interface CompressOptions { + quality?: number; + size?: number; + maxWidth?: number; + maxHeight?: number; + resize?: boolean; +} + +interface CompressResult { + data: string; + prefix: string; + elapsedTimeInSeconds: number; + alt: string; + initialSizeInMb: number; + endSizeInMb: number; + ext: string; + quality: number; + endWidthInPx: number; + endHeightInPx: number; + initialWidthInPx: number; + initialHeightInPx: number; + sizeReducedInPercent: number; + iterations: number; +} diff --git a/types/compress.js/tsconfig.json b/types/compress.js/tsconfig.json new file mode 100644 index 0000000000..fbb383c3d2 --- /dev/null +++ b/types/compress.js/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "compress.js-tests.ts" + ] +} \ No newline at end of file diff --git a/types/compress.js/tslint.json b/types/compress.js/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/compress.js/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }