Skip to content

Commit 51593b3

Browse files
committed
chore: adjust linting and stuff
1 parent 00e41e6 commit 51593b3

File tree

3 files changed

+61
-61
lines changed

3 files changed

+61
-61
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
| Statements | Branches | Functions | Lines |
1010
| ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
11-
| ![Statements](https://img.shields.io/badge/statements-87.38%25-yellow.svg?style=flat&logo=jest) | ![Branches](https://img.shields.io/badge/branches-72.5%25-red.svg?style=flat&logo=jest) | ![Functions](https://img.shields.io/badge/functions-81.81%25-yellow.svg?style=flat&logo=jest) | ![Lines](https://img.shields.io/badge/lines-88%25-yellow.svg?style=flat&logo=jest) |
11+
| ![Statements](https://img.shields.io/badge/statements-87.38%25-yellow.svg?style=flat&logo=jest) | ![Branches](https://img.shields.io/badge/branches-73.17%25-red.svg?style=flat&logo=jest) | ![Functions](https://img.shields.io/badge/functions-81.81%25-yellow.svg?style=flat&logo=jest) | ![Lines](https://img.shields.io/badge/lines-88%25-yellow.svg?style=flat&logo=jest) |
1212

1313
## Table of Contents
1414

src/index.ts

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
} from './types';
1010

1111
/**
12-
*
13-
* @param param0
14-
* @returns
12+
* Resolver function to handle the download progress.
13+
* @param {ResolverProps} props
14+
* @returns {Response}
1515
*/
1616
export const resolver =
1717
({
@@ -20,73 +20,73 @@ export const resolver =
2020
setPercentageCallback,
2121
setErrorCallback,
2222
}: ResolverProps) =>
23-
(response: Response): Response => {
24-
if (!response.ok) {
25-
throw Error(`${response.status} ${response.type} ${response.statusText}`);
26-
}
23+
(response: Response): Response => {
24+
if (!response.ok) {
25+
throw Error(`${response.status} ${response.type} ${response.statusText}`);
26+
}
2727

28-
if (!response.body) {
29-
throw Error('ReadableStream not yet supported in this browser.');
30-
}
28+
if (!response.body) {
29+
throw Error('ReadableStream not yet supported in this browser.');
30+
}
3131

32-
const responseBody = response.body;
32+
const responseBody = response.body;
3333

34-
const contentEncoding = response.headers.get('content-encoding');
35-
const contentLength = response.headers.get(
36-
contentEncoding ? 'x-file-size' : 'content-length'
37-
);
34+
const contentEncoding = response.headers.get('content-encoding');
35+
const contentLength = response.headers.get(
36+
contentEncoding ? 'x-file-size' : 'content-length'
37+
);
3838

39-
const total = parseInt(contentLength || '0', 10);
39+
const total = parseInt(contentLength || '0', 10);
4040

41-
setSize(() => total);
41+
setSize(() => total);
4242

43-
let loaded = 0;
43+
let loaded = 0;
4444

45-
const stream = new ReadableStream<Uint8Array>({
46-
start(controller) {
47-
setControllerCallback(controller);
45+
const stream = new ReadableStream<Uint8Array>({
46+
start(controller) {
47+
setControllerCallback(controller);
4848

49-
const reader = responseBody.getReader();
49+
const reader = responseBody.getReader();
5050

51-
async function read(): Promise<void> {
52-
return reader
53-
.read()
54-
.then(({ done, value }) => {
55-
if (done) {
56-
return controller.close();
57-
}
51+
async function read(): Promise<void> {
52+
return reader
53+
.read()
54+
.then(({ done, value }) => {
55+
if (done) {
56+
return controller.close();
57+
}
5858

59-
loaded += value?.byteLength || 0;
59+
loaded += value?.byteLength || 0;
6060

61-
if (value) {
62-
controller.enqueue(value);
63-
}
61+
if (value) {
62+
controller.enqueue(value);
63+
}
6464

65-
setPercentageCallback({ loaded, total });
65+
setPercentageCallback({ loaded, total });
6666

67-
return read();
68-
})
69-
.catch((error: Error) => {
70-
setErrorCallback(error);
71-
reader.cancel('Cancelled');
67+
return read();
68+
})
69+
.catch((error: Error) => {
70+
setErrorCallback(error);
71+
reader.cancel('Cancelled');
7272

73-
return controller.error(error);
74-
});
75-
}
73+
return controller.error(error);
74+
});
75+
}
7676

77-
return read();
78-
},
79-
});
77+
return read();
78+
},
79+
});
8080

81-
return new Response(stream);
82-
};
81+
return new Response(stream);
82+
};
8383

8484
/**
85-
*
86-
* @param {Blob} data
87-
* @param {string} filename
88-
* @param {string} mime
89-
* @returns
85+
* jsDownload function to handle the download process.
86+
* @param {Blob} data
87+
* @param {string} filename
88+
* @param {string} mime
89+
* @returns {boolean | NodeJS.Timeout}
9090
*/
9191
export const jsDownload = (
9292
data: Blob,
@@ -131,9 +131,9 @@ export const jsDownload = (
131131
};
132132

133133
/**
134-
* Initialise a new instance of downloader.
135-
* @param {UseDownloaderOptions} options
136-
* @returns UseDownloader
134+
* useDownloader hook to handle the download process.
135+
* @param {UseDownloaderOptions} options
136+
* @returns {UseDownloader}
137137
*/
138138
export default function useDownloader(
139139
options: UseDownloaderOptions = {}

src/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ export type ErrorMessage = {
44
errorMessage: string;
55
} | null;
66

7+
/** useDownloader options for fetch call
8+
* See fetch RequestInit for more details
9+
*/
10+
export type UseDownloaderOptions = RequestInit;
11+
712
/**
813
* Initiate the download of the specified asset from the specified url. Optionally supply timeout and overrideOptions.
914
* @example await download('https://example.com/file.zip', 'file.zip')
@@ -80,8 +85,3 @@ interface CustomNavigator extends Navigator {
8085
export interface WindowDownloaderEmbedded extends Window {
8186
navigator: CustomNavigator;
8287
}
83-
84-
/** useDownloader options for fetch call
85-
* See fetch RequestInit for more details
86-
*/
87-
export type UseDownloaderOptions = RequestInit;

0 commit comments

Comments
 (0)