UNPKG

util-ex

Version:

Browser-friendly enhanced util fully compatible with standard node.js

42 lines (40 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clonePropertiesTo = clonePropertiesTo; exports.default = void 0; var _defineProperty = _interopRequireDefault(require("./defineProperty.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const getAllOwnKeys = Object.getOwnPropertyNames; const getDescriptor = Object.getOwnPropertyDescriptor; /** * Clone all own properties of a source object to a destination object. * * @summary Clones own properties from source object to destination object. * * @description * This function clones all own properties of a source object to a destination object. * * @param {object} dest - The destination object to clone the properties to. * @param {object} src - The source object to clone the properties from. * * @returns {object} - The destination object with cloned properties from the source object. * * @example * var obj1 = { a: 1, b: 2 }; * var obj2 = { c: 3 }; * * clonePropertiesTo(obj2, obj1); // obj2 = { a: 1, b: 2, c: 3 } */ function clonePropertiesTo(dest, src) { const ref = getAllOwnKeys(src); for (let i = 0; i < ref.length; i++) { const k = ref[i]; const attr = getDescriptor(src, k); (0, _defineProperty.default)(dest, k, undefined, attr); } return dest; } ; var _default = exports.default = clonePropertiesTo;