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

pixabayjs

v2.0.5

Published

Pixabay API client wrapper

Downloads

23

Readme

pixabayjs

build status

A Javascript Wrapper for the Pixabay API. To learn more about Pixabay, read the docs.

Installation

npm i pixabayjs

Example Usage

var pixabay = require('pixabayjs');

// Authenticate the client to make requests
pixabay.authenticate('username', 'api_key');

// Set default query parameters to make with every request
pixabay.defaults = {safesearch: true};

// Get a ResultList
var search = ['dogs', 'puppies'];
var options = {editors_choice: true};
var onSuccess = function(response) {
  console.log('Success');
  return response;
};
var onFailure = function(response) {
  console.log('Failure');
  return response;
};

var resultList = pixabay.resultList(search, options, onSuccess, onFailure);

// Get a promise for a page of results
var resultsPromise = resultList.next(); // page 1

// Get a promise for the next page of results
var resultsPromise2 = resultList.next(); // page 2

// Get the previous page of results
var resultPromise3 = resultList.previous(); // cached promise for page 1

Development

  1. Install dependencies:

    npm install

  2. Run tests:

    npm test

API

pixabay

The high level client wrapper used to set authentication, set default query parameters, and create ResultLists.

authenticate pixabay.authenticate(apiKey)

authenticate is used to set your apiKey, provided to you from Pixabay, on the client. The values are used each time a ResultList is created.

defaults pixabay.defaults

Use defaults to set default query parameters for each created ResultList. Takes an object.

imageResultList pixabay.imageResultList(search, options, onSuccess, onFailure)

Returns a ResultList instance using the authentication credentials and defaults previously set.

  • search: Array of search terms
  • options: Object of key-value pairs to set the query parameters sent with the request to Pixabay. See the documentation for a list of supported query parameters.
    • Note: Do not set q. Use the search argument instead.
  • onSuccess: A function called on a successful response.
  • onFailure: A function called on a failed response.

videoResultList pixabay.videoResultList(search, options, onSuccess, onFailure)

Returns a ResultList instance using the authentication credentials and defaults previously set.

  • search: Array of search terms
  • options: Object of key-value pairs to set the query parameters sent with the request to Pixabay. See the documentation for a list of supported query parameters.
    • Note: Do not set q. Use the search argument instead.
  • onSuccess: A function called on a successful response.
  • onFailure: A function called on a failed response.
Callbacks

The callbacks should take a response argument, which is the processed response from the request. See below for what the response object looks like.

ResultList

A generator that makes requests to Pixabay and returns a promise for each.

next ResultList.next()

Returns a promise for the next page of results. Normally begins with the first page, but the initial page can be set by setting the page key in the options passed into pixabay.resultList().

previous ResultList.previous()

Returns a promose for the previous page of results. Will throw an error when requesting pages numbered <= 1;

Pixabay Results

By default, a response will be in the following form:

{
    error: null,
    page: 1,
    hits: [
        {
           id_hash: '779def4966ad3741-1356479553',
           type: 'photo',
           thumbURL: 'https://pixabay.com/get/d665608aa966adad0e6e/1356479553/ef2c43ccb41a18d6_68.jpg',
           previewURL: 'https://pixabay.com/get/d665608aa966adad0e6e/1356479553/28d20b56447d87bf_150.jpg',
           previewWidth: 150,
           previewHeight: 112,
           webformatURL: 'https://pixabay.com/get/d665608aa966adad0e6e/1356479553/286a88431d7a9651_640.jpg',
           webformatWidth: 640,
           webformatHeight: 480,
           largeImageURL: 'https://pixabay.com/get/d665608aa966adad0e6e/1356479553/14f48b3f589431efa50561c7_1280.jpg',
           fullHDURL: 'https://pixabay.com/get/d665608aa966adad0e6e/1356479553/e1849b5c833c6dc8554eded5_1920.jpg',
           imageURL: 'https://pixabay.com/get/d665608aa966adad0e6e/1356479553/94f19b8545cf5355895bbcfa.jpg',
           imageWidth: 3264,
           imageHeight: 2448,
           vectorURL: 'https://pixabay.com/get/d665608aa966adad0e6e/1356479553/fd35g48942gfzs8d9zfs98df.svg',
           user: 'WikiImages'
       },
    ],
    totalHits: 199,
    totalPages: 4
}

The error and page keys are set by Pixabayjs for convenience. When an error occurs, error will be set to the error's text, page will contain the requested page, totalHits and totalPages will be null, and hits will be an empty array.

License

MIT