0.0.2-pre1 ā€¢ Published 4 years ago

esysplash v0.0.2-pre1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Install the Esysplash by using the npm install command. By default, Esysplash will install automatically the unsplash-js, node-fetch and others packages.

šŸ‘‰ npm install esysplash

But... you can install these packages yourself by using the command below with the default packages šŸ‘‰ isn't recommended šŸ‘ˆ. In anotherpkg you must place the packages that will be installed.

šŸ‘‰ npm install esysplash unsplash-js node-fetch anotherpkg anotherpkg

First, you need to connect the Esysplash to your Unsplash application using the access_key given by the application itself. The function parameters/arguments is Esysplash.connect(access_key: string). View more at the docs šŸ‘‰ here.

šŸšØ Remembering that the key must be very well protected with security, as it is your own access key. šŸšØ

const Esysplash = require('esysplash');
Esysplash.connect('my_access_key');

Or also use dotenv variables. šŸ‘‡

require('dotenv').config();

const Esysplash = require('esysplash');
Esysplash.connect(process.env.MY_ACCESS_KEY);

Once you have done all of these processes, you can now use Esysplash as you wish, using functions like random, that will give you a random image body. ā˜ The random function will only generate the body of an image as a url, with information from it.To obtain the url for that image, use the image function with the body url of that image.

Esysplash.random({ query: 'cars' }).then(async(image) => {
  const url = await Esysplash.image(image);
  console.log(url);
  /*
  {
    raw: 'https://images.unsplash.com/photo-1534862262637-373c120dcbcc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjE3NDMyN30',
    full: 'https://images.unsplash.com/photo-1534862262637-373c120dcbcc?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE3NDMyN30',
    regular: 'https://images.unsplash.com/photo-1534862262637-373c120dcbcc?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjE3NDMyN30',
    small: 'https://images.unsplash.com/photo-1534862262637-373c120dcbcc?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE3NDMyN30',
    thumb: 'https://images.unsplash.com/photo-1534862262637-373c120dcbcc?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjE3NDMyN30'
  }
  */
});

View below a example of a cars random image script.

const fetch = require('node-fetch');

Esysplash.random({ query: 'cars' }).then((_) => {
  // Get data from the image (optional):
  //  fetch(_)
  //  .then((res) => res.json())
  //  .then((response) => {});
  // Get images from the image body url.
  const images = await Esysplash.image(_);
  // Returns { raw: "raw img", full: "... }
}).catch(console.error);

Documentation

connect(access_key: string) Connect to Esysplash wrapper for Unsplash developers API.

  • access_key
    • type: String
    • optional: false

random(options: object) Generate a random image from a query or user.

  • options
    • type: Object
    • optional: false
    • options.query
      • type: String
      • optional: true
    • options.username
      • type: String
      • optional: true
    • options.featured
      • type: Boolean
      • optional: true

download(id: string) Get a track download from a image id.

  • id
    • type: String
    • optional: false

search(keyword: string, page: number, per: number) Search a keyword from a page.

  • keyword
    • type: String
    • optional: false
  • page
    • type: Number
    • optional: true
  • per
    • type: Number
    • optional: true

list(page: number, per: number) List images from a certain page.

  • page
    • type: Number
    • optional: true
  • per
    • type: Number
    • optional: true

image(url: string) Return a image url by their body.

  • url
    • type: String
    • optional: false