From 84488b3e63441c33ae9eca1ee945d6dcb7af6115 Mon Sep 17 00:00:00 2001 From: adroslice Date: Tue, 30 Jul 2024 16:29:10 +0200 Subject: [PATCH] Add variantOf utility function for enums --- client/src/util.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/src/util.ts b/client/src/util.ts index 6c6ff70..59b0c60 100644 --- a/client/src/util.ts +++ b/client/src/util.ts @@ -15,5 +15,10 @@ export function isNullish(value: any) { return (value === null || value === undefined); } +export function variantOf(enumValue: any) { + if (typeof enumValue === 'string') return enumValue; + else return Object.entries(enumValue)[0][0]; +} + export type Index = string | number | symbol; -export type MaybeIndex = Index | null; \ No newline at end of file +export type MaybeIndex = Index | null;