UNPKG

@sodiumlabs/plume-api

Version:
476 lines (470 loc) 14.5 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { PlumeAPI: () => PlumeAPI, PlumeAPIError: () => PlumeAPIError, PlumeAPIREST: () => PlumeAPIREST }); module.exports = __toCommonJS(index_exports); // src/PlumeAPIError.ts var PlumeAPIError = class extends Error { constructor(message, options, res) { super(message, options); this.res = res; this.res = res || null; } static { __name(this, "PlumeAPIError"); } }; // package.json var version = "1.5.0"; // src/PlumeAPIREST.ts var PlumeAPIREST = class _PlumeAPIREST { constructor(options = {}) { this.options = options; this.options = options; } static { __name(this, "PlumeAPIREST"); } static baseURL = "https://plume.sodiumlabs.xyz/api"; static defaultUserAgent = `plume-api.js/${version}`; async request(method, path, body) { if (!path.startsWith("/")) { throw new Error(`Invalid path: ${path}`); } const headers = new Headers({ "User-Agent": `${_PlumeAPIREST.defaultUserAgent} ${this.options.userAgent || ""}`.trim() }); const url = `${_PlumeAPIREST.baseURL}${path}`; let res; try { res = await fetch(url, { method, headers, body: body ? JSON.stringify(body) : void 0 }); } catch (err) { throw new PlumeAPIError(`Failed to fetch ${url}`, { cause: err }); } if (!res.ok) { throw new PlumeAPIError(`Invalid response ${url}: ${res.statusText}`, void 0, res); } return res; } async get(path) { const res = await this.request("GET", path); return await res.json(); } async file(path) { const res = await this.request("GET", path); return Buffer.from(await res.arrayBuffer()); } }; // src/utils.ts var queryfy = /* @__PURE__ */ __name((options) => { const params = new URLSearchParams( Object.entries(options).filter(([, v]) => v !== void 0).map(([k, v]) => [k, `${v}`]) ); const encoded = params.toString(); return encoded ? `?${encoded}` : ""; }, "queryfy"); // src/PlumeAPI.ts var PlumeAPI = class { static { __name(this, "PlumeAPI"); } rest; constructor(options) { this.rest = new PlumeAPIREST(options); } // Fun async eightBall(locale) { const params = queryfy({ locale }); return await this.rest.get(`/8ball${params}`); } async advice(locale) { const params = queryfy({ locale }); return await this.rest.get(`/advice${params}`); } async agify(name) { const params = queryfy({ name }); return await this.rest.get(`/agify${params}`); } async asciiImage(text, font) { const params = queryfy({ text, font }); return await this.rest.file(`/ascii-image${params}`); } async asciiText(text) { const params = queryfy({ text }); return await this.rest.get(`/ascii-text${params}`); } /** * @deprecated Use `eightBall` instead */ async heightBall(locale) { const params = queryfy({ locale }); return await this.rest.get(`/8ball${params}`); } async emojiMix(left, right) { const params = queryfy({ left, right }); return await this.rest.get(`/emoji-mix${params}`); } async emojify(text) { const params = queryfy({ text }); return await this.rest.get(`/emojify${params}`); } async funFact(locale) { const params = queryfy({ locale }); return await this.rest.get(`/funfact${params}`); } async issImage(circle) { const params = queryfy({ circle }); return await this.rest.file(`/iss-image${params}`); } async iss() { return await this.rest.get("/iss"); } async joke(locale) { const params = queryfy({ locale }); return await this.rest.get(`/joke${params}`); } async math(expr) { const params = queryfy({ expr }); return await this.rest.get(`/math${params}`); } async meme() { return await this.rest.get("/meme"); } async nasaAPOD() { return await this.rest.get("/nasa-apod"); } async npm(name) { const params = queryfy({ name }); return await this.rest.get(`/npm${params}`); } async quote(locale) { const params = queryfy({ locale }); return await this.rest.get(`/quote${params}`); } async randomEmojiMix() { return await this.rest.get("/random-emoji-mix"); } async upsideDown(text) { const params = queryfy({ text }); return await this.rest.get(`/upside-down${params}`); } async urban(word) { const params = queryfy({ word }); return await this.rest.get(`/urban${params}`); } async color(hex) { const params = queryfy({ hex }); return await this.rest.get(`/color${params}`); } async colorImage(hex) { return await this.rest.file(`/color/image/${hex}`); } async randomColor() { return await this.rest.get("/color/random"); } async githubRepository(name) { const params = queryfy({ name }); return await this.rest.get(`/github/repository${params}`); } async githubUser(name) { const params = queryfy({ name }); return await this.rest.get(`/github/user${params}`); } // Utility async captcha() { const res = await this.rest.request("GET", "/captcha"); const code = res.headers.get("X-Captcha-Code"); if (!code) throw new Error("X-Captcha-Code missing in response"); const image = Buffer.from(await res.arrayBuffer()); return { code, image }; } async crypto(name, currency) { const params = queryfy({ name, currency }); return await this.rest.get(`/crypto${params}`); } async definition(locale, word) { const params = queryfy({ locale, word }); return await this.rest.get(`/definition${params}`); } async exec(language, code) { const params = queryfy({ language, code }); return await this.rest.get(`/exec${params}`); } async freeGames(locale) { const params = queryfy({ locale }); return await this.rest.get(`/free-games${params}`); } async ipInfo(ip) { const params = queryfy({ ip }); return await this.rest.get(`/ipinfo${params}`); } async latex(expr) { const params = queryfy({ expr }); return await this.rest.file(`/latex${params}`); } async qrcode(text) { const params = queryfy({ text }); return await this.rest.file(`/qrcode${params}`); } async reverseText(text) { const params = queryfy({ text }); return await this.rest.get(`/reverse-text${params}`); } async screenshot(url) { const params = queryfy({ url }); return await this.rest.file(`/screenshot${params}`); } async translate(text, to) { const params = queryfy({ text, to }); return await this.rest.get(`/translate${params}`); } async uuid() { return await this.rest.get("/uuid"); } async weather(city) { const params = queryfy({ city }); return await this.rest.get(`/weather${params}`); } async wikipedia(page, locale) { const params = queryfy({ page, locale }); return await this.rest.get(`/wikipedia${params}`); } // Animals async duck() { return await this.rest.file("/animals/duck"); } async fox() { return await this.rest.file("/animals/fox"); } // Encode async encode(type, text) { const params = queryfy({ text }); return await this.rest.get(`/encode/${type}${params}`); } // Decode async decode(type, text) { const params = queryfy({ text }); return await this.rest.get(`/decode/${type}${params}`); } // Fortnite async fortniteMapImagePois(locale) { const params = queryfy({ locale }); return await this.rest.file(`/fortnite/map/image-pois${params}`); } async fortniteMapImage() { return await this.rest.file("/fortnite/map/image"); } async fortniteMap(locale) { const params = queryfy({ locale }); return await this.rest.get(`/fortnite/map${params}`); } // Minecraft async minecraftAvatar(name) { const params = queryfy({ name }); return await this.rest.get(`/minecraft/avatar${params}`); } async minecraftBody(name) { const params = queryfy({ name }); return await this.rest.get(`/minecraft/body${params}`); } async minecraftID(name) { const params = queryfy({ name }); return await this.rest.get(`/minecraft/id${params}`); } async minecraftName(id) { const params = queryfy({ id }); return await this.rest.get(`/minecraft/name${params}`); } async minecraftSkin(name) { const params = queryfy({ name }); return await this.rest.get(`/minecraft/skin${params}`); } // Interactions async interaction(type) { return await this.rest.get(`/interactions/${type}`); } // Image Creation async achievement(text) { const params = queryfy({ text }); return await this.rest.file(`/images/achievement${params}`); } async alert(text) { const params = queryfy({ text }); return await this.rest.file(`/images/alert${params}`); } async caution(text) { const params = queryfy({ text }); return await this.rest.file(`/images/caution${params}`); } async challenge(text) { const params = queryfy({ text }); return await this.rest.file(`/images/challenge${params}`); } async jail(avatar) { const params = queryfy({ avatar }); return await this.rest.file(`/images/jail${params}`); } async nokia(url) { const params = queryfy({ url }); return await this.rest.file(`/images/nokia${params}`); } async tweet(avatar, name, username, text, retweets, quote_tweets, likes) { const params = queryfy({ avatar, name, username, text, retweets, quote_tweets, likes }); return await this.rest.file(`/images/tweet${params}`); } async wanted(avatar) { const params = queryfy({ avatar }); return await this.rest.file(`/images/wanted${params}`); } // Image Manipulation async blur(url) { const params = queryfy({ url }); return await this.rest.file(`/images/blur${params}`); } async colorify(url, color) { const params = queryfy({ url, color }); return await this.rest.file(`/images/colorify${params}`); } async grayscale(url) { const params = queryfy({ url }); return await this.rest.file(`/images/grayscale${params}`); } async invert(url) { const params = queryfy({ url }); return await this.rest.file(`/images/invert${params}`); } async rotate(url, deg) { const params = queryfy({ url, deg }); return await this.rest.file(`/images/rotate${params}`); } // Meme Creation async changeMyMind(text) { const params = queryfy({ text }); return await this.rest.file(`/memes/changemymind${params}`); } async didYouMean(search, correction) { const params = queryfy({ search, correction }); return await this.rest.file(`/memes/didyoumean${params}`); } async drake(top, bottom) { const params = queryfy({ top, bottom }); return await this.rest.file(`/memes/drake${params}`); } async duolingo(text) { const params = queryfy({ text }); return await this.rest.file(`/memes/duolingo${params}`); } async facts(text) { const params = queryfy({ text }); return await this.rest.file(`/memes/facts${params}`); } async fuze3(text) { const params = queryfy({ text }); return await this.rest.file(`/memes/fuze3${params}`); } async hugo(text) { const params = queryfy({ text }); return await this.rest.file(`/memes/hugo${params}`); } async nothing(text) { const params = queryfy({ text }); return await this.rest.file(`/memes/nothing${params}`); } async oogway(text) { const params = queryfy({ text }); return await this.rest.file(`/memes/oogway${params}`); } async pepeHug(avatar) { const params = queryfy({ avatar }); return await this.rest.file(`/memes/pepe-hug${params}`); } async sadcat(top, bottom) { const params = queryfy({ top, bottom }); return await this.rest.file(`/memes/sadcat${params}`); } async stonks(avatar, stonks) { const params = queryfy({ avatar, stonks }); return await this.rest.file(`/memes/stonks${params}`); } async tableFlip(avatar) { const params = queryfy({ avatar }); return await this.rest.file(`/memes/tableflip${params}`); } async water(text) { const params = queryfy({ text }); return await this.rest.file(`/memes/water${params}`); } async woosh(avatar) { const params = queryfy({ avatar }); return await this.rest.file(`/memes/woosh${params}`); } // Cards async boost(avatar, username, text) { const params = queryfy({ avatar, username, text }); return await this.rest.file(`/cards/boost${params}`); } async couple(avatar1, avatar2, percentage, primary_color) { const params = queryfy({ avatar1, avatar2, percentage, primary_color }); return await this.rest.file(`/cards/couple${params}`); } async rank(avatar, global_name, username, level, xp, max_xp, rank, bg_url, bg_color, blur, color) { const params = queryfy({ avatar, global_name, username, level, xp, max_xp, rank, bg_url, bg_color, blur, color }); return await this.rest.file(`/cards/rank${params}`); } async welcome(avatar, text1, text2, text3, bg_url, bg_color, font_color, blur, avatar_border, avatar_border_color) { const params = queryfy({ avatar, text1, text2, text3, bg_url, bg_color, font_color, blur, avatar_border, avatar_border_color }); return await this.rest.file(`/cards/welcome${params}`); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { PlumeAPI, PlumeAPIError, PlumeAPIREST }); //# sourceMappingURL=index.js.map