1-
21/**
3- This function is used to determine the filename for each downloaded file.
4- @param options - The options for renaming.
5- @returns The new filename for the downloaded file.
2+ @param options - The options for renaming.
3+
4+ @returns - The new filename for the downloaded file.
5+
6+ @description - This function is used to determine the filename for each downloaded file.
67*/
7- export type RenameFunction = ( options : { url : string ; index : number ; urls : string [ ] } ) => string ;
8+ export type RenameFunction = ( options : {
9+ url : string ;
10+ index : number ;
11+ urls : string [ ] ;
12+ } ) => string ;
813
914/*
1015 Options for the multiDownload function.
1116 */
12- export type MultiDownloadOptions = {
17+ export type Options = {
1318 /**
14- The function to rename the downloaded files.
15- @default undefined (use original filenames)
16- */
19+ @default undefined - (use original filenames)
20+
21+ @description - A function that returns the new filename for each downloaded file.
22+ */
1723 rename ?: RenameFunction ;
1824 /**
1925 The delay time between each file download in milliseconds.
@@ -23,36 +29,42 @@ export type MultiDownloadOptions = {
2329} ;
2430
2531/**
26- Download multiple files from an array of URLs.
27- @param urls - The URLs to download.
28- @param options - The options for downloading.
29- @returns A promise that resolves when all files have been downloaded.
32+ @param urls - The URLs to download.
33+
34+ @param options - The options for downloading.
35+
36+ @returns - A promise that resolves when all files have been downloaded.
37+
38+ @description - Download multiple files from an array of URLs.
39+
3040 @example
3141 ```
32- import { multiDownload } from ' multi-download' ;
42+ import { multiDownload } from " multi-download" ;
3343
3444 async function downloadFiles() {
35- const urls = [
36- 'https://example.com/file1.txt',
37- 'https://example.com/file2.txt',
38- 'https://example.com/file3.txt',
39- ];
40-
41- try {
42- await multiDownload(urls, {
43- rename: ({ url, index }) => `file${index + 1}.txt`,
44- downloadInterval: 1000,
45- });
46- console.log('Files downloaded successfully');
47- } catch (error) {
48- console.error('Error downloading files:', error);
49- }
45+
46+ const urls = [
47+ "https://example.com/file1.txt",
48+ "https://example.com/file2.txt",
49+ "https://example.com/file3.txt",
50+ ];
51+
52+ try {
53+ await multiDownload(urls, {
54+ rename: ({ url, index }) => `file${index + 1}.txt`,
55+ downloadInterval: 1000,
56+ });
57+ console.log("Files downloaded successfully");
58+ } catch (error) {
59+ console.error("Error downloading files:", error);
60+ }
61+
5062 }
5163
52- downloadFiles();
64+ await downloadFiles();
5365 ```
5466 */
5567export default function multiDownload (
5668 urls : string [ ] ,
57- options ?: MultiDownloadOptions
69+ options ?: Options
5870) : Promise < void > ;
0 commit comments