function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import { isObject } from './inspect'; // --- Static --- export var assign = function assign() { return Object.assign.apply(Object, arguments); }; export var create = function create(proto, optionalProps) { return Object.create(proto, optionalProps); }; export var defineProperties = function defineProperties(obj, props) { return Object.defineProperties(obj, props); }; export var defineProperty = function defineProperty(obj, prop, descriptor) { return Object.defineProperty(obj, prop, descriptor); }; export var freeze = function freeze(obj) { return Object.freeze(obj); }; export var getOwnPropertyNames = function getOwnPropertyNames(obj) { return Object.getOwnPropertyNames(obj); }; export var getOwnPropertyDescriptor = function getOwnPropertyDescriptor(obj, prop) { return Object.getOwnPropertyDescriptor(obj, prop); }; export var getOwnPropertySymbols = function getOwnPropertySymbols(obj) { return Object.getOwnPropertySymbols(obj); }; export var getPrototypeOf = function getPrototypeOf(obj) { return Object.getPrototypeOf(obj); }; export var is = function is(value1, value2) { return Object.is(value1, value2); }; export var isFrozen = function isFrozen(obj) { return Object.isFrozen(obj); }; export var keys = function keys(obj) { return Object.keys(obj); }; // --- "Instance" --- export var hasOwnProperty = function hasOwnProperty(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; export var toString = function toString(obj) { return Object.prototype.toString.call(obj); }; // --- Utilities --- /** * Shallow copy an object. If the passed in object * is null or undefined, returns an empty object */ export var clone = function clone(obj) { return _objectSpread({}, obj); }; /** * Return a shallow copy of object with the specified properties only * @link https://gist.github.com/bisubus/2da8af7e801ffd813fab7ac221aa7afc */ export var pick = function pick(obj, props) { return keys(obj).filter(function (key) { return props.indexOf(key) !== -1; }).reduce(function (result, key) { return _objectSpread(_objectSpread({}, result), {}, _defineProperty({}, key, obj[key])); }, {}); }; /** * Return a shallow copy of object with the specified properties omitted * @link https://gist.github.com/bisubus/2da8af7e801ffd813fab7ac221aa7afc */ export var omit = function omit(obj, props) { return keys(obj).filter(function (key) { return props.indexOf(key) === -1; }).reduce(function (result, key) { return _objectSpread(_objectSpread({}, result), {}, _defineProperty({}, key, obj[key])); }, {}); }; /** * Merges two object deeply together * @link https://gist.github.com/Salakar/1d7137de9cb8b704e48a */ export var mergeDeep = function mergeDeep(target, source) { if (isObject(target) && isObject(source)) { keys(source).forEach(function (key) { if (isObject(source[key])) { if (!target[key] || !isObject(target[key])) { target[key] = source[key]; } mergeDeep(target[key], source[key]); } else { assign(target, _defineProperty({}, key, source[key])); } }); } return target; }; /** * Convenience method to create a read-only descriptor */ export var readonlyDescriptor = function readonlyDescriptor() { return { enumerable: true, configurable: false, writable: false }; };