npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@stamlercas/reddit.js

v0.1.5

Published

Reddit API wrapper for the browser

Downloads

4

Readme

Reddit.js

Reddit.js is a browser based wrapper on most of the read-only Reddit API. It makes CORS requests to the Reddit API. Thus only unauthenicated (logged-out) requests are allowed.

Latest versions of Chrome, Firefox, Internet Explorer and Safari are supported.

Build Status npm version

Usage

Reddit.js is a lightweight dependency-free library which comes with minified source.

  • Install via npm install reddit.js
  • Or include a link from the jsdelivr CDN.
  • Or download the reddit.min.js file from here.

Include the minfied source via script tag like so

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/reddit.min.js"></script>

The reddit variable is exported which can be used to talk to the Reddit API. The examples directory includes usage with pure DOM API. More sophisticated examples are on the way!

  // Fetch the 5 hottest posts on /r/awww
  reddit.hot('aww').limit(5).fetch(function(res) {
    // res contains JSON parsed response from Reddit
    console.log(res);
  });
  // Errors (if any) will be passed to the 2nd argument of fetch()
  reddit.hot('aww').limit(5).fetch(function(res) {}, function(err) {
    // err contains the error from Reddit
  });
  // All Reddit API filters are supported and chainable
  reddit.hot('aww').limit(1).after("t3_23jf8n").fetch(function(res) {
    // res contains JSON parsed response from Reddit
    console.log(res);
  });
  // Subreddits may be omitted
  // Fetch the hottest posts from Reddit
  reddit.hot().fetch(function(res) {
    console.log(res);
  });

Supported API Endpoints

Fetch the hottest posts on Reddit or on a subreddit. All filters such as after, before, limit are supported.

  reddit.hot('aww').limit(1).after("t3_23jf8n").fetch(function(res) {
    // res contains JSON parsed response from Reddit
    console.log(res);
  });

Fetch the newest posts on Reddit or on a subreddit. Again all filters are supported.

  reddit.new('programming').before("t3_23jf8n").fetch(function(res) {
    // res contains JSON parsed response from Reddit
    console.log(res);
  });

Fetch the top posts on Reddit or on a subreddit. As usual all filters are supported. The t filter allows filtering by top posts of the day, week, month, year or all-time.

  // Fetch the top 5 funniest posts of all time from /r/funny
  reddit.top('funny').t('all').limit(5).fetch(function(res) {
    console.log(res);
  });

Fetch the top posts on Reddit or on a subreddit As usual all filters are supported.. The t filter allows filtering by top posts of the day, week, month, year or all-time.

  // Fetch the 25 most controversial posts from this month
  reddit.controversial().t('month').limit(25).fetch(function(res) {
    console.log(res);
  });

Fetch comments on a link. As usual all filters are supported. Context and depth are useful filters to narrow or highlight comments.

  // Fetch the hottest comment on article 23ha0a from /r/pics
  reddit.comments("23ha0a", "pics").limit(1).sort("hot").fetch(function(res) {
    console.log(res);
  });

Search everything. All filters including syntax and t are supported.

  reddit.search("programming").t('month').limit(1).sort("hot").fetch();

Search subreddits by title and description. Filter away.

  // Fetch 5 subreddits related to gardening
  reddit.searchSubreddits("gardening").limit(5).fetch();

Fetch information about Reddit or a subreddit.

  // Fetch information about /r/pics
  reddit.about("pics").fetch(function(res) {
    console.log(res);
  });

The Serendipity button.

  // Fetch random articles from /r/funny
  reddit.random("funny").fetch(function(res) {
    console.log(res);
  });

Fetch a link by fullname or a list of links by URL. Can be filtered by a subreddit.

  // Fetch info about reddit itself
  reddit.info().url("https://www.reddit.com/").fetch(function(res) {
    console.log(res);
  });

Fetch a list of recommended subreddits based on the comma separated list of subreddits supplied. Can be filtered by the omit param.

 reddit.recommendedSubreddits("programming").omit("leapmotion,CFD").fetch(function(res) {
    console.log(res);
  });

Fetch list of subreddits that are relevant to a search query.

 reddit.subredditsByTopic("programming").fetch();

Fetch subreddits ordered by activity.

  // Fetch the 25 most popular subreddits
  reddit.popularSubreddits().limit(25).fetch();

Fetch newest subreddits.

  // Fetch the 25 newest subreddits.
  reddit.newSubreddits().limit(25).fetch();

Fetch information about the user's activity. Supported second parameters are about, overview, submitted, comments, upvoted, downvoted, hidden, saved, and gilded. Filters such as show, sort, t, type, username, after, before, count, limit, and sr_detail are supported. Second parameter is optional.

  reddit.user('chromakode', 'comments').limit(1).fetch(function(res) {
    // res contains JSON parsed response from Reddit
    console.log(res);
  });

Contributing

Pull requests are welcome. Reddit.js is built using node and npm. Once you have them installed you can run all tests with:

$ npm install
$ npm test

To build the minified source

 $ npm run minify

License

The MIT License (MIT)

Copyright (c) 2014 Sahil Muthoo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.