1.2.0 • Published 4 years ago
@elchologamer/random-reddit v1.2.0
reddit-post
Get random Reddit posts from a specified Subreddit extremely simple! Here's how it works:
Installation
npm i @elchologamer/random-reddit --save
Options
You can use any of these options when getting a post:
- searchLimit -> number: Number of posts to fetch for selection. (If this is too big, the request will have a significant delay)
- imageOnly -> boolean: Determines if the post must come with an image
- allowNSFW -> boolean: Determines if NSFW posts are allowed
JavaScript usage
const randomReddit = require('@elchologamer/random-reddit');
// Create options
let options = {
imageOnly: true,
allowNSFW: false,
};
/*
Get a random post from r/memes,
returning only an image, and not
allowing NSFW posts
*/
randomReddit('memes', options)
.then((post) => {
console.log(`Post found: ${post.title}`);
})
.catch((err) => {
console.error(err);
});
TypeScript usage
import randomReddit, { SearchOptions } from '@elchologamer/random-reddit';
// Create options
let options: SearchOptions = {
imageOnly: true,
allowNSFW: false,
};
/*
Get a random post from r/memes,
returning only an image, and not
allowing NSFW posts
*/
getPost('memes', options)
.then((post) => {
console.log(`Post found: ${post.title}`);
})
.catch((err) => {
console.error(err);
});