Socket
Socket
Sign inDemoInstall

@catte_/pastebin.js

Package Overview
Dependencies
11
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @catte_/pastebin.js

An object-oriented JavaScript wrapper for the Pastebin API.


Version published
Maintainers
1
Created

Readme

Source

pastebin.js

An object-oriented JavaScript wrapper for the Pastebin API.

Installation

$ npm install @catte_/pastebin.js

Usage

const { PastebinClient } = require("@catte_/pastebin.js")
const pastebin = new PastebinClient(process.env.API_KEY)

const paste = await pastebin.pastes.create("console.log('hello, world')", {
    title: "pastebin.js test",
    format: "javascript",
    privacy: "unlisted"
})
console.log(paste.url)
  • Classes
  • Typedefs

Classes

The module exports the following classes, you can import them like so:

const {
    PastebinClient,
    PastebinError,
    Paste,
    User,
    ClientUser,
    PasteStore,
    UserStore,
    UserPasteStore
} = require("@catte_/pastebin.js")

PastebinClient

The client used to interact with the Pastebin API.

.constructor()
new PastebinClient(apiKey, username, password)
Parameters
namedescriptiontypedefault
apiKeyYour Pastebin API keystringnull
usernameYour Pastebin usernamestringnull
passwordYour Pastebin passwordstringnull
.credentials

Your Pastebin credentials.
Type: PastebinCredentials

.user

The user the client logged in with, if it has.
Type: ?ClientUser

.users

All of the cached users.
Type: ?UserStore

.pastes

All of the cached pastes.
Type: ?PasteStore

.login()

Login with the stored username and password and store the user key.

Returns

Promise<PastebinClient>

PastebinError extends Error

Thrown when there's an error related to the Pastebin API or pastebin.js.

.constructor()
new PastebinError(message)
Parameters
namedescriptiontypedefault
messageThe error messagestring
.message

The error message.

Paste

A Pastebin paste.

.constructor()
new Paste(client, data)
Parameters
namedescriptiontypedefault
clientThe client used to get this pastePastebinClient
dataThe data obtained from the APIObject
.client

The client used to get this paste.
Type: PastebinClient

.key

The key of this paste.
Type: string

.url

The URL of this paste.
Type: string

.title

The title of this paste.
Type: ?string

.author

The author of this paste.
Type: ?User

.content

The content of this paste.
Type: ?string

.size

The length of the content of this paste.
Type: ?number

.date

The date this paste was posted.
Type: ?Date

.format

The format of this paste.
Type: ?string

.privacy

The privacy setting of this paste.
Type: ?number

.expiry

The expiry time of this paste.
Type: ?string

.hits

The number of times anyone saw this paste.
Type: ?number

.fetch()

Fetch the content of this paste, and store it in the cache.

Returns

Promise<Paste>

.delete()

Delete this paste.

Returns

Promise<Paste>

User

A Pastebin user.

.constructor()
new User(client, username)
Parameters
namedescriptiontypedefault
clientThe client used to get this pastePastebinClient
usernameThe user's usernamestring
.client

The client used to get this user.
Type: PastebinClient

.username

This user's username.
Type: string

.me

Whether this user is the same as the client's user.
Type: boolean

ClientUser extends User

The Pastebin user of the logged in client.

.constructor()
new ClientUser(client, data)
Parameters
namedescriptiontypedefault
clientThe client used to get this pastePastebinClient
dataThe data obtained from the APIObject
.username

This user's username.
Type: string

.format

This user's format setting.
Type: ?string

.expiry

This user's expiry setting.
Type: ?string

.avatarURL

This user's avatar URL.
Type: ?string

.privacy

This user's privacy setting.
Type: ?number

.website

This user's website.
Type: ?string

.email

This user's e-mail.
Type: ?string

.location

This user's location.
Type: ?string

.pro

Whether this user is a PRO account.
Type: ?boolean

.pastes

All of this user's cached pastes.
Type: ?UserPasteStore

PasteStore extends Map

A structure that holds all of the cached pastes.

.constructor()
new PasteStore(client, entries)
Parameters
namedescriptiontypedefault
clientThe client the store belongs toPastebinClient
entriesArray<Array<string, Paste>>null
.client

The client this store belongs to.
Type: PastebinClient

.fetch()

Fetch a paste by its key, and store it in the cache.

Parameters
namedescriptiontypedefault
keyThe paste's keystring
Returns

Promise<Paste>

.create()

Create a paste, and store it in the cache.

Parameters
namedescriptiontypedefault
contentThe paste's contentany
optionsArray<Array<string, Paste>>null
options.titleThe paste's titlestring{}
options.formatThe paste's formatFormatnull
options.privacyThe paste's privacy settingPrivacynull
options.expiryThe paste's expiry timeExpirynull
Returns

Promise<Paste>

UserStore

A structure that holds all of the cached users.

.constructor()
new UserStore(client, entries)
Paramaters
namedescriptiontypedefault
clientThe client the store belongs toPastebinClient
entriesArray<Array<string, Paste>>null
.client

The client this store belongs to.
Type: PastebinClient

.fetch()

Fetch a user by their username, and store them in the cache.

Parameters
namedescriptiontypedefault
usernameThe user's usernamestring
Returns

Promise<User>

UserPasteStore

A structure that holds all of a user's cached pastes.

.constructor()
new UserPasteStore()
Parameters
namedescriptiontypedefault
clientThe client the store belongs toPastebinClient
userThe user the store belongs toUser
entriesArray<Array<string, Paste>>null
.client

The client this store belongs to.
Type: PastebinClient

.user

The user this store belongs to.
Type: User

.fetch()

Fetch this user's pastes, and store them in the cache.

Parameters
namedescriptiontypedefault
maxThe maximum number of pastes to fetchnumber50
Returns

Promise<UserPasteStore>

Typedefs

PastebinCredentials

The credentials provided to and stored in the PastebinClient.

Type: { apiKey?, username?, password?, userKey? }

Properties
namedescriptiontypedefault
apiKeyYour Pastebin API keystringnull
usernameYour Pastebin usernamestringnull
passwordYour Pastebin passwordstringnull
userKeyYour Pastebin user key, obtained when logging instringnull

PasteCreateOptions

Options to create a paste.

Type: { title?, format?, privacy?, expiry? }

Properties
namedescriptiontypedefault
titleYour Pastebin API keystringnull
formatYour Pastebin usernameFormatnull
privacyYour Pastebin passwordPrivacynull
expiryYour Pastebin user key, obtained when logging inExpirynull

Format

A "format," which will be used for syntax highlighting. You can see the full list of formats here.

Type: string

Privacy

A privacy setting. Can be one of the following:

  • 0 (or "public")
  • 1 (or "unlisted")
  • 2 (or "private")

Type: string or number

Expiry

An expiry setting. Can be one of the following:

  • "NEVER" (or "N")
  • "10 MINUTES" (or "10M")
  • "1 HOUR" (or "1H")
  • "1 DAY" (or "1D")
  • "1 WEEK" (or "1W")
  • "2 WEEKS" (or "2W")
  • "1 MONTH" (or "1M")
  • "6 MONTHS" (or "6M")
  • "1 YEAR" (or "1Y")

Keywords

FAQs

Last updated on 23 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc