Miss any of our Open RFC calls?Watch the recordings here! »

random-image-js

1.1.5 • Public • Published

Random Image JS

A javascript package for fetching random memes and wallpapers. Fetched images are scraped from reddit.

Features:

  • Bulk memes
  • Bulk wallpapers
  • Customizable
  • Lightweight

PHP package is available at Packagist.

Homepage

Installation

Install via NPM

npm install --save random-image-js

Usage

Available functions:

  • getMemes()
  • getWallpapers()
import randomImageJs from 'random-image-js';
#or
var randomImageJs = require('random-image-js');
 
-------------------
-------------------
 
 
//use with await
await randomImageJs.getMemes(); //returns 1 meme 
await randomImageJs.getWallpapers(); //returns 1 wallpaper
 
 
//use with callback
randomImageJs.getMemes().then(response => {}); //returns 1 meme
randomImageJs.getWallpapers().then(response => {});//returns 1 wallpaper
 
 
//options
await randomImageJs.getWallpapers({ get: 50 }); //returns 50 wallpapers 
 
await randomImageJs.getMemes({ 
    get: 50, 
    addSubReddit: ['memes', 'funny'], 
    removeSubReddit: ['dankmemes'] 
}); //returns 50 memes by filtering
 
 
//can be use other than fetching memes and wallpapers
//use as cat image fetcher
await randomImageJs.getMemes({ 
    get: 50, 
    removeAllSubReddit: true, 
    addSubReddit: ['cats', 'Catswhoyell', 'sleepingcats'] 
}); //returns 50 cat images

Result

The functions are asynchronous functions and return array.

[
  {
    id: "hfh51v",
    title: "Illuminated City at Night [1920 x 1200]",
    postLink: "https://redd.it/hfh51v",
    image: "https://i.redd.it/b6x9i2n830751.jpg",
    thumbnail: "https://b.thumbs.redditmedia.com/mLCk8Bh0N4M8hZafHsbAmw8rM7JEEznsT2nRZSo3GsU.jpg",
    subreddit: "wallpaper",
    NSFW: false,
    spoiler: false,
    createdUtc: 1593066557,
    
  },
  {
    id: "h9glhi",
    title: "Missing Home by Just Jaker",
    postLink: "https://redd.it/h9glhi",
    image: "https://cdnb.artstation.com/p/assets/images/images/027/020/665/large/just-jaker-galax-noise.jpg",
    thumbnail: "https://b.thumbs.redditmedia.com/4utBLNbsIDDLl46z494PCRkDhmAnapQq9FL7l-07aJo.jpg",
    subreddit: "ImaginaryFuturism",
    NSFW: false,
    spoiler: false,
    createdUtc: 1592228591
  }
]

Options

Property Type Description Default
get int How many images to get. Max is 50. 1
addSubReddit array Add subreddits to subreddit library. [ ]
removeSubReddit array Remove subreddits from subreddit library. [ ]
removeAllSubReddit boolean Remove all subreddits from subreddit library. false
searchLimit int Max reddit posts to search. Max is 100. 100

Browser Compatibility

Browser Works?
Chrome
Firefox
Safari
IE 11

Demo

See the package in action Here.

Try it on RunKit

License

MIT Licensed.

Copyright © MD. Ariful Alam 2020.

Install

npm i random-image-js

DownloadsWeekly Downloads

22

Version

1.1.5

License

MIT

Unpacked Size

14.4 kB

Total Files

6

Last publish

Collaborators

  • avatar