UNPKG

@fivem-ts/shared

Version:

FiveM Typescript wrapper shared part

20 lines (19 loc) 834 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRandomEnumValue = getRandomEnumValue; const maths_1 = require("../maths"); /** * Returns a random value from an enumerated type, filtered by the specified value type. * * @template T * * @param {object} enumType - The enumerated type object from which to select a random value. * @param {'string'|'number'} valueType - Specifies the type of the values to consider ('string' or 'number'). * * @return {T[keyof T]} A random value from the enumerated type that matches the specified value type. */ function getRandomEnumValue(enumType, valueType) { const values = Object.values(enumType).filter(value => typeof value === valueType); const randomIndex = (0, maths_1.getRandomInt)(0, values.length); return values[randomIndex]; }