UNPKG

d2-ui

Version:
26 lines (23 loc) 692 B
/** * Applies properties from "config" if they are undefined in "object. * * @param {Object} object The object to receive properties * @param {Object} config The object to pass properties * @returns {Object} The object that may have received properties * * @example * let object = {id: 1} * const config = {id: 2, name: 'Name'} * objectApplyIf(object, config); // returns: {id: 1, name: 'Name'} */ export default function objectApplyIf(object, config) { var property; if (object) { for (property in config) { if (object[property] === undefined) { object[property] = config[property]; } } } return object; }