How to use the unsplash-js.default function in unsplash-js

To help you get started, we’ve selected a few unsplash-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saasify-sh / saasify / examples / typescript / meta-stock / lib / services / unsplash.js View on Github external
/**
 * Note: even though most APIs don't, unsplash specifically recommends
 * hotlinking their images, which makes our integration easier.
 */

'use strict'

// ugly hack required for unsplash client to work
global.fetch = require('node-fetch')

const { toJson, default: Unsplash } = require('unsplash-js')

const unsplash = new Unsplash({
  accessKey: process.env.UNSPLASH_ACCESS_KEY,
  secret: process.env.UNSPLASH_SECRET_KEY
})

const utm = '?utm_source=saasify&utm_medium=referral&utm_campaign=api-credit'

module.exports = async (opts) => {
  const { query, offset, limit } = opts

  const response = await unsplash.search.photos(
    query,
    1 + Math.ceil(offset / limit),
    limit
  )

  if (!response.ok) {
github silexlabs / CloudExplorer2 / lib / image-bank.js View on Github external
}
  if(offlineTestPath) {
    console.info('Unsplash: found offline test path', offlineTestPath)
    return {
      random: () => Promise.resolve(require(offlineTestPath).search)
        .then(formatUnsplashResult),
      search: (query) => Promise.resolve(require(offlineTestPath).search)
        .then(formatUnsplashResult),
    };
  }
  if(!accessKey || !appName) throw 'Unsplash bank image requires options: accessKey, appName.';
  const fetch = require('node-fetch');
  global.fetch = fetch;
  const Unsplash = require('unsplash-js').default;
  const {toJson} = require('unsplash-js');
  const unsplash = new Unsplash({ accessKey })
  return {
    random: () => unsplash.photos.listPhotos(1, 50)
      .then(toJson)
      .then(json => { return {
        total: json.length,
        pages: 1,
        results: json,
      }})
      .then(formatUnsplashResult),
    search: (query) => unsplash.search.photos(query, 1, 50)
      .then(toJson)
      .then(formatUnsplashResult),
  };
}
github jsdevkr / gitCodeShare.com / handlers / unsplash.js View on Github external
require('isomorphic-fetch');
const { default: Unsplash, toJson } = require('unsplash-js');

const WALLPAPER_COLLECTION_ID = 136026;

const client = new Unsplash({
  applicationId: process.env.UNSPLASH_ACCESS_KEY,
  secret: process.env.UNSPLASH_SECRET_KEY,
  callbackUrl: process.env.UNSPLASH_CALLBACK_URL,
});

const parseImageResult = img => ({
  id: img.id,
  photographer: {
    name: img.user.name,
    profile_url: img.user.links.html,
  },
  url: img.urls.small,
});

const getRandomImages = () =>
  client.photos
github CodingTrain / Eyeo-Festival-2019 / archived / Rainbow-Unsplash / index.js View on Github external
const Unsplash = require('unsplash-js').default;
const fetch = require('node-fetch');
global.fetch = fetch;
const fs = require('fs');
require('dotenv').config();

let all = [];

const unsplash = new Unsplash({
  applicationId: process.env.API_KEY,
  secret: process.env.API_SECRET
});

async function download(url, name) {
  const response = await fetch(url);
  const dest = fs.createWriteStream(`./images/regular/${name}.png`);
  response.body.pipe(dest);
}

getAll();
async function getAll() {
  for (let i = 1; i < 328; i++) {
    //let i = 300;
    try {
      const response = await unsplash.search.photos('rainbow', i, 20);

unsplash-js

Official JavaScript wrapper for the Unsplash API

MIT
Latest version published 4 months ago

Package Health Score

76 / 100
Full package analysis