Socket
Socket
Sign inDemoInstall

stocksnap.io

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stocksnap.io - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

68

index.js

@@ -5,12 +5,22 @@ //index.js

//General function for getting images
//Variables:
//query:(string) Search term, can be null (will default to no search).
//options:(object) can contain:
// sort:(string) Source of images by sort by pages, can be relevance (when using a search query), date, trending, views, downloads and favorites.
// pages:(int) Amount of pages you want to rip.
// shuffle:(bool) If you want to shuffle the final array for a more random array of photos.
// highres:(bool) If you want the image links referencing to the downloadable high res images instead of the thumbnails.
//fn:(function) Callback that gives an array with photos as a variable.
/**
* Module for getting stockphotos from stocksnap.io
* @module stocksnap.io
* @author Bram van der Veen <96aa48@gmail.com>
*/
module.exports = get;
/**
* Function for getting images from stocksnap.io
* @param {string} query - the search query for the image request.
* @param {Object} options - options object
* @param {string} options.sort - Sort method of images by : page, relevance, date, tredning, views, downloads and favotires.
* @param {int} options.pages - Amount of pages you want to crawl.
* @param {bool} options.shuffle - If true will shuffle the final array of images that are returned
* @param {bool} options.highres - If true the image links will reference downloadable high res images instead of thumbnails
* @param {bool} - options.one - If true will only return one image instead of an array.
* @param {function} fn - Callback that gives an array with photos as a variable
*/
function get(query, options, fn) {

@@ -20,22 +30,20 @@ if (!fn) throw 'You didn\'t specify a callback function.';

if (query) {
var link = 'https://stocksnap.io/search/' + query + '/sort/' + (options.sort || 'relevance') + '/desc';
rip_photos(link, options, function (arr) {
if (options.shuffle) arr = shuffle(arr);
fn(arr);
})
}
else {
var link = 'https://stocksnap.io/view-photos/sort/' + (options.sort || 'trending') + '/desc';
rip_photos(link, options, function (arr) {
if (options.shuffle) arr = shuffle(arr);
fn(arr);
});
}
if (query) var link = 'https://stocksnap.io/search/' + query + '/sort/' + (options.sort || 'relevance') + '/desc';
else var link = 'https://stocksnap.io/view-photos/sort/' + (options.sort || 'trending') + '/desc';
ripPhotos(link, options, function (arr) {
if (options.shuffle) arr = shuffle(arr);
if (!options.one) fn(arr);
else fn(arr[0]);
});
}
//Function for ripping photos from the provided links.
//Not accessible via the module.
/**
* Function for ripping photos from the provided links (only accessible by the module)
* @param {string} link - Link to a stocksnap page
* @param {Object} options - Options object (same as get() options object)
* @param {function} fn - Callback function
*/
function rip_photos(link, options, fn) {
function ripPhotos(link, options, fn) {
var arr = [];

@@ -73,3 +81,7 @@ var done = 0;

//Function for shuffling the array when scrambling is set to true.
/**
* Function for shuffeling a supplied array
* @param {Object[]} o - Array that needs to be shuffled
* @returns {Object[]} o - Shuffled array
*/
function shuffle(o) {

@@ -79,3 +91,1 @@ for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);

}
module.exports = get;
{
"name": "stocksnap.io",
"version": "0.1.3",
"version": "0.1.4",
"description": "A make-shift api interpreter for stocksnap.io",

@@ -5,0 +5,0 @@ "repository": {

@@ -18,1 +18,6 @@ //test.js

});
//Getting just one photo of a girl
stocksnap('girl', {one: true}, function (snaps) {
console.log('Just a girl', snaps);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc