mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 11:27:04 +02:00
VARIOUS: Various changes prior to release 2.2 (#271)
See PR #271 description
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { getRandomInt } from "./getRandomInt";
|
||||
|
||||
/** Verifies that a supplied value is a member of the provided object/enum. Works for enums as well as enum-like objects (const {} as const). */
|
||||
export function checkEnum<T extends Record<string, unknown>>(obj: T, value: unknown): value is T[keyof T] {
|
||||
export function checkEnum<T extends object>(obj: T, value: unknown): value is T[keyof T] {
|
||||
return Object.values(obj).includes(value);
|
||||
}
|
||||
|
||||
@@ -9,3 +11,9 @@ export function findEnumMember<T extends Record<string, string>>(obj: T, value:
|
||||
if (lowerValue.includes(member.toLowerCase().replace(/ /g, ""))) return member;
|
||||
}
|
||||
}
|
||||
|
||||
export function getRandomMember<T extends Record<string, string>>(obj: T): T[keyof T] {
|
||||
const array = Object.values(obj);
|
||||
const index = getRandomInt(0, array.length - 1);
|
||||
return array[index] as T[keyof T];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user