UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

43 lines (31 loc) 709 B
'use strict'; var is_object = require('./is_object.js'); require('./get_tag.js'); var is_string = require('./is_string.js'); var is_symbol = require('./is_symbol.js'); /* eslint-disable eqeqeq */ function set(obj, props, value) { if (is_string(props)) { props = props.split('.'); } if (is_symbol(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 || !is_object(obj)) { return false; } } obj[lastProp] = value; return true; } module.exports = set;