Sha256: 25769fe75cab5b5375154b7baf8e04bec038d87f1f5c3fed26980fc525ab9178

Contents?: true

Size: 1.09 KB

Versions: 44

Compression:

Stored size: 1.09 KB

Contents

"use strict";

var includes      = require("../array/#/contains")
  , uniq          = require("../array/#/uniq")
  , copyDeep      = require("./copy-deep")
  , objForEach    = require("./for-each")
  , isPlainObject = require("./is-plain-object")
  , ensureValue   = require("./valid-value");

var isArray = Array.isArray, slice = Array.prototype.slice;

var deepAssign = function (target, source) {
	if (target === source) return target;
	if (isPlainObject(target) && isPlainObject(source)) {
		objForEach(source, function (value, key) { target[key] = deepAssign(target[key], value); });
		return target;
	}
	if (isArray(target) && isArray(source)) {
		source.forEach(function (item) {
			if (includes.call(target, item)) return;
			if (isArray(item) || isPlainObject(item)) item = copyDeep(item);
			target.push(item);
		});
		return target;
	}
	if (isPlainObject(source) || isArray(source)) return copyDeep(source);
	return source;
};

module.exports = function (target/*, ...objects*/) {
	return uniq
		.call([ensureValue(target)].concat(slice.call(arguments, 1).map(ensureValue)))
		.reduce(deepAssign);
};

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-18.0.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.21.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.20.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.19.1 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.19.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.18.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.17.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.16.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.15.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.14.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.13.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.12.2 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.12.1 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.12.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.11.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.10.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.9.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.8.0 node_modules/es5-ext/object/assign-deep.js
govuk_publishing_components-17.7.0 node_modules/es5-ext/object/assign-deep.js