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

@smarthost/feathers-unsplash

v0.0.12

Published

Feathersjs wrapper for querying the unsplash api

Downloads

8

Readme

@smarthost/feathers-unsplash

FeathersJS service adapter for querying the Unsplash API

npm version build

About

This project uses Feathers. An open source web framework for building modern real-time applications.

It is built on top of the official unsplash-js package.

This is a fork and update of marshallswain/feathers-unsplash

Supported Services

Below is a list of all exposed services and their implemented methods. All can be used like the UnsplashPhotos example given below

  • UnsplashPhotos (find, get)
  • UnsplashPhotoStatistics (get)
  • UnsplashTrackPhotos (create)
  • UnsplashCollections (find, get)
  • UnsplashCollectionPhotos (find)
  • UnsplashRelatedCollections (get)
  • UnsplashTopics (find, get)
  • UnsplashTopicPhotos (find)
  • UnsplashUsers (find, get)
  • UnsplashUserPhotos (find)
  • UnsplashUserCollections (find)
  • UnsplashUserLikes (find)

More documentation coming soon

Install

npm install @smarthost/feathers-unsplash node-fetch unsplash-js

yarn add @smarthost/feathers-unsplash node-fetch unsplash-js

Other packages needed may be: tslib, @feathersjs/errors

This adapter requires fetch support, which means you'll need to provide it on the global scope. This means that somewhere in your app you need to use this code:

// preferably in the the index file
const fetch = require("node-fetch");
global.fetch = fetch;

// typescript
import fetch from "node-fetch";
global.fetch = fetch as any; // trick for type imcompatibility for now

Setup API Access

First you'll need to setup Unsplash API access.

  1. Create an app on the Unsplash API
  2. Copy the accessKey into an environment variable.
  3. Setup the FeathersJS config
// default.json

"unsplash": {
    "accessKey": "MYAPPNAME_UNSPLASH_ACCESS_KEY"
}

Setup a Service

The easiest way to setup a service is to use the FeathersJS Cli to generate a "Custom Service". You can then delete the service-name.class.js file that the generator makes and use code like in this example:

// Initializes the `unsplash-photos` service on path `/unsplash-photos`
const { UnsplashPhotos } = require("@smarthost/feathers-unsplash");
const hooks = require("./unsplash-photos.hooks");

module.exports = function (app) {
  const options = {
    accessKey: app.get("unsplash").accessKey,
  };

  // Initialize the service with any options it requires
  app.use("/unsplash-photos", new UnsplashPhotos(options, app));

  // Get the initialized service so that we can register hooks
  const service = app.service("unsplash-photos");

  service.hooks(hooks);
};

API

find

The find method supports searching photos by the following query params:

  • keyword: the search text
  • orientation: can be either portrait or landscape. Any other values return an empty list.
  • collectionIds: an array of collection ids.
  • also other parameters supported by the unsplash wrapper. search.getPhotos

It also supports familiar pagination attributes: $limit and $skip. Note that since the Unsplash API only supports page-level pagination (not record-level skipping like most FeathersJS adapters), you must provide $skip as a multiple of the $limit. Here is an example query:

const response = await app.service('unsplash-photos').find({
  query: {
    $limit: 10, // this is the default limit
    $skip: 10 // Skipping 10 returns the second page of data.
    keyword: 'food',
    orientation: 'portrait',
  }
})

get

The get method can be used in two ways:

  • Pass an image id to retrieve data about the image.
  • Pass 'random' to retrieve a random image. See possible params for photos.getRandom
const imageData = await app.service("unsplash-photos").get(id);
const randomImageData = await app.service("unsplash-photos").get("random");

Help

For more information on all the things you can do with Feathers visit docs.feathersjs.com.