UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

41 lines (30 loc) 675 B
import isObject from './is_object.js'; import './get_tag.js'; import isString from './is_string.js'; import isSymbol from './is_symbol.js'; /* eslint-disable eqeqeq */ function set(obj, props, value) { if (isString(props)) { props = props.split('.'); } if (isSymbol(props)) { props = [props]; } var lastProp = props.pop(); if (!lastProp) { return false; } var thisProp; while (thisProp = props.shift()) { if (typeof obj[thisProp] == 'undefined') { obj[thisProp] = {}; } obj = obj[thisProp]; if (!obj || !isObject(obj)) { return false; } } obj[lastProp] = value; return true; } export default set;