Skip to content

Commit b6e8f6e

Browse files
authored
Merge pull request #82 from jamiehaywood/dev
Update interfaces & docs
2 parents 7dab008 + f8faca9 commit b6e8f6e

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,25 @@ const options = {
5050
onProgress: Function, // optional, a function takes one progress argument (percentage from 0 to 100)
5151
useWebWorker: boolean, // optional, use multi-thread web worker, fallback to run in main-thread (default: true)
5252

53-
// following options are for advanced user
53+
// following options are for advanced users
5454
maxIteration: number, // optional, max number of iteration to compress the image (default: 10)
5555
exifOrientation: number, // optional, see https://stackoverflow.com/a/32490603/10395024
5656
fileType: string, // optional, fileType override
5757
initialQuality: number // optional, initial quality value between 0 and 1 (default: 1)
5858
}
5959

60-
imageCompression(file: File, options): Promise<File | Blob>
60+
imageCompression(file: File, options): Promise<File>
6161
```
6262
### Helper function ###
63-
- for advanced user only, most user won't need to use the helper functions
63+
- for advanced users only, most users won't need to use the helper functions
6464
```javascript
65-
imageCompression.getDataUrlFromFile(file: File | Blob): Promise<base64 encoded string>
65+
imageCompression.getDataUrlFromFile(file: File): Promise<base64 encoded string>
6666
imageCompression.getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise<File>
6767
imageCompression.loadImage(url: string): Promise<HTMLImageElement>
6868
imageCompression.drawImageInCanvas(img: HTMLImageElement): HTMLCanvasElement | OffscreenCanvas
69-
imageCompression.drawFileInCanvas(file: File| Blob): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]>
70-
imageCompression.canvasToFile(canvas: HTMLCanvasElement | OffscreenCanvas, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File | Blob>
71-
imageCompression.getExifOrientation(file: File| Blob): Promise<number> // based on https://stackoverflow.com/a/32490603/10395024
69+
imageCompression.drawFileInCanvas(file: File): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement | OffscreenCanvas]>
70+
imageCompression.canvasToFile(canvas: HTMLCanvasElement | OffscreenCanvas, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File>
71+
imageCompression.getExifOrientation(file: File): Promise<number> // based on https://stackoverflow.com/a/32490603/10395024
7272
```
7373

7474
## Usage ##
@@ -148,11 +148,7 @@ You can include the following script to load the Promise polyfill:
148148
```
149149

150150
## Typescript type definitions ##
151-
```
152-
npm install --save-dev @types/browser-image-compression
153-
or
154-
yarn add --dev @types/browser-image-compression
155-
```
151+
Typescript definitions are included in the package & referenced in the `types` section of the `package.json`
156152

157153
## Contribution ##
158154
1. fork the repo and git clone it

lib/index.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Type definitions for browser-image-compression 1.0
22
// Project: https://github.com/Donaldcwl/browser-image-compression
3-
// Definitions by: Donald <https://github.com/Donaldcwl>
3+
// Definitions by: Donald <https://github.com/Donaldcwl> & Jamie Haywood <https://github.com/jamiehaywood>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
55

66
interface Options {
@@ -22,16 +22,16 @@ interface Options {
2222
initialQuality?: number;
2323
}
2424

25-
declare function imageCompression(image: File | Blob, options: Options): Promise<File | Blob>;
25+
declare function imageCompression(image: File, options: Options): Promise<File>;
2626

2727
declare namespace imageCompression {
28-
function getDataUrlFromFile(file: File | Blob): Promise<string>;
29-
function getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise<File | Blob>;
28+
function getDataUrlFromFile(file: File): Promise<string>;
29+
function getFilefromDataUrl(dataUrl: string, filename: string, lastModified?: number): Promise<File>;
3030
function loadImage(src: string): Promise<HTMLImageElement>;
3131
function drawImageInCanvas(img: HTMLImageElement): HTMLCanvasElement;
32-
function drawFileInCanvas(file: File | Blob): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement]>;
33-
function canvasToFile(canvas: HTMLCanvasElement, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File | Blob>;
34-
function getExifOrientation(file: File | Blob): Promise<number>;
32+
function drawFileInCanvas(file: File): Promise<[ImageBitmap | HTMLImageElement, HTMLCanvasElement]>;
33+
function canvasToFile(canvas: HTMLCanvasElement, fileType: string, fileName: string, fileLastModified: number, quality?: number): Promise<File>;
34+
function getExifOrientation(file: File): Promise<number>;
3535
}
3636

3737
export as namespace imageCompression;

0 commit comments

Comments
 (0)