2.0.1 • Published 8 months ago

@mudbill/duckduckgo-images-api v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

duckduckgo-images-api

Based on KshitijMhatre's version as it has been unmaintained.

A lightweight library to programmatically obtain image search results from DuckDuckGo's search engine.

Usage

To install:

# npm
npm install @mudbill/duckduckgo-images-api

# bun
bun add @mudbill/duckduckgo-images-api

TypeScript definitions are included.

The package provides a simple async/await API:

const images = await imageSearch({
    // the search term
    query: "pikachu",

    // filter by safe search (default true)
    safe: true, 
    
    // number of result sets to fetch (default 1)
    // each set includes up to 100 images
    iterations: 1, 
    
    // number of retries if a query fails
    retries: 2, 
})

The imageSearch function returns a Promise that resolves to an array of complete results.

imageSearch({ query: "birds", safe: true })
    .then((results) => console.log(results));

The imageSearchGenerator function is an async generator that yields a Promise of each result set. Useful for large iterations.

for await (let resultSet of imageSearchGenerator({
    query: "birds",
    safe: true,
    iterations: 4,
})) {
    // 4 loops of 100 images each
    console.log(resultSet);
}

Please feel free to report any issues or feature requests.

Note

DuckDuckGo provides an instant answer API. This package does not use this route. This package mocks the browser behaviour using the same request format. Use it wisely.

2.0.1

8 months ago

2.0.0

8 months ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago