UNPKG

@gitlab/ui

Version:
26 lines (23 loc) 584 B
import isObject from 'lodash/isObject'; /** * Purpose is a substitute of Vue.set but with preserving reactivity * New object can be assigned to data property of aa component * @param source * @param key * @param value * @returns {*} */ const setObjectProperty = function (source, key) { let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; if (!source || !key || !isObject(source)) { return {}; } if (typeof key !== 'string') { return source; } return { ...source, [key]: value }; }; export { setObjectProperty };