UNPKG

hastebin-paste

Version:

A simple hastebin client for uploading things to hastebin.com with error code help that make it easier for you to debug!

31 lines (18 loc) 1.35 kB
const fetch = require("node-fetch"); module.exports = async (input, options = {}) => { if (!input) throw new Error("Invalid String Input. Please provide a new input"); if (typeof options === "string") options = { url: "https://hastebin.com", extension: options, message: "Powered by hastebin-paste, a npm package.", prefix: "The link is: " }; const url = "url" in options ? options.url : "https://hastebin.com"; const extension = "extension" in options ? options.extension : "txt"; const message = "message" in options ? options.message : "Powered by hastebin-paste, a npm package."; const prefix = "prefix" in options ? options.message : "The link is: "; const res = await fetch(`${url}/documents`, { method: "POST", body: input, headers: { "Content-Type": "text/plain" } }); const { key } = await res.json(); return `${prefix} ${url}/${key}.${extension} ${message}`; if (res.ok) throw new Error(`This is not a error! Hastebin url generated at ${url}/${key}.${extension}`) if (!res.ok) throw new Error(res.statusText + "Please see https://www.npmjs.com/package/hastebin-paste#example-with-a-custom-haste-server-instance for help or submit an issue at https://www.github.com/Absolute-Development/hastebin-paste/issues for help."); };