kiutils
Version:
🎑 (Library) an Javascript library that provide various utilities, including Image manipulation tools, Discord-related utilities, and a logger.
38 lines • 1.31 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.waifu = exports.WaifuType = void 0;
const node_fetch_1 = __importDefault(require("node-fetch"));
var WaifuType;
(function (WaifuType) {
WaifuType["SFW"] = "sfw";
WaifuType["NSFW"] = "nsfw";
})(WaifuType || (exports.WaifuType = WaifuType = {}));
/**
* @typedef {Object} WaifuData
* @property {string[]} categoryNsfw - The NSFW categories
* @property {string[]} categorySfw - The SFW categories
* @property {string} type - The type of the image
* @example
* const { waifu } = require("kiutils")
* waifu("sfw").then(console.log)
*
* // => "https://..."
*/
async function waifu(type = WaifuType.SFW) {
try {
const res = await (0, node_fetch_1.default)(`https://api.waifu.pics/${type}/waifu`);
if (!res.ok) {
throw new Error(`Failed to fetch waifu: ${res.statusText}`);
}
const data = await res.json();
return data.url;
}
catch (error) {
throw new Error(`Error fetching waifu: ${error instanceof Error ? error.message : String(error)}`);
}
}
exports.waifu = waifu;
//# sourceMappingURL=waifu.js.map
;