All files / utils class.util.ts

100% Statements 8/8
100% Branches 6/6
100% Functions 1/1
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          10x 26x 11x 11x 11x 11x 24x 24x        
/**
 * Initializes a DTO class properties.
 * @param self initial class instance
 * @param input class instance property values
 */
export const initializeClassProperties = <T = Record<string, unknown>>(self: T, input?: T) => {
  if (typeof input !== 'undefined') {
    const typedSelf = self as Record<string, unknown>;
    const typedInput = input as Record<string, unknown>;
    const keys = Object.keys(typedInput);
    for (const key of keys) {
      const inputValue = typedInput[key];
      typedSelf[key] = typeof inputValue !== 'undefined' && inputValue !== null ? typedInput[key] : typedSelf[key];
    }
  }
};