All files / app/src/shared/helpers enum.helpers.ts

57.89% Statements 11/19
100% Branches 3/3
33.33% Functions 1/3
57.89% Lines 11/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 261x                   1x       1x 10x   10x 80x 60x 60x 80x   10x 10x  
export function enumToObject<T extends Record<string, string>>(enumeration: T): { [key in keyof T]: string } {
  const obj: { [key: string]: string } = {}
 
  Object.keys(enumeration).forEach(key => {
    obj[key] = enumeration[key]
  })
 
  return obj as { [key in keyof T]: string }
}
 
export function copyEnum<T extends Record<string, string>>(enumeration: T): T {
  return JSON.parse(JSON.stringify(enumeration))
}
 
export function omitEnum<T extends Record<string, string>>(enumeration: T, excludeKeys: (keyof T)[]): Partial<T> {
  const omittedEnum: Partial<T> = {}
 
  for (const key in enumeration) {
    if (!excludeKeys.includes(key as keyof T)) {
      omittedEnum[key] = enumeration[key]
    }
  }
 
  return omittedEnum
}