esysplash v0.0.2-pre1
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
- type:
random(options: object) Generate a random image from a query or user.
options
- type:
Object
- optional: false
- options.query
- type:
String
- optional: true
- type:
- options.username
- type:
String
- optional: true
- type:
- options.featured
- type:
Boolean
- optional: true
- type:
- type:
download(id: string) Get a track download from a image id.
id
- type:
String
- optional: false
- type:
search(keyword: string, page: number, per: number) Search a keyword from a page.
keyword
- type:
String
- optional: false
- type:
page
- type:
Number
- optional: true
- type:
per
- type:
Number
- optional: true
- type:
list(page: number, per: number) List images from a certain page.
page
- type:
Number
- optional: true
- type:
per
- type:
Number
- optional: true
- type:
image(url: string) Return a image url by their body.
url
- type:
String
- optional: false
- type:
4 years ago
4 years ago