All files / dist/utils object.utils.js

100% Statements 14/14
100% Branches 3/3
100% Functions 1/1
100% Lines 14/14

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  4x 4x     2x 1x     1x 1x 1x 1x 1x 1x 1x   2x 2x   4x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clone = void 0;
function clone(classIns, data, applyConstructor = false) {
    let instance;
    if (applyConstructor) {
        instance = new classIns();
    }
    else {
        instance = Object.create(classIns);
        instance.constructor = new classIns().constructor;
        const descriptor = Object.getOwnPropertyDescriptor(instance, 'constructor');
        descriptor.enumerable = false;
        descriptor.writable = false;
        Object.defineProperty(instance, 'constructor', descriptor);
        Object.setPrototypeOf(instance, classIns.prototype);
    }
    Object.assign(instance, data);
    return instance;
}
exports.clone = clone;