UNPKG

kiutils

Version:

🎑 (Library) an Javascript library that provide various utilities, including Image manipulation tools, Discord-related utilities, and a logger.

39 lines • 1.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.bin = void 0; const axios_1 = __importDefault(require("axios")); /** * Uploads the code to sourceb.in * @param {string} code - Code to upload * @returns {Promise<string>} url of the uploaded code * @example * const { bin } = require("kiutils") * bin("console.log('Hello World')").then(console.log) */ async function bin(code) { if (!code) throw new Error("The parameter 'code' is missing"); if (typeof code !== "string") throw new TypeError("The parameter 'code' must be a string"); try { const response = await axios_1.default.post("https://sourceb.in/api/bins", { files: [ { content: code } ] }); return `https://sourceb.in/${response.data.key}`; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`Failed to upload to sourceb.in: ${error.message}`); } throw error; } } exports.bin = bin; //# sourceMappingURL=bin.js.map