Skip to content

Commit 8402fc2

Browse files
committed
Fixes based on the PR review
1 parent b7abf2b commit 8402fc2

File tree

4 files changed

+57
-46
lines changed

4 files changed

+57
-46
lines changed

index.d.ts

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Function to rename downloaded files.
2+
Function to rename downloaded files.
33
*/
44
export interface RenameFunction {
55
/**
@@ -11,52 +11,51 @@ export interface RenameFunction {
1111
}
1212

1313
/**
14-
* Options for the multiDownload function.
14+
Options for the multiDownload function.
1515
*/
1616
export interface MultiDownloadOptions {
1717
/**
18-
* The function to rename the downloaded files.
19-
* @default undefined (use original filenames)
18+
The function to rename the downloaded files.
19+
@default undefined (use original filenames)
2020
*/
2121
rename?: RenameFunction;
2222

2323
/**
24-
* The delay time between each file download in milliseconds.
25-
* @default 1000
24+
The delay time between each file download in milliseconds.
25+
@default 1000
2626
*/
27-
delayTime?: number;
27+
downloadInterval?: number;
2828
}
2929

3030
/**
31-
* Download multiple files at once.
32-
* @param urls The URLs to download.
33-
* @param options The options for downloading.
34-
* @param options.rename The function to rename the downloaded files.
35-
* @param options.delayTime The delay time between each file download.
36-
* @example
37-
* ```typescript
38-
* import { multiDownload } from 'multi-download';
39-
*
40-
* async function downloadFiles() {
41-
* const urls = [
42-
* 'https://example.com/file1.txt',
43-
* 'https://example.com/file2.txt',
44-
* 'https://example.com/file3.txt',
45-
* ];
46-
*
47-
* try {
48-
* await multiDownload(urls, {
49-
* rename: ({ url, index }) => `file${index + 1}.txt`,
50-
* delayTime: 1000,
51-
* });
52-
* console.log('Files downloaded successfully');
53-
* } catch (error) {
54-
* console.error('Error downloading files:', error);
55-
* }
56-
* }
57-
*
58-
* downloadFiles();
59-
* ```
31+
Download multiple files from an array of URLs.
32+
@param urls - The URLs to download.
33+
@param options - The options for downloading.
34+
@returns A promise that resolves when all files have been downloaded.
35+
@example
36+
```
37+
import { multiDownload } from 'multi-download';
38+
39+
async function downloadFiles() {
40+
const urls = [
41+
'https://example.com/file1.txt',
42+
'https://example.com/file2.txt',
43+
'https://example.com/file3.txt',
44+
];
45+
46+
try {
47+
await multiDownload(urls, {
48+
rename: ({ url, index }) => `file${index + 1}.txt`,
49+
downloadInterval: 1000,
50+
});
51+
console.log('Files downloaded successfully');
52+
} catch (error) {
53+
console.error('Error downloading files:', error);
54+
}
55+
}
56+
57+
downloadFiles();
58+
```
6059
*/
6160
export default function multiDownload(
6261
urls: string[],

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const getName = ({ url }) => {
2121
};
2222

2323
export default async function multiDownload(urls = [], options = {}) {
24-
const { delay = 1000, rename = getName } = options;
24+
const { downloadInterval = 1000, rename = getName } = options;
2525
if (!urls?.length) {
2626
throw new Error("`urls` required");
2727
}
2828
if (urls.every((url) => typeof url !== "string")) {
2929
throw new Error("`urls` must be an array of strings");
3030
}
31-
if (typeof delay !== "number") {
32-
throw new Error("`delay` must be a number");
31+
if (typeof downloadInterval !== "number") {
32+
throw new Error("`downloadInterval` must be a number");
3333
}
3434
if (typeof rename !== "function") {
3535
throw new Error("`rename` must be a function");
@@ -38,7 +38,7 @@ export default async function multiDownload(urls = [], options = {}) {
3838
for (const [index, url] of urls.entries()) {
3939
const name = rename({ url, index, urls });
4040

41-
await delay(index * delay);
41+
await delay(index * downloadInterval);
4242
download(url, name);
4343
}
4444
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
22
"name": "multi-download",
3-
"version": "5.0.0",
3+
"version": "4.1.0",
44
"description": "Download multiple files at once in the browser",
55
"license": "MIT",
66
"repository": "sindresorhus/multi-download",
77
"author": {
88
"name": "Sindre Sorhus",
99
"email": "[email protected]",
10-
"url": "sindresorhus.com"
10+
"url": "https://sindresorhus.com"
1111
},
1212
"type": "module",
1313
"exports": "./index.js",
1414
"files": [
15-
"index.js"
15+
"index.js",
16+
"index.d.ts"
1617
],
1718
"typings": "index.d.ts",
1819
"keywords": [

readme.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ Type: `Function`
7474

7575
A function that accepts an object containing `url`, `index`, and `urls` properties and is expected to return the new filename.
7676

77-
##### delayTime
77+
##### downloadInterval
7878

7979
Type: `number`
8080

81-
Time in miliseconds to delay between each download
81+
The delay time between each file download in milliseconds.
8282

8383
```html
8484
<button id="download-button" data-files="unicorn.jpg rainbow.jpg">Download</button>
@@ -91,7 +91,18 @@ document.querySelector('#download-button').addEventListener('click', event => {
9191
const files = event.target.dataset.files.split(' ');
9292
multiDownload(files, {
9393
rename: ({url, index, urls}) => 'New name.pdf',
94-
delayTime: 500
94+
});
95+
});
96+
```
97+
98+
```js
99+
import multiDownload from 'multi-download';
100+
101+
document.querySelector('#download-button').addEventListener('click', event => {
102+
const files = event.target.dataset.files.split(' ');
103+
multiDownload(files, {
104+
rename: ({url, index, urls}) => 'New name.pdf',
105+
downloadInterval: 500
95106
});
96107
});
97108
```

0 commit comments

Comments
 (0)