UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

70 lines (69 loc) 2.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.assign = void 0; const assignValue_1 = __importDefault(require("./.internal/assignValue")); const copyObject_1 = __importDefault(require("./.internal/copyObject")); const createAssigner_1 = __importDefault(require("./.internal/createAssigner")); const isPrototype_1 = __importDefault(require("./.internal/isPrototype")); const isArrayLike_1 = __importDefault(require("./isArrayLike")); const keys_1 = __importDefault(require("./keys")); /** * @internal * @ignore */ const hasOwnProperty = Object.prototype.hasOwnProperty; /** * @internal * @ignore */ const internal = (0, createAssigner_1.default)((object, source) => { if ((0, isPrototype_1.default)(source) || (0, isArrayLike_1.default)(source)) { (0, copyObject_1.default)(source, (0, keys_1.default)(source), object); return; } for (const key in source) { if (hasOwnProperty.call(source, key)) { (0, assignValue_1.default)(object, key, source[key]); } } }); /** * Assigns own enumerable string keyed properties of source objects to the * destination object. Source objects are applied from left to right. * Subsequent sources overwrite property assignments of previous sources. * * **Note:** This method mutates `object` and is loosely based on * [`Object.assign`](https://mdn.io/Object/assign). * * @since 5.5.0 * @category Object * @param object The destination object. * @param sources The source objects. * @returns Returns `object`. * @see [[assignIn]] * @example * * ```js * function Foo() { * this.a = 1; * } * * function Bar() { * this.c = 3; * } * * Foo.prototype.b = 2; * Bar.prototype.d = 4; * * assign({ 'a': 0 }, new Foo, new Bar); * // => { 'a': 1, 'c': 3 } * ``` */ function assign(target, ...args) { return internal(target, ...args); } exports.assign = assign; exports.default = assign;