-
-
Notifications
You must be signed in to change notification settings - Fork 50
Feature/improvements #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
06e6646
19904f7
c7a6156
ee18568
d6ffd84
9d98e0c
84317ca
77e682e
3e74bc2
a59c04c
22bfef2
9391fa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||
| /** | ||||||
| @param options - The options for renaming. | ||||||
| @returns - The new filename for the downloaded file. | ||||||
| @description - This function is used to determine the filename for each downloaded file. | ||||||
| */ | ||||||
| export type RenameFunction = (options: { | ||||||
| url: string; | ||||||
| index: number; | ||||||
| urls: string[]; | ||||||
| }) => string; | ||||||
|
|
||||||
| /* | ||||||
| Options for the multiDownload function. | ||||||
| */ | ||||||
| export type Options = { | ||||||
| /** | ||||||
| @default undefined - (use original filenames) | ||||||
| @description - A function that returns the new filename for each downloaded file. | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing example like in the readme. |
||||||
| */ | ||||||
| rename?: RenameFunction; | ||||||
| /** | ||||||
| The delay time between each file download in milliseconds. | ||||||
| @default 1000 | ||||||
| */ | ||||||
| downloadInterval?: number; | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
| @param urls - The URLs to download. | ||||||
| @param options - The options for downloading. | ||||||
| @returns - A promise that resolves when all files have been downloaded. | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the correct TSDoc syntax. Applies to the everything else too.
Suggested change
|
||||||
| @description - Download multiple files from an array of URLs. | ||||||
| @example | ||||||
| ``` | ||||||
| import { multiDownload } from "multi-download"; | ||||||
| async function downloadFiles() { | ||||||
| const urls = [ | ||||||
| "https://example.com/file1.txt", | ||||||
| "https://example.com/file2.txt", | ||||||
| "https://example.com/file3.txt", | ||||||
| ]; | ||||||
| try { | ||||||
| await multiDownload(urls, { | ||||||
| rename: ({ url, index }) => `file${index + 1}.txt`, | ||||||
| downloadInterval: 1000, | ||||||
| }); | ||||||
| console.log("Files downloaded successfully"); | ||||||
| } catch (error) { | ||||||
| console.error("Error downloading files:", error); | ||||||
| } | ||||||
| } | ||||||
| await downloadFiles(); | ||||||
| ``` | ||||||
| */ | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is messy code style wise. You are mixing spaces with tabs and the formatting is completely off. Use the formatting shown in https://github.com/sindresorhus/typescript-definition-style-guide#documentation Use single-quotes. |
||||||
| export default function multiDownload( | ||||||
| urls: string[], | ||||||
| options?: Options | ||||||
| ): Promise<void>; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,12 @@ Type: `Function` | |
|
|
||
| A function that accepts an object containing `url`, `index`, and `urls` properties and is expected to return the new filename. | ||
|
|
||
| ##### downloadInterval | ||
|
|
||
| Type: `number` | ||
|
|
||
| The delay time between each file download in milliseconds. | ||
|
Comment on lines
+77
to
+81
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the wrong location. Please look at the readme and you'll see that the below code example is for the |
||
|
|
||
| ```html | ||
| <button id="download-button" data-files="unicorn.jpg rainbow.jpg">Download</button> | ||
| ``` | ||
|
|
@@ -84,7 +90,19 @@ import multiDownload from 'multi-download'; | |
| document.querySelector('#download-button').addEventListener('click', event => { | ||
ismi29ch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const files = event.target.dataset.files.split(' '); | ||
| multiDownload(files, { | ||
| rename: ({url, index, urls}) => 'New name.pdf' | ||
| rename: ({url, index, urls}) => 'New name.pdf', | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| ```js | ||
| import multiDownload from 'multi-download'; | ||
|
|
||
| document.querySelector('#download-button').addEventListener('click', event => { | ||
| const files = event.target.dataset.files.split(' '); | ||
| multiDownload(files, { | ||
| rename: ({url, index, urls}) => 'New name.pdf', | ||
| downloadInterval: 500 | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optionsis the wrong term here. They are not options.