How to use the unsplash-js.toJson 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
const response = await unsplash.search.photos(
    query,
    1 + Math.ceil(offset / limit),
    limit
  )

  if (!response.ok) {
    const err = new Error(
      `unsplash error ${response.status} "${response.statusText}"`
    )
    err.status = response.status
    throw err
  }

  const results = await toJson(response)

  if (results.results) {
    const sizes = ['small', 'regular'] // 'thumb', 'full'
    console.log(
      `unplash image search "${query}" => ${results.results.length} results (${results.total} total)`
    )

    const transformedResults = results.results
      .map((result) => {
        // console.log(JSON.stringify(result, null, 2))

        let largest = null
        let smallest = null

        for (let i = 0; i < sizes.length; ++i) {
          const image = result.urls[sizes[i]]

unsplash-js

Official JavaScript wrapper for the Unsplash API

MIT
Latest version published 4 months ago

Package Health Score

78 / 100
Full package analysis