All files / services/utils mapObject.ts

80% Statements 8/10
100% Branches 0/0
50% Functions 2/4
88.89% Lines 8/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 209x   2x 2x 2x 1x   1x   9x       9x            
export interface Map<Type> {
  [key: string]: Type;
}
 
export function mapObject<SourceItem, ResultItem>(
  input: Map<SourceItem>,
  mapper: (item: SourceItem, key: string) => ResultItem,
): Map<ResultItem> {
  const result: Map<ResultItem> = {};
  Object.keys(input).map(key => {
    const mapped = mapper(input[key], key);
    result[key] = mapped;
  });
  return result;
}
 
export function convertObjectToArray<Type>(input: Map<Type>): Type[] {
  return Object.keys(input).map(key => input[key]);
}