mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-04 23:18:01 +00:00
refactor: create utility for enums
This commit is contained in:
committed by
Carlos Valente
parent
b28573455a
commit
8aad271ffe
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user