VARIOUS: Various changes prior to release 2.2 (#271)

See PR #271 description
This commit is contained in:
Snarling
2022-12-29 20:28:53 -05:00
committed by GitHub
parent 24ad342203
commit fb1f95c26e
310 changed files with 3768 additions and 2583 deletions
+9 -1
View File
@@ -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];
}