All files / normalize normalize-localization.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      227x 89x 179x 73x 3x   72x 106x             106x      
import { isLocalizationObject } from "../utils";
 
export function normalizeLocalization(data: any): any {
  if (Array.isArray(data)) {
    return data.map((item) => normalizeLocalization(item));
  } else if (Object(data) === data) {
    if (isLocalizationObject(data)) {
      return Object.entries(data).map(([lang, text]) => ({ lang, text }));
    } else {
      return Object.fromEntries(
        Object.entries(data).map(([key, value]) => [
          key,
          normalizeLocalization(value),
        ]),
      );
    }
  } else {
    return data;
  }
}