2.0.5 • Published 5 years ago

hastebin-gen v2.0.5

Weekly downloads
50,007
License
MIT
Repository
github
Last release
5 years ago

Discord npm npm downloads NPM version Build Status Open Source Love dependencies Status devDependencies Status NPM

hastebin-gen

A npm module for generating hastebin links. https://www.npmjs.com/package/hastebin-gen

Installation

NPM: npm i hastebin-gen

Yarn: yarn add hastebin-gen

Options

OptionTypeDefault Value
urlstring"https://hastebin.com"
extensionstring"js"

Examples

Using .then().catch()

const hastebin = require("hastebin-gen");

// You can change the extension by setting the extension option
hastebin("code", { extension: "txt" }).then(haste => {
    // Logs the created hastebin url to the console
    console.log(haste); // https://hastebin.com/someid.txt
}).catch(error => {
    // Handle error
    console.error(error);
});

Using async/await

This is assuming that you are in a asynchronous scope

Understanding Async/Await

const hastebin = require("hastebin-gen");

// You can change the extension by setting the extension option
const haste = await hastebin("code", { extension: "txt" });

// Logs the created hastebin url to the console
console.log(haste); // https://hastebin.com/someid.txt

Example with a custom haste-server instance

Using .then().catch()

const hastebin = require("hastebin-gen");

// You can change the extension by setting the extension option
hastebin("code", { url: "https://paste.example.com", extension: "txt" }).then(haste => {
    // Logs the created hastebin url to the console
    console.log(haste); // https://paste.example.com/someid.txt
}).catch(error => {
    // Handle error
    console.error(error);
});

Using async/await

This is assuming that you are in a asynchronous scope

Understanding Async/Await

const hastebin = require("hastebin-gen");

// You can change the extension by setting the extension option
const haste = await hastebin("code", { url: "https://paste.example.com", extension: "txt" });

// Logs the created hastebin url to the console
console.log(haste); // https://paste.example.com/someid.txt