UNPKG

d3plus-common

Version:

Common functions and methods used across D3plus modules.

41 lines (39 loc) 1.48 kB
import { default as isObject } from "./isObject.js"; /** @function validObject @desc Determines if the object passed is the document or window. @param {Object} obj @private */ function validObject(obj) { if (typeof window === "undefined") return true;else return obj !== window && obj !== document; } /** @function assign @desc A deeply recursive version of `Object.assign`. @param {...Object} objects @example <caption>this</caption> assign({id: "foo", deep: {group: "A"}}, {id: "bar", deep: {value: 20}})); @example <caption>returns this</caption> {id: "bar", deep: {group: "A", value: 20}} */ function assign() { var _arguments = arguments; var target = arguments.length <= 0 ? undefined : arguments[0]; var _loop = function _loop() { var source = i < 0 || _arguments.length <= i ? undefined : _arguments[i]; if (!isObject(source)) return "continue"; Object.keys(source).forEach(function (prop) { var value = source[prop]; if (isObject(value) && validObject(value)) { if (Object.prototype.hasOwnProperty.call(target, prop) && isObject(target[prop])) target[prop] = assign({}, target[prop], value);else target[prop] = assign({}, value); } else if (Array.isArray(value)) target[prop] = value.slice();else target[prop] = value; }); }; for (var i = 1; i < arguments.length; i++) { var _ret = _loop(); if (_ret === "continue") continue; } return target; } export default assign;