npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

picscout

v1.3.0

Published

Search for images using Google, Bing and DuckDuckGo

Downloads

10

Readme

PicScout

npm codecov

PicScout is an NPM module that allows you to search for images using various search engines, currently included ones are Google, Bing and DuckDuckGo.

Installation

To install the package, use the following command:

npm install picscout

Usage

Here's an example of how to use the package in your code:

const PicScout = require('picscout').default;

(async () => {
  const res = await PicScout.search('cats');
  console.log(res);
})();

Output:

[
    {
        "url": "https://upload.wikimedia.org/wikipedia/commons/b/bc/Juvenile_Ragdoll.jpg",
        "width": 3336,
        "height": 3000
    },
    {
        "url": "https://upload.wikimedia.org/wikipedia/commons/1/15/Cat_August_2010-4.jpg",
        "width": 3640,
        "height": 2226
    },
    {
        "url": "https://cdn.britannica.com/39/7139-050-A88818BB/Himalayan-chocolate-point.jpg",
        "width": 930,
        "height": 620
    }
]

Note: The returned URLs are not guaranteed to work 100% of the time, some of the URLs might be broken.

Additional Options

The search method of PicScout supports additional options for more control over the search behavior.

Search Engine Option

You can specify the search engine to be used by passing the engine option with the desired value, such as 'google', 'bing' or 'duckduckgo':

const PicScout = require('picscout').default;

(async () => {
  const res = await PicScout.search('cats', { engine: 'bing' });
  console.log(res);
})();

In the above example, the search will be performed using the Bing search engine. The default engine is 'google'.

Safe Search Option

To enable safe search mode and filter out explicit content from the search results, you can pass the safe option as true:

const PicScout = require('picscout').default;

(async () => {
  const res = await PicScout.search('cats', { safe: true });
  console.log(res);
})();

In the above example, the search results will only include images considered safe for all audiences.

Additional Query Parameters Option

You can also include additional query parameters in the search request by using the additionalQueryParams option. It accepts a URLSearchParams instance:

const PicScout = require('picscout').default;

(async () => {
  const additionalParams = new URLSearchParams();
  additionalParams.set('testparam', 'test');

  // Will call: http://images.google.com/search?tbm=isch&q=cats&testparam=test
  const res = await PicScout.search('cats', {
    additionalQueryParams: additionalParams,
  });
  console.log(res);
})();

In the above example, the search request will include an additional query parameter testparam with the value 'test'. You can customize the additional query parameters as needed.

Global Parameters

The PicScout instance allows you to define some of the parameters globally, which will be used as defaults for the search method. However, if you specify a parameter in the method call, it will take precedence over the global value. Here are the available global parameters:

  • userAgent (if not defined, a random one will be generated for each call)
  • safe (default: false)
  • engine (default: 'google')

For example, to set the global safe parameter to true and the engine parameter to 'bing', you can do the following:

const PicScout = require('picscout').default;

PicScout.safe = true;
PicScout.engine = 'bing';

(async () => {
  const res = await PicScout.search('cats');
  console.log(res);
})();

In the above example, the search will be performed with safe search enabled and using the Bing search engine. If you pass a different value for any of these parameters in the method call, it will override the global setting.

Acknowledgments

This package started off based on the g-i-s package by Jim Kang. Please check it out as well.