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

better-pastebin

v0.4.1

Published

The Pastebin API wrapper Node deserves

Downloads

27

Readme

better-pastebin

NPM

The Pastebin API wrapper Node deserves. better-pastebin is the most fully-featured module available for connecting to pastebin.com, both to its API and directly to the site itself for accomplishing tasks that the API doesn't support. It uses cheerio, request, and xml2js.

Installation

npm install better-pastebin

Example

var paste = require("better-pastebin");

paste.setDevKey("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
paste.login("username", "password", function(success, data) {
    if(!success) {
        console.log("Failed (" + data + ")");
        return false;
    }

    paste.create({
        contents: "test contents",
        name: "test paste",
        privacy: "1"
    }, function(success, data) {
        if(success) {
            //data contains the URL of the created paste
        } else {
            //data contains an Error object indicating why the creation failed
        }
    });
});

Usage

Setting the devkey

paste.setDevKey("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

This is necessary before performing any other API call. It's synchronous, so it doesn't require a callback. You can find your devkey on pastebin.com after signing in.

Logging in

paste.login(username, password, function(success, data) {
    //data contains this session's userkey
});

Logs in to Pastebin. Any actions requiring a login should be placed within the callback.

Getting a paste

paste.get(paste_id, function(success, data) {
    //data contains the contents of the paste 
});

Gets the contents of a paste. Either the ID or the URL of a paste can be supplied.

Creating a paste

paste.create(options, function(success, data) {
    //data contains the URL of the created paste
});

Creates a new paste. You do not need to be logged in to do this, but you can only create global or unlisted pastes as a guest. options can either be the contents of the paste as a string, or an object containing one or more of the following keys:

  • options.contents: The contents of the paste; this is the only mandatory property.
  • options.anonymous (default: false): If true, the paste will be created as a guest even if logged in.
  • options.expires (default: "N"): When the paste should expire.
  • options.format (default: "text"): The syntax highlighting of the paste.
  • options.privacy (default: "0"): The privacy of the paste.
  • options.name (default: ""): The name of the paste.

Creating a paste from a file

paste.createFromFile(options, function(success, data) {
    //data contains the URL of the created paste
});

Creates a new paste from the contents of a file. This works the same way that paste.create does, except that options.path should be specified instead of options.contents, or options should be the path to the file you want to upload as a string. It also accepts an additional key, options.encoding:

  • options.encoding (default: "utf8"): The encoding of the file.

Editing a paste

paste.edit(paste_id, options, function(success, data) {
    //data contains the new contents of the paste
});

Updates a paste's contents. You must be logged in to do this, and you can only edit a paste that you created. Either the ID or the URL of a paste can be supplied. options can either be the new contents of the paste as a string, or an object containing one or more of the following keys:

  • options.contents: The new contents of the paste.
  • options.expires: When the paste should expire.
  • options.format: The syntax highlighting of the paste.
  • options.privacy: The privacy of the paste.
  • options.name: The name of the paste.

If left unspecified, these default to the paste's existing options.

Listing the logged-in user's pastes

paste.list(limit, function(success, data) {
    //data contains an array of objects of information about each paste
});

Lists up to 1,000 of the logged-in user's created pastes. limit specifies how many pastes to return; it can be a number between 1 and 1,000, and defaults to 50. You must be logged in to do this.

Listing trending pastes

paste.listTrending(function(success, data) {
    //data contains an array of objects of information about each paste
});

Lists currently trending pastes. The array of pastes is identical in structure to the one returned by paste.list.

Deleting a paste

paste.delete(paste_id, function(success, data) {
    //data contains the ID of the deleted paste
});

Deletes a paste. You must be logged in to do this, and you can only delete a paste that you created. Either the ID or the URL of a paste can be supplied.

Getting information about the logged-in user

paste.user(function(success, data) {
    //data contains an object of information about the logged-in user
});

Returns information about the logged-in user. You must be logged in to do this.

Valid options

expires

N = Never
10M = 10 Minutes
1H = 1 Hour
1D = 1 Day
1W = 1 Week
2W = 2 Weeks
1M = 1 Month

privacy

0 = Public
1 = Unlisted
2 = Private

Note that private pastes can only be created if you are signed in. These values should be passed as a string, because 0 is a falsy value and can cause some issues.

format

Refer to http://pastebin.com/api#5 for the full list of syntax highlighting options.

License

All code in this repository is licensed under the MIT license. See LICENSE for more information.