UNPKG

vme50

Version:
66 lines (65 loc) 1.92 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.vme50Image = exports.vme50Text = void 0; const data_1 = __importDefault(require("./data")); const defualtOptions = { console: false, type: 'error', returnUndefined: true, resultType: 'text', }; /** * 生成随机数 */ function ran(max, min = 0) { return Math.floor(Math.random() * (max - min + 1)) + min; } /** * 获取随机 vme50 文本 */ function vme50Text() { return data_1.default.texts[ran(data_1.default.texts.length - 1)]; } exports.vme50Text = vme50Text; /** * 获取随机 vme50 图片链接 */ function vme50Image() { return data_1.default.images[ran(data_1.default.images.length - 1)]; } exports.vme50Image = vme50Image; function vme50Fun(options = defualtOptions) { var _a; for (const key in options) { // @ts-ignore options[key] = (_a = options[key]) !== null && _a !== void 0 ? _a : defualtOptions[key]; } const isThursday = new Date().getDay() === 4; if (isThursday) { if (options.type === 'error') { if (options.console) console.error('Error: Crazy Thursday need ¥50'); else throw 'Error: Crazy Thursday need ¥50'; } else if (options.type === 'warn') { console.warn('Warning: Crazy Thursday need ¥50'); } } if (options.returnUndefined && !isThursday) return undefined; if (options.resultType === 'text') return vme50Text(); if (options.resultType === 'image') return vme50Image(); } /** * V我50 */ const vme50 = vme50Fun; vme50.text = vme50Text; vme50.image = vme50Image; exports.default = vme50;