refactor: create utility for enums

This commit is contained in:
Carlos Valente
2026-01-18 10:29:22 +01:00
committed by Carlos Valente
parent b28573455a
commit 8aad271ffe
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ export { deepmerge } from './src/externals/deepmerge.js';
// array utils
export { deleteAtIndex, insertAtIndex, mergeAtIndex, reorderArray } from './src/common/arrayUtils.js';
// object utils
export { getPropertyFromPath, isObjectEmpty } from './src/common/objectUtils.js';
export { getPropertyFromPath, isObjectEmpty, withoutUndefinedValues, isValueOfEnum } from './src/common/objectUtils.js';
// generic utilities
export { getErrorMessage } from './src/generic/generic.js';
+7
View File
@@ -33,3 +33,10 @@ export function withoutUndefinedValues<T extends Record<string, unknown>>(
Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]);
return obj as { [K in keyof T]: Exclude<T[K], undefined> };
}
/**
* Checks whether a value is part of an enum
*/
export function isValueOfEnum<T extends object>(enumObj: T, value: unknown): value is T[keyof T] {
return Object.values(enumObj).includes(value);
}