Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

img-dl

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

img-dl - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

dist/chunk-HYWEAAWU.js

10

dist/cli.js
#!/usr/bin/env node
import{a as i,b as d,c as g}from"./chunk-4WBFE7PX.js";import p from"cli-progress";import f from"meow";import h from"fs";import u from"path";var s=f(`
import{a as i,b as d,c}from"./chunk-HYWEAAWU.js";import p from"cli-progress";import f from"meow";import h from"fs";import u from"path";var s=f(`
USAGE

@@ -18,4 +18,6 @@ $ imgdl <url> ... [OPTIONS]

-n, --name=<filename> The filename. Default: original filename or timestamp
--max-retry=<number> Set the maximum number of times to retry the request if it fails
--silent Disable logging
--start=<number> The start index for increment mode. Default: 0
-t, --timeout=<number> Set timeout for each request in milliseconds
-v, --version Show the version number

@@ -29,5 +31,5 @@

$ imgdl https://example.com/image-{i}.jpg --increment --start=1 --end=10
`,{importMeta:import.meta,description:"Download an image from a URL",booleanDefault:void 0,flags:{dir:{shortFlag:"d",type:"string"},ext:{shortFlag:"e",type:"string"},increment:{shortFlag:"i",type:"boolean"},start:{type:"number"},end:{type:"number"},name:{shortFlag:"n",type:"string"},silent:{type:"boolean"}}});async function w(){let t=s.input,{flags:e}=s;if(t.length||s.showHelp(),e.increment){if(t.length>1)throw new i("Only one URL is allowed in increment mode");let n=t[0];if(!n.includes("{i}"))throw new i("The URL must contain {i} placeholder for the index");if(!e.end)throw new i("The end index is required in increment mode");if(e.start&&e.start>e.end)throw new i("The start index cannot be greater than the end index");let{start:l=0,end:c}=e;t=[];for(let m=l;m<=c;m+=1)t.push(n.replace("{i}",m.toString()))}e.silent||console.log(`
Downloading...`);let o=new p.SingleBar({format:"{percentage}% [{bar}] {value}/{total} | Success: {success} | ETA: {eta_formatted} | Elapsed: {duration_formatted}",hideCursor:null,barsize:24}),a=0,r=0;!e.silent&&t.length>1&&o.start(t.length,0,{success:a}),await g(t.length===1?t[0]:t,{directory:e.dir,name:e.name,extension:e.ext,onSuccess:()=>{e.silent||(a+=1,o.increment({success:a}))},onError:(n,l)=>{if(r+=1,e.silent||o.increment(),n instanceof i||n instanceof d)throw n;h.appendFileSync(u.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${l}, ${n.name}: ${n.message}
`)}}),e.silent||(o.stop(),console.log("Done!"),r&&console.log(`${r} image${r>1?"s":""} failed to download. See ./error.log for details.`))}w().catch(t=>{console.error(`${t.name}: ${t.message}`),process.exit(1)});
`,{importMeta:import.meta,description:"Download an image from a URL",booleanDefault:void 0,flags:{dir:{shortFlag:"d",type:"string"},ext:{shortFlag:"e",type:"string"},increment:{shortFlag:"i",type:"boolean"},start:{type:"number"},end:{type:"number"},name:{shortFlag:"n",type:"string"},maxRetry:{type:"number"},silent:{type:"boolean"},timeout:{shortFlag:"t",type:"number"}}});async function x(){let t=s.input,{flags:e}=s;if(t.length||s.showHelp(),e.increment){if(t.length>1)throw new i("Only one URL is allowed in increment mode");let n=t[0];if(!n.includes("{i}"))throw new i("The URL must contain {i} placeholder for the index");if(!e.end)throw new i("The end index is required in increment mode");if(e.start&&e.start>e.end)throw new i("The start index cannot be greater than the end index");let{start:m=0,end:g}=e;t=[];for(let l=m;l<=g;l+=1)t.push(n.replace("{i}",l.toString()))}e.silent||console.log(`
Downloading...`);let o=new p.SingleBar({format:"{percentage}% [{bar}] {value}/{total} | Success: {success} | ETA: {eta_formatted} | Elapsed: {duration_formatted}",hideCursor:null,barsize:24}),a=0,r=0;!e.silent&&t.length>1&&o.start(t.length,0,{success:a}),await c(t.length===1?t[0]:t,{directory:e.dir,name:e.name,extension:e.ext,onSuccess:()=>{e.silent||(a+=1,o.increment({success:a}))},onError:(n,m)=>{if(r+=1,e.silent||o.increment(),n instanceof i||n instanceof d)throw n;h.appendFileSync(u.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${m}, ${n.name}: ${n.message}
`)},maxRetry:e.maxRetry,timeout:e.timeout}),e.silent||(o.stop(),console.log("Done!"),r&&console.log(`${r} image${r>1?"s":""} failed to download. See ./error.log for details.`))}x().catch(t=>{console.error(`${t.name}: ${t.message}`),process.exit(1)});
//# sourceMappingURL=cli.js.map

@@ -21,2 +21,8 @@ type DownloadOptions = {

/**
* Set the maximum number of times to retry the request if it fails.
*
* @default 2
*/
maxRetry?: number;
/**
* The extension of the image.

@@ -29,2 +35,6 @@ *

extension?: string;
/**
* Set timeout for each request in milliseconds.
*/
timeout?: number;
};

@@ -31,0 +41,0 @@

2

dist/index.js

@@ -1,2 +0,2 @@

import{c as a}from"./chunk-4WBFE7PX.js";export{a as default};
import{c as a}from"./chunk-HYWEAAWU.js";export{a as default};
//# sourceMappingURL=index.js.map
{
"name": "img-dl",
"version": "0.1.0",
"version": "0.2.0",
"description": "Download public image(s), by command or programmatically",

@@ -56,2 +56,3 @@ "type": "module",

"cli-progress": "^3.12.0",
"got": "^13.0.0",
"meow": "^12.1.1",

@@ -58,0 +59,0 @@ "sanitize-filename": "^1.6.3"

# img-dl
Downloade image(s), by command or programmatically
Downloade image(s), by command or programmatically. The alternative for `image-downloader` package (see the [comparison](#comparison)).
[![MIT license](https://img.shields.io/github/license/fityannugroho/img-dl.svg)](https://github.com/fityannugroho/img-dl/blob/main/LICENSE)
[![npm version](https://img.shields.io/npm/v/img-dl.svg)](https://www.npmjs.com/package/img-dl)
[![npm downloads](https://img.shields.io/npm/dm/img-dl.svg)](https://www.npmjs.com/package/img-dl)
[![install size](https://packagephobia.com/badge?p=img-dl)](https://packagephobia.com/result?p=img-dl)
## Prerequisites

@@ -50,4 +56,6 @@

-n, --name=<filename> The filename. Default: original filename or timestamp
--max-retry=<number> Set the maximum number of times to retry the request if it fails
--silent Disable logging
--start=<number> The start index for increment mode. Default: 0
-t, --timeout=<number> Set timeout for each request in milliseconds
-v, --version Show the version number

@@ -129,3 +137,3 @@

Type: `Options` <br>
Type: [`Options`](https://github.com/fityannugroho/img-dl/blob/main/src/index.ts#L35) <br>
Required: `false`

@@ -135,6 +143,30 @@

| --- | --- | --- | --- |
| `options.directory` | `string` | `process.cwd()` | The output directory |
| `options.extension` | `string` | `'jpg'` | The file extension. If not specified, the original extension will be used. If the original extension is not available, `'jpg'` will be used. |
| `options.name` | `string` | `'image'` | The filename. If not specified, the original filename will be used. If the original filename is not available, `'image'` will be used. <br>When downloading multiple images, `-index` will be appended to the end of the name (suffix). `index` will start from 1. For example: `image-1` |
| `options.onSuccess` | `(image: Image) => void` | `undefined` | The callback function to be called when the image is successfully downloaded. Only available when downloading multiple images. |
| `options.onError` | `(error: Error, url: string) => void` | `undefined` | The callback function to be called when the image fails to download. Only available when downloading multiple images. |
| `directory` | `string` | `process.cwd()` | The output directory |
| `extension` | `string` | jpg | The file extension. If not specified, the original extension will be used. If the original extension is not available, 'jpg' will be used. |
| `name` | `string` | image | The filename. If not specified, the original filename will be used. If the original filename is not available, 'image' will be used. <br>When downloading multiple images, `-index` will be appended to the end of the name (suffix). `index` will start from 1. For example: 'image-1' |
| `maxRetry` | `number` | 2 | Set the maximum number of times to retry the request if it fails.
| `onSuccess` | `(image: Image) => void` | `undefined` | The callback function to be called when the image is successfully downloaded. Only available when downloading multiple images. |
| `onError` | `(error: Error, url: string) => void` | `undefined` | The callback function to be called when the image fails to download. Only available when downloading multiple images. |
| `timeout` | `number` | `undefined` | Set timeout for each request in milliseconds.
## Comparison
| Features | **img-dl** | [image-downloader][p1] |
| --- | :---: | :---: |
| Download single image | ✅ | ✅ |
| Download multiple images | ✅ | ❌ |
| CLI | ✅ | ❌ |
| Increment download | ✅ | ❌ |
| Custom filename | ✅ | ✅ |
| Custom extension | ✅ | ❌ |
| Request timeout | ✅ | ✅ |
| Retry failed request | ✅ | ❌ |
<!-- Project links -->
[p1]: https://www.npmjs.com/package/image-downloader
## Support This Project
Give a ⭐️ if this project helped you!
You can support this project by donating via [GitHub Sponsors](https://github.com/sponsors/fityannugroho), [Trakteer](https://trakteer.id/fityannugroho/tip), or [Saweria](https://saweria.co/fityannugroho).

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc