discord-authorize
Version:
A node module for easy authentication with Discord
49 lines • 2.38 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatServerIcon = exports.formatUserAvatar = void 0;
const getType_1 = __importDefault(require("./getType"));
/**
* Format a user's avatar image URLs in various formats.
*
* @template I - The type of the imageString parameter.
* @param {snowflake} userId - The user's unique identifier (snowflake).
* @param {I} imageString - The image string used to create the avatar URLs.
* @returns {Image} An object containing URLs in different image formats (jpg, png, webp, gif).
* @throws {TypeError} If the userId's type is not 'snowflake'.
*/
const formatUserAvatar = (userId, imageString) => {
if ((0, getType_1.default)(userId) !== "snowflake") {
throw new TypeError(`Expected type of user id to be 'snowflake' but got ${(0, getType_1.default)(userId)} instead.`);
}
const formattedJPG = `https://cdn.discordapp.com/avatars/${userId}/${imageString}.jpg`;
const formattedPNG = `https://cdn.discordapp.com/avatars/${userId}/${imageString}.png`;
const formattedWEBP = `https://cdn.discordapp.com/avatars/${userId}/${imageString}.webp`;
const formattedGIF = `https://cdn.discordapp.com/avatars/${userId}/${imageString}.gif`;
return {
jpg: formattedJPG,
png: formattedPNG,
webp: formattedWEBP,
gif: formattedGIF,
};
};
exports.formatUserAvatar = formatUserAvatar;
const formatServerIcon = (guildId, imageString) => {
if ((0, getType_1.default)(guildId) !== "snowflake") {
throw new TypeError(`Expected type of user id to be 'snowflake' but got ${(0, getType_1.default)(guildId)} instead.`);
}
const formattedJPG = `https://cdn.discordapp.com/icons/${guildId}/${imageString}.jpg`;
const formattedPNG = `https://cdn.discordapp.com/icons/${guildId}/${imageString}.png`;
const formattedWEBP = `https://cdn.discordapp.com/icons/${guildId}/${imageString}.webp`;
const formattedGIF = `https://cdn.discordapp.com/icons/${guildId}/${imageString}.gif`;
return {
jpg: formattedJPG,
png: formattedPNG,
webp: formattedWEBP,
gif: formattedGIF,
};
};
exports.formatServerIcon = formatServerIcon;
//# sourceMappingURL=Format.js.map