64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.emsg = exports.errorMessage = exports.shuffle = void 0;
|
|
const Lang = __importStar(require("../lang"));
|
|
/**
|
|
* shuffles an array
|
|
* https://stackoverflow.com/a/2450976/2856416
|
|
* @param array an array
|
|
* @returns an array but shuffled
|
|
*/
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
function shuffle(array) {
|
|
let currentIndex = array.length, randomIndex;
|
|
// While there remain elements to shuffle...
|
|
while (currentIndex != 0) {
|
|
// Pick a remaining element...
|
|
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
currentIndex--;
|
|
// And swap it with the current element.
|
|
[array[currentIndex], array[randomIndex]] = [
|
|
array[randomIndex], array[currentIndex]
|
|
];
|
|
}
|
|
return array;
|
|
}
|
|
exports.shuffle = shuffle;
|
|
/**
|
|
* use the emsg() function instead
|
|
*/
|
|
class errorMessage {
|
|
constructor(msg, ephemeral = true) {
|
|
this.msg = msg;
|
|
this.ephemeral = ephemeral;
|
|
}
|
|
}
|
|
exports.errorMessage = errorMessage;
|
|
/**
|
|
* a simple class to contain an error message and related data
|
|
* @param msg error message
|
|
* @param ephemeral (default=true)
|
|
* @returns new errorMessage
|
|
*/
|
|
const emsg = (msg, ephemeral = true) => new errorMessage(Lang.get(`error.${msg}`), ephemeral);
|
|
exports.emsg = emsg;
|