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

unsplash-api

v1.2.0

Published

This is a wrapper for the Unsplash API

Downloads

7

Readme

#unsplash-api

Introduction

This is a Node.js wrapper for the Unsplash REST API.

The wrapper encloses all public and private endpoints provided by Unsplash at this time, and will be updated as changes are made. For more information on the data each function returns, visit the Unsplash REST API Documentation.

Installation

npm i --save unsplash-api

Usage

Initialization

Loading the Module

To load the Unsplash API wrapper:

var unsplash = require('unsplash-api');
.apiInit(clientId)

To initialize Unsplash using your client ID:

var clientId = 'dummyKey'; //this is required to verify your application's requests
unsplash.init(clientId);

This must be done for any of the following functions to return results. Client IDs can be obtained by signing up for the Unsplash REST API.

Public Scope Functions

Public scope functions require only a client ID, initialized using the function above.

.getUserByName(username, callback)

Retrieve information on a specific user. To access info by username:

unsplash.getUserByName('sampleUser', function(error, userInfo) {
   //Access user information here
});

More info on: get user.

.getUserPhotos(username, callback)

Retrieve a list of photos uploaded by a specific user. To access photos by username:

unsplash.getUserPhotos('sampleUser', function(error, photos) {
   //Access array of photos here
});

More info on: get user photos.

.getPhotos(page, perPage, callback)

Retrieve photos from a list of all photos. Results are organized by page, with a default of 10 results per page. The first/prev/next/last pages of results can be accessed through the link object. To access photos:

unsplash.getPhotos(null, null, function(error, photos, link) {
   //Access default 10 photos from first page of results here
});

//or

unsplash.getPhotos(2, 20, function(error, photos, link) {
   //Access 20 photos from second page of results here
});

More info on: get photos.

.searchPhotos(query, categories, page, perPage, callback)

Retrieve photos filtered by a specific query. Results are organized by page, with a default of 10 results per page, and can be furthered filter by specified categories. The first/prev/next/last pages of results can be accessed through the link object. To search photos:

unsplash.searchPhotos('sampleQuery', null, null, null, function(error, photos, link) {
   //Access default 10 photos from first page of search results here
});

//or

unsplash.searchPhotos('sampleQuery', [1, 2, 3], 2, 20, function(error, photos, link) {
   //Access 20 photos from second page of search results with filtering categories applied here
});

More info on: search photos.

.getPhoto(id, width, height, rect, callback)

Retrieve a single photo. The photo can be retreived with custom dimensions using width and height, or a specific portion of the photo can be obtained using the rect ([x, y, width, height]) parameter. To access a photo by ID:

unsplash.getPhoto(sampleID, null, null, null, function(error, photo) {
   //Access photo here
});

//or

unsplash.getPhoto(sampleID, 400, 200, null, function(error, photo) {
   //Access custom sized photo here
});

//or

unsplash.getPhoto(sampleID, null, null, [10, 10, 400, 200], function(error, photo) {
   //Access custom portion of photo here
});

More info on: get a photo.

.getAllCategories(callback)

Retrieve a list of all categories. To access categories:

unsplash.getAllCategories(function(error, categories) {
   //Access array of categories here
});

More info on: get categories.

.getCategory(categoryId, callback)

Retrieve info on a specific category. To access category info by ID:

unsplash.getCategory(sampleID, function(error, categoryInfo) {
   //Access category info here
});

More info on: get a category.

.getCategoryPhotos(categoryId, page, perPage, callback)

Retrieve photos by category. Results are organized by page, with a default of 10 results per page. The first/prev/next/last pages of results can be accessed through the link object. To access photos by category ID:

unsplash.getCategoryPhotos(sampleID, null, null, function(error, photos, link) {
   //Access default 10 photos from first page of category photos here
});

//or

unsplash.getCategoryPhotos(sampleID, 2, 20, function(error, photos, link) {
   //Access 20 photos from second page of category photos here
});

More info on: get category photos.

.getCuratedBatches(page, perPage, callback)

Retrieve a list of curated batches. Results are organized by page, with a default of 10 results per page. The first/prev/next/last pages of results can be accessed through the link object. To access curated batches:

unsplash.getCuratedBatches(null, null, function(error, batches) {
   //Access default 10 curated batches from first page here
});

//or

unsplash.getCuratedBatches(2, 20, function(error, batches) {
   //Access 20 batches from second page of curated batches here
});

More info on: get curated batches.

.getCuratedBatch(id, callback)

Retrieve info on a single curated batch. To access curated batch info by ID:

unsplash.getCuratedBatch(sampleID, function(error, batch) {
   //Access batch info here
});

More info on: get a curated batch.

.getCuratedBatchPhotos(id, callback)

Retrieve 10 photos from a curated batch. To access photos by curated batch ID:

unsplash.getCuratedBatchPhotos(sampleID, function(error, photos) {
   //Access curated batch photos here
});

More info on: get curated batch photos.

.getTotalStats(callback)

Retrieve total Unsplash download stats. To access stats:

unsplash.getTotalStats(function(error, stats) {
   //Access stats here
});

More info on: get stats.

Private Scope Functions

These functions require an OAuth2 generated token, which can be acquired using this workflow.

.getCurrentUser(token, callback)

Retrieve information on the current user. Requires read_user scope from authentication. To access user info:

unsplash.getCurrentUser('sampleToken', function(error, userInfo) {
   //Access current user info here
});

More info on: get current user.

.updateCurrentUser(token, changes, callback)

Change information for the current user. Requires write_user scope from authentication. To update user info:

var changes = {'username': 'newUsername', 'first_name': 'newName'};
unsplash.updateCurrentUser('sampleToken', changes, function(error, userInfo) {
   //Access updated current user info here
});

More info on: update current user.

.uploadPhoto(token, photo, callback)

Upload photo for the current user. Requires write_photos scope from authentication. To upload a photo:

unsplash.uploadPhoto('sampleToken', photoPath, function(error, photo) {
   //Access the newly uploaded photo here
});

More info on: upload photo.

License MIT

Disclaimer: We are not employees of Unsplash nor do we represent them in any way.