All files / normalize normalize-array-of-primitives.ts

100% Statements 10/10
100% Branches 6/6
100% Functions 4/4
100% Lines 8/8

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      208x 49x 28x   64x   159x 75x 112x           84x      
import { isArrayOfPrimitives } from "../utils";
 
export function normalizeArrayOfPrimitives(data: any): any {
  if (Array.isArray(data)) {
    if (isArrayOfPrimitives(data)) {
      return data.map((value) => ({ value }));
    } else {
      return data.map((item) => normalizeArrayOfPrimitives(item));
    }
  } else if (Object(data) === data) {
    return Object.fromEntries(
      Object.entries(data).map(([key, value]) => [
        key,
        normalizeArrayOfPrimitives(value),
      ]),
    );
  } else {
    return data;
  }
}